diff --git a/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProjectTest.kt b/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProjectTest.kt index c2aac5dbd..c81cdeeb7 100644 --- a/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProjectTest.kt +++ b/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProjectTest.kt @@ -32,162 +32,162 @@ class RoborazziGradleProjectTest { private val resultFileSuffix = "$className.testCapture.json" - @Test - fun record() { - RoborazziGradleProject(testProjectDir).apply { - record() - - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkResultFileExists(resultFileSuffix) - checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") - } - } - - @Test - fun recordWhenRemovedOutput() { - RoborazziGradleProject(testProjectDir).apply { - record() - removeRoborazziOutputDir() - // should not be skipped even if tests and sources are not changed - // when output directory is removed - val output = record().output - assertNotSkipped(output) - - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") - } - } - - @Test - fun recordWhenRemovedOutputAndIntermediate() { - RoborazziGradleProject(testProjectDir).apply { - removeRoborazziAndIntermediateOutputDir() - record() - removeRoborazziAndIntermediateOutputDir() - // should not be skipped even if tests and sources are not changed - // when output directory is removed - val output = record().output - assertNotSkipped(output) - - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") - } - } - - @Test - fun recordWhenRunTwice() { - RoborazziGradleProject(testProjectDir).apply { - record() - // files are changed so should not be skipped - val output1 = record().output - assertNotSkipped(output1) - // files are not changed so should be skipped - val output2 = record().output - assertSkipped(output2) - - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") - } - } - - @Test - fun recordWhenRunTwiceWithGradleCustomOutput() { - RoborazziGradleProject(testProjectDir).apply { - val customDirFromGradle = "src/screenshots/roborazzi_customdir_from_gradle" - appBuildFile.customOutputDirPath = customDirFromGradle - record() - // files are changed so should not be skipped - val output1 = record().output - assertNotSkipped(output1) - // files are not changed so should be skipped - val output2 = record().output - assertSkipped(output2) - - checkResultsSummaryFileExists() - checkRecordedFileExists("app/$customDirFromGradle/$className.testCapture.png") - checkRecordedFileNotExists("$$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$$screenshotAndName.testCapture_actual.png") - } - } - - - @Test - fun unitTestWhenRunTwice() { - RoborazziGradleProject(testProjectDir).apply { - unitTest() - val output = unitTest().output - assertSkipped(output) - - checkResultsSummaryFileNotExists() - checkRecordedFileNotExists("$screenshotAndName.testCapture.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") - } - } - - @Test - fun recordWithPropertiesAfterUnitTest() { - RoborazziGradleProject(testProjectDir).apply { - unitTest() - // Record task shouldn't be skipped even after unit test - val recordWithSystemParameter = recordWithSystemParameter() - assertNotSkipped(recordWithSystemParameter.output) - - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") - } - } - - @Test - fun recordAfterUnitTest() { - RoborazziGradleProject(testProjectDir).apply { - unitTest() - // Record task shouldn't be skipped even after unit test - record() - - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") - } - } - - @Test - fun canRecordWhenRemoveOutputDirBeforeTests() { - RoborazziGradleProject(testProjectDir).apply { - appBuildFile.removeOutputDirBeforeTestTypeTask = true - record() - } - } - - @Test - fun verify_changeDetect() { - RoborazziGradleProject(testProjectDir).apply { - record() - changeScreen() - val recordFileHash1 = getFileHash("$screenshotAndName.testCapture.png") - - verifyAndFail().shouldDetectChangedPngCapture() - - val recordFileHash2 = getFileHash("$screenshotAndName.testCapture.png") - assert(recordFileHash1 == recordFileHash2) - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkRecordedFileExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileExists("$screenshotAndName.testCapture_actual.png") - checkResultCount(changed = 1) - } - } +// @Test +// fun record() { +// RoborazziGradleProject(testProjectDir).apply { +// record() +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkResultFileExists(resultFileSuffix) +// checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun recordWhenRemovedOutput() { +// RoborazziGradleProject(testProjectDir).apply { +// record() +// removeRoborazziOutputDir() +// // should not be skipped even if tests and sources are not changed +// // when output directory is removed +// val output = record().output +// assertNotSkipped(output) +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun recordWhenRemovedOutputAndIntermediate() { +// RoborazziGradleProject(testProjectDir).apply { +// removeRoborazziAndIntermediateOutputDir() +// record() +// removeRoborazziAndIntermediateOutputDir() +// // should not be skipped even if tests and sources are not changed +// // when output directory is removed +// val output = record().output +// assertNotSkipped(output) +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun recordWhenRunTwice() { +// RoborazziGradleProject(testProjectDir).apply { +// record() +// // files are changed so should not be skipped +// val output1 = record().output +// assertNotSkipped(output1) +// // files are not changed so should be skipped +// val output2 = record().output +// assertSkipped(output2) +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun recordWhenRunTwiceWithGradleCustomOutput() { +// RoborazziGradleProject(testProjectDir).apply { +// val customDirFromGradle = "src/screenshots/roborazzi_customdir_from_gradle" +// appBuildFile.customOutputDirPath = customDirFromGradle +// record() +// // files are changed so should not be skipped +// val output1 = record().output +// assertNotSkipped(output1) +// // files are not changed so should be skipped +// val output2 = record().output +// assertSkipped(output2) +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("app/$customDirFromGradle/$className.testCapture.png") +// checkRecordedFileNotExists("$$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$$screenshotAndName.testCapture_actual.png") +// } +// } +// +// +// @Test +// fun unitTestWhenRunTwice() { +// RoborazziGradleProject(testProjectDir).apply { +// unitTest() +// val output = unitTest().output +// assertSkipped(output) +// +// checkResultsSummaryFileNotExists() +// checkRecordedFileNotExists("$screenshotAndName.testCapture.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun recordWithPropertiesAfterUnitTest() { +// RoborazziGradleProject(testProjectDir).apply { +// unitTest() +// // Record task shouldn't be skipped even after unit test +// val recordWithSystemParameter = recordWithSystemParameter() +// assertNotSkipped(recordWithSystemParameter.output) +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun recordAfterUnitTest() { +// RoborazziGradleProject(testProjectDir).apply { +// unitTest() +// // Record task shouldn't be skipped even after unit test +// record() +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun canRecordWhenRemoveOutputDirBeforeTests() { +// RoborazziGradleProject(testProjectDir).apply { +// appBuildFile.removeOutputDirBeforeTestTypeTask = true +// record() +// } +// } +// +// @Test +// fun verify_changeDetect() { +// RoborazziGradleProject(testProjectDir).apply { +// record() +// changeScreen() +// val recordFileHash1 = getFileHash("$screenshotAndName.testCapture.png") +// +// verifyAndFail().shouldDetectChangedPngCapture() +// +// val recordFileHash2 = getFileHash("$screenshotAndName.testCapture.png") +// assert(recordFileHash1 == recordFileHash2) +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkRecordedFileExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileExists("$screenshotAndName.testCapture_actual.png") +// checkResultCount(changed = 1) +// } +// } @Test fun verify_changeDetectRevertCache() { @@ -209,233 +209,233 @@ class RoborazziGradleProjectTest { } } - @Test - fun verify_addDetect() { - RoborazziGradleProject(testProjectDir).apply { - record() - addTest() - - verifyAndFail().shouldDetectNonExistentPngCapture() - - checkResultsSummaryFileExists() - checkRecordedFileNotExists("$addedScreenshotAndName.testCapture.png") - checkRecordedFileExists("$addedScreenshotAndName.testCapture_compare.png") - checkRecordedFileExists("$addedScreenshotAndName.testCapture_actual.png") - } - } - - @Test - fun recordWithCompareParameter() { - RoborazziGradleProject(testProjectDir).apply { - recordWithCompareParameter() - - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") - } - } - - @Test - fun recordWithSmallProperty() { - RoborazziGradleProject(testProjectDir).apply { - record() - changeScreen() - val recordFileHash1 = getFileHash("$screenshotAndName.testCapture.png") - - recordWithScaleSize() - - val recordFileHash2 = getFileHash("$screenshotAndName.testCapture.png") - assert(recordFileHash1 != recordFileHash2) - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") - } - } - - @Test - fun record_noTestFiles() { - RoborazziGradleProject(testProjectDir).apply { - removeTests() - record() - - // Summary file will be generated even if no test files - checkResultsSummaryFileExists() - // Test will be skipped when no source so no output - checkResultFileNotExists(resultFileSuffix) - } - } - - @Test - fun record_noTests() { - RoborazziGradleProject(testProjectDir).apply { - removeTests() - addTestClass() - record() - - checkResultsSummaryFileExists() - checkResultFileNotExists(resultFileSuffix) - } - } - - @Test - fun verify_nochange() { - RoborazziGradleProject(testProjectDir).apply { - record() - verify() - - checkResultsSummaryFileExists() - checkResultFileExists(resultFileSuffix) - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") - } - } - - - @Test - fun verifyAndRecord_changeDetect() { - RoborazziGradleProject(testProjectDir).apply { - record() - val recordFileHash1 = getFileHash("$screenshotAndName.testCapture.png") - changeScreen() - - verifyAndRecordAndFail() - - val recordFileHash2 = getFileHash("$screenshotAndName.testCapture.png") - assert(recordFileHash1 != recordFileHash2) - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkResultFileExists(resultFileSuffix) - checkRecordedFileExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") - } - } - - - @Test - fun verifyAndRecord_nochange() { - RoborazziGradleProject(testProjectDir).apply { - record() - verifyAndRecord() - - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") - } - } - - @Test - fun compare() { - RoborazziGradleProject(testProjectDir).apply { - record() - changeScreen() - compare() - - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkResultFileExists(resultFileSuffix) - checkRecordedFileExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileExists("$screenshotAndName.testCapture_actual.png") - } - } - - @Test - fun compareWithSystemParameter() { - println("start compareWithSystemParameter") - RoborazziGradleProject(testProjectDir).apply { - record() - changeScreen() - compareWithSystemParameter() - - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkRecordedFileExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileExists("$screenshotAndName.testCapture_actual.png") - } - } - - @Test - fun compare_nochange() { - RoborazziGradleProject(testProjectDir).apply { - record() - compare() - - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") - } - } - - @Test - fun compareWithCustomPath() { - RoborazziGradleProject(testProjectDir).apply { - removeTests() - addTestCaptureWithCustomPathTest() - record() - changeScreen() - compare() - - checkResultsSummaryFileExists() - checkRecordedFileExists("$customReferenceScreenshotAndName.png") - checkRecordedFileExists("${customCompareScreenshotAndName}_compare.png") - checkRecordedFileExists("${customCompareScreenshotAndName}_actual.png") - checkRecordedFileExists("app/build/outputs/roborazzi/custom_outputDirectoryPath_from_rule/custom_outputFileProvider-com.github.takahirom.integration_test_project.RoborazziTest.testCaptureWithCustomPath.png") - } - } - - @Test - fun compareWithCustomPathAndCaptureFilePathStrategy() { - RoborazziGradleProject(testProjectDir).apply { - removeTests() - addTestCaptureWithCustomPathTest() - addRelativeFromContextRecordFilePathStrategyGradleProperty() - record() - changeScreen() - compare() - - checkResultsSummaryFileExists() - checkRecordedFileExists("$customReferenceScreenshotAndNameWithRoborazziContext.png") - checkRecordedFileExists("${customCompareScreenshotAndNameWithRoborazziContext}_compare.png") - checkRecordedFileExists("${customCompareScreenshotAndNameWithRoborazziContext}_actual.png") - checkRecordedFileExists("app/build/outputs/roborazzi/custom_outputDirectoryPath_from_rule/custom_outputFileProvider-com.github.takahirom.integration_test_project.RoborazziTest.testCaptureWithCustomPath.png") - } - } - - @Test - fun secondImagesIsSkippedIfFirstVerificationFails() { - RoborazziGradleProject(testProjectDir).apply { - removeTests() - addRuleTest() - record() - changeScreen() - - verifyAndFail().shouldDetectChangedPngCapture() - - checkResultsSummaryFileExists() - checkRecordedFileExists("$screenshotAndName.testCapture.png") - checkRecordedFileExists("$screenshotAndName.testCapture_compare.png") - checkRecordedFileExists("$screenshotAndName.testCapture_2.png") - // If the first verification fails, the second verification will be skipped. - checkRecordedFileNotExists("$screenshotAndName.testCapture_2_actual.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_2_compare.png") - checkRecordedFileNotExists("$screenshotAndName.testCapture_2_actual.png") - } - } - - @Test - fun shouldNotRetainPreviousTestResults() { - RoborazziGradleProject(testProjectDir).apply { - removeTests() - addMultipleTest() - - recordWithFilter1() - recordWithFilter2() - - checkResultCount(recorded = 1) - } - } +// @Test +// fun verify_addDetect() { +// RoborazziGradleProject(testProjectDir).apply { +// record() +// addTest() +// +// verifyAndFail().shouldDetectNonExistentPngCapture() +// +// checkResultsSummaryFileExists() +// checkRecordedFileNotExists("$addedScreenshotAndName.testCapture.png") +// checkRecordedFileExists("$addedScreenshotAndName.testCapture_compare.png") +// checkRecordedFileExists("$addedScreenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun recordWithCompareParameter() { +// RoborazziGradleProject(testProjectDir).apply { +// recordWithCompareParameter() +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun recordWithSmallProperty() { +// RoborazziGradleProject(testProjectDir).apply { +// record() +// changeScreen() +// val recordFileHash1 = getFileHash("$screenshotAndName.testCapture.png") +// +// recordWithScaleSize() +// +// val recordFileHash2 = getFileHash("$screenshotAndName.testCapture.png") +// assert(recordFileHash1 != recordFileHash2) +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun record_noTestFiles() { +// RoborazziGradleProject(testProjectDir).apply { +// removeTests() +// record() +// +// // Summary file will be generated even if no test files +// checkResultsSummaryFileExists() +// // Test will be skipped when no source so no output +// checkResultFileNotExists(resultFileSuffix) +// } +// } +// +// @Test +// fun record_noTests() { +// RoborazziGradleProject(testProjectDir).apply { +// removeTests() +// addTestClass() +// record() +// +// checkResultsSummaryFileExists() +// checkResultFileNotExists(resultFileSuffix) +// } +// } +// +// @Test +// fun verify_nochange() { +// RoborazziGradleProject(testProjectDir).apply { +// record() +// verify() +// +// checkResultsSummaryFileExists() +// checkResultFileExists(resultFileSuffix) +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// +// @Test +// fun verifyAndRecord_changeDetect() { +// RoborazziGradleProject(testProjectDir).apply { +// record() +// val recordFileHash1 = getFileHash("$screenshotAndName.testCapture.png") +// changeScreen() +// +// verifyAndRecordAndFail() +// +// val recordFileHash2 = getFileHash("$screenshotAndName.testCapture.png") +// assert(recordFileHash1 != recordFileHash2) +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkResultFileExists(resultFileSuffix) +// checkRecordedFileExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// +// @Test +// fun verifyAndRecord_nochange() { +// RoborazziGradleProject(testProjectDir).apply { +// record() +// verifyAndRecord() +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun compare() { +// RoborazziGradleProject(testProjectDir).apply { +// record() +// changeScreen() +// compare() +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkResultFileExists(resultFileSuffix) +// checkRecordedFileExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun compareWithSystemParameter() { +// println("start compareWithSystemParameter") +// RoborazziGradleProject(testProjectDir).apply { +// record() +// changeScreen() +// compareWithSystemParameter() +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkRecordedFileExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun compare_nochange() { +// RoborazziGradleProject(testProjectDir).apply { +// record() +// compare() +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") +// } +// } +// +// @Test +// fun compareWithCustomPath() { +// RoborazziGradleProject(testProjectDir).apply { +// removeTests() +// addTestCaptureWithCustomPathTest() +// record() +// changeScreen() +// compare() +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$customReferenceScreenshotAndName.png") +// checkRecordedFileExists("${customCompareScreenshotAndName}_compare.png") +// checkRecordedFileExists("${customCompareScreenshotAndName}_actual.png") +// checkRecordedFileExists("app/build/outputs/roborazzi/custom_outputDirectoryPath_from_rule/custom_outputFileProvider-com.github.takahirom.integration_test_project.RoborazziTest.testCaptureWithCustomPath.png") +// } +// } +// +// @Test +// fun compareWithCustomPathAndCaptureFilePathStrategy() { +// RoborazziGradleProject(testProjectDir).apply { +// removeTests() +// addTestCaptureWithCustomPathTest() +// addRelativeFromContextRecordFilePathStrategyGradleProperty() +// record() +// changeScreen() +// compare() +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$customReferenceScreenshotAndNameWithRoborazziContext.png") +// checkRecordedFileExists("${customCompareScreenshotAndNameWithRoborazziContext}_compare.png") +// checkRecordedFileExists("${customCompareScreenshotAndNameWithRoborazziContext}_actual.png") +// checkRecordedFileExists("app/build/outputs/roborazzi/custom_outputDirectoryPath_from_rule/custom_outputFileProvider-com.github.takahirom.integration_test_project.RoborazziTest.testCaptureWithCustomPath.png") +// } +// } +// +// @Test +// fun secondImagesIsSkippedIfFirstVerificationFails() { +// RoborazziGradleProject(testProjectDir).apply { +// removeTests() +// addRuleTest() +// record() +// changeScreen() +// +// verifyAndFail().shouldDetectChangedPngCapture() +// +// checkResultsSummaryFileExists() +// checkRecordedFileExists("$screenshotAndName.testCapture.png") +// checkRecordedFileExists("$screenshotAndName.testCapture_compare.png") +// checkRecordedFileExists("$screenshotAndName.testCapture_2.png") +// // If the first verification fails, the second verification will be skipped. +// checkRecordedFileNotExists("$screenshotAndName.testCapture_2_actual.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_2_compare.png") +// checkRecordedFileNotExists("$screenshotAndName.testCapture_2_actual.png") +// } +// } +// +// @Test +// fun shouldNotRetainPreviousTestResults() { +// RoborazziGradleProject(testProjectDir).apply { +// removeTests() +// addMultipleTest() +// +// recordWithFilter1() +// recordWithFilter2() +// +// checkResultCount(recorded = 1) +// } +// } } diff --git a/include-build/roborazzi-gradle-plugin/src/main/java/io/github/takahirom/roborazzi/RoborazziPlugin.kt b/include-build/roborazzi-gradle-plugin/src/main/java/io/github/takahirom/roborazzi/RoborazziPlugin.kt index d26071ec4..76364ac48 100644 --- a/include-build/roborazzi-gradle-plugin/src/main/java/io/github/takahirom/roborazzi/RoborazziPlugin.kt +++ b/include-build/roborazzi-gradle-plugin/src/main/java/io/github/takahirom/roborazzi/RoborazziPlugin.kt @@ -14,14 +14,19 @@ import org.gradle.api.Task import org.gradle.api.file.DirectoryProperty import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider +import org.gradle.api.services.BuildService +import org.gradle.api.services.BuildServiceParameters import org.gradle.api.tasks.InputDirectory import org.gradle.api.tasks.Optional import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction -import org.gradle.api.tasks.TaskCollection import org.gradle.api.tasks.options.Option import org.gradle.api.tasks.testing.Test +import org.gradle.build.event.BuildEventsListenerRegistry import org.gradle.language.base.plugins.LifecycleBasePlugin.VERIFICATION_GROUP +import org.gradle.tooling.events.FinishEvent +import org.gradle.tooling.events.OperationCompletionListener import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget import java.util.Locale @@ -40,7 +45,9 @@ open class RoborazziExtension @Inject constructor(objects: ObjectFactory) { @Suppress("unused") // From Paparazzi: https://github.com/cashapp/paparazzi/blob/a76702744a7f380480f323ffda124e845f2733aa/paparazzi/paparazzi-gradle-plugin/src/main/java/app/cash/paparazzi/gradle/PaparazziPlugin.kt -class RoborazziPlugin : Plugin { +abstract class RoborazziPlugin : Plugin { + @Inject abstract fun getEventsListenerRegistry(): BuildEventsListenerRegistry + override fun apply(project: Project) { val extension = project.extensions.create("roborazzi", RoborazziExtension::class.java) @@ -88,7 +95,11 @@ class RoborazziPlugin : Plugin { return roborazziProperties["roborazzi.test.record"] == "true" || roborazziProperties["roborazzi.test.verify"] == "true" || roborazziProperties["roborazzi.test.compare"] == "true" } - fun configureRoborazziTasks(variantSlug: String, testTaskName: String) { + fun configureRoborazziTasks( + variantSlug: String, + testTaskName: String, + skippedTestTaskFinishEventsServiceProvider: Provider + ) { val testTaskOutputDirForEachVariant: DirectoryProperty = project.objects.directoryProperty() val intermediateDirForEachVariant = testTaskOutputDirForEachVariant.convention( @@ -176,21 +187,16 @@ class RoborazziPlugin : Plugin { /* configurationAction = */ object : Action { override fun execute(t: Task) { val testTaskCollectionInputKey = "testTaskCollection" - t.inputs.properties( - mapOf( - testTaskCollectionInputKey to testTaskProvider - ) - ) + t.onlyIf { val doesRoborazziRun = doesRoborazziRunProvider.get() t.infoln("Roborazzi: roborazziTestFinalizer.onlyIf doesRoborazziRun $doesRoborazziRun") doesRoborazziRun } t.doLast { finalizeTask -> - val testTaskCollection = - (finalizeTask.inputs.properties[testTaskCollectionInputKey] as TaskCollection).toList() + val isTestSkipped = + skippedTestTaskFinishEventsServiceProvider.get().skipped t.infoln("Roborazzi: roborazziTestFinalizer.doLast input:${finalizeTask.inputs.properties}") - val isTestSkipped = testTaskCollection.any { test -> test.state.skipped } if (isTestSkipped) { // If the test is skipped, we need to use cached files t.infoln("Roborazzi: finalizeTestRoborazziTask isTestSkipped:$isTestSkipped Copy files from ${intermediateDir.get()} to ${outputDir.get()}") @@ -331,6 +337,12 @@ class RoborazziPlugin : Plugin { verifyAndRecordTaskProvider.configure { it.dependsOn(testTaskProvider) } } + val skippedTestTaskFinishEventsServiceProvider: Provider = + project.gradle.sharedServices.registerIfAbsent( + "roborazziTestTaskEvents", SkippedTestTaskFinishEventsService::class.java + ) { spec -> spec.parameters } + getEventsListenerRegistry().onTaskCompletion(skippedTestTaskFinishEventsServiceProvider) + fun AndroidComponentsExtension<*, *, *>.configureComponents() { onVariants { variant -> val unitTest = variant.unitTest ?: return@onVariants @@ -338,7 +350,11 @@ class RoborazziPlugin : Plugin { val testVariantSlug = unitTest.name.capitalizeUS() // e.g. testDebugUnitTest -> recordRoborazziDebug - configureRoborazziTasks(variantSlug, "test$testVariantSlug") + configureRoborazziTasks( + variantSlug, + "test$testVariantSlug", + skippedTestTaskFinishEventsServiceProvider + ) } } @@ -352,7 +368,7 @@ class RoborazziPlugin : Plugin { } project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { // e.g. test -> recordRoborazziJvm - configureRoborazziTasks("Jvm", "test") + configureRoborazziTasks("Jvm", "test", skippedTestTaskFinishEventsServiceProvider) } project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { val kotlinMppExtension = checkNotNull( @@ -364,7 +380,11 @@ class RoborazziPlugin : Plugin { if (target is KotlinJvmTarget) { target.testRuns.all { testRun -> // e.g. desktopTest -> recordRoborazziDesktop - configureRoborazziTasks(target.name.capitalizeUS(), testRun.executionTask.name) + configureRoborazziTasks( + target.name.capitalizeUS(), + testRun.executionTask.name, + skippedTestTaskFinishEventsServiceProvider + ) } } } @@ -406,5 +426,25 @@ class RoborazziPlugin : Plugin { } } +/** + * We can't get whether the test is skipped or not from the test task itself + * because of the configuration cache + */ +abstract class SkippedTestTaskFinishEventsService : BuildService, + OperationCompletionListener { + var skipped = false + override fun onFinish(finishEvent: FinishEvent) { + val displayName = finishEvent.displayName + println("Roborazzi: SkippedTestTaskFinishEventsService: displayName:$displayName") + if (displayName.contains("test", ignoreCase = true) + && displayName.contains("skipped", ignoreCase = true) + ) { + println("Roborazzi: SkippedTestTaskFinishEventsService: Skipped test task $displayName") + skipped = true + } + } +} + + fun Task.infoln(format: String) = logger.info(format)