From 50236c4e0ef6cde7c21cb352b0e996b96e1e2710 Mon Sep 17 00:00:00 2001 From: takahirom Date: Fri, 23 Feb 2024 13:06:50 +0900 Subject: [PATCH] Add change build dir test --- .../roborazzi/RoborazziGradleProject.kt | 24 ++++++---- .../roborazzi/RoborazziGradleProjectTest.kt | 46 +++++++++++-------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProject.kt b/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProject.kt index 8e69ab99..b1ca7e8b 100644 --- a/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProject.kt +++ b/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProject.kt @@ -7,6 +7,7 @@ import org.junit.rules.TemporaryFolder import java.io.File class RoborazziGradleProject(val testProjectDir: TemporaryFolder) { + var buildDirName = "build" init { File("./src/integrationTest/projects").copyRecursively(testProjectDir.root, true) } @@ -103,12 +104,12 @@ class RoborazziGradleProject(val testProjectDir: TemporaryFolder) { } fun removeRoborazziOutputDir() { - File(testProjectDir.root, "app/build/outputs/roborazzi").deleteRecursively() + File(testProjectDir.root, "app/$buildDirName/outputs/roborazzi").deleteRecursively() } fun removeRoborazziAndIntermediateOutputDir() { - File(testProjectDir.root, "app/build/outputs/roborazzi").deleteRecursively() - File(testProjectDir.root, "app/build/intermediates/roborazzi").deleteRecursively() + File(testProjectDir.root, "app/$buildDirName/outputs/roborazzi").deleteRecursively() + File(testProjectDir.root, "app/$buildDirName/intermediates/roborazzi").deleteRecursively() } fun assertNotSkipped(output: String) { @@ -278,13 +279,13 @@ dependencies { } fun checkResultFileExists(nameSuffix: String) { - testProjectDir.root.resolve("app/build/test-results/roborazzi/results/").listFiles() + testProjectDir.root.resolve("app/$buildDirName/test-results/roborazzi/results/").listFiles() .firstOrNull { it.name.endsWith(nameSuffix) } ?: error("File not found: $nameSuffix") } fun checkResultFileNotExists(nameSuffix: String) { - testProjectDir.root.resolve("app/build/test-results/roborazzi/results/").listFiles() + testProjectDir.root.resolve("app/$buildDirName/test-results/roborazzi/results/").listFiles() ?.firstOrNull { it.name.endsWith(nameSuffix) } ?.let { error("File exists: $nameSuffix") @@ -294,7 +295,7 @@ dependencies { fun checkResultsSummaryFileNotExists() { val recordedFile = - testProjectDir.root.resolve("app/build/test-results/roborazzi/results-summary.json") + testProjectDir.root.resolve("app/$buildDirName/test-results/roborazzi/results-summary.json") assert(!recordedFile.exists()) { "File exists: ${recordedFile.absolutePath}" } @@ -302,7 +303,7 @@ dependencies { fun checkResultsSummaryFileExists() { val recordedFile = - testProjectDir.root.resolve("app/build/test-results/roborazzi/results-summary.json") + testProjectDir.root.resolve("app/$buildDirName/test-results/roborazzi/results-summary.json") assert(recordedFile.exists()) { "File not exists: ${recordedFile.absolutePath}" } @@ -315,7 +316,7 @@ dependencies { unchanged: Int = 0 ) { val recordedFile = - testProjectDir.root.resolve("app/build/test-results/roborazzi/results-summary.json") + testProjectDir.root.resolve("app/$buildDirName/test-results/roborazzi/results-summary.json") val resutls = CaptureResults.fromJsonFile(recordedFile.absolutePath) assert(resutls.resultSummary.recorded == recorded) { "Expected count: $recorded, actual count: ${resutls.resultSummary.recorded} summary:${resutls.resultSummary}" @@ -350,6 +351,13 @@ dependencies { } } + fun changeBuildDir(buildDirName: String) { + testProjectDir.root.resolve("gradle.properties").appendText( + "\nbuildDir=$buildDirName" + ) + this.buildDirName = buildDirName + } + fun changeScreen() { val file = testProjectDir.root.resolve("app/src/main/java/com/github/takahirom/integration_test_project/MainActivity.kt") 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 d1fccae3..50861432 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 @@ -4,7 +4,6 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder - /** * Run this test with `cd include-build` and `./gradlew roborazzi-gradle-plugin:check` */ @@ -14,23 +13,32 @@ class RoborazziGradleProjectTest { val testProjectDir = TemporaryFolder() private val className = "com.github.takahirom.integration_test_project.RoborazziTest" - private val screenshotAndName = - "app/build/outputs/roborazzi/$className" - private val defaultRoborazziOutputDir = "build/outputs/roborazzi" - private val customReferenceScreenshotAndName = - "app/$defaultRoborazziOutputDir/customdir/custom_file" - private val customCompareScreenshotAndName = - "app/$defaultRoborazziOutputDir/custom_compare_outputDirectoryPath/custom_file" - private val customReferenceScreenshotAndNameWithRoborazziContext = - "app/$defaultRoborazziOutputDir/custom_outputDirectoryPath_from_rule/$defaultRoborazziOutputDir/customdir/custom_file" - private val customCompareScreenshotAndNameWithRoborazziContext = - "app/$defaultRoborazziOutputDir/custom_compare_outputDirectoryPath/custom_file" + private var defaultBuildDir = "build" + + private val screenshotAndName + get() = + "app/$defaultBuildDir/outputs/roborazzi/$className" + + private val defaultRoborazziOutputDir get() = "$defaultBuildDir/outputs/roborazzi" + private val customReferenceScreenshotAndName + get() = + "app/$defaultRoborazziOutputDir/customdir/custom_file" + private val customCompareScreenshotAndName + get() = + "app/$defaultRoborazziOutputDir/custom_compare_outputDirectoryPath/custom_file" + private val customReferenceScreenshotAndNameWithRoborazziContext + get() = + "app/$defaultRoborazziOutputDir/custom_outputDirectoryPath_from_rule/$defaultRoborazziOutputDir/customdir/custom_file" + private val customCompareScreenshotAndNameWithRoborazziContext + get() = + "app/$defaultRoborazziOutputDir/custom_compare_outputDirectoryPath/custom_file" - private val addedScreenshotAndName = - "app/$defaultRoborazziOutputDir/com.github.takahirom.integration_test_project.AddedRoborazziTest" + private val addedScreenshotAndName + get() = + "app/$defaultRoborazziOutputDir/com.github.takahirom.integration_test_project.AddedRoborazziTest" - private val resultFileSuffix = "$className.testCapture.json" + private val resultFileSuffix get() = "$className.testCapture.json" @Test fun record() { @@ -118,7 +126,6 @@ class RoborazziGradleProjectTest { } } - @Test fun unitTestWhenRunTwice() { RoborazziGradleProject(testProjectDir).apply { @@ -284,8 +291,11 @@ class RoborazziGradleProjectTest { } @Test - fun verify_nochange() { + fun verify_nochange_with_changed_build_dir() { RoborazziGradleProject(testProjectDir).apply { + val buildDirName = "testCustomBuildDirName" + changeBuildDir(buildDirName) + defaultBuildDir = buildDirName record() verify() @@ -294,10 +304,10 @@ class RoborazziGradleProjectTest { checkRecordedFileExists("$screenshotAndName.testCapture.png") checkRecordedFileNotExists("$screenshotAndName.testCapture_compare.png") checkRecordedFileNotExists("$screenshotAndName.testCapture_actual.png") + checkResultCount(unchanged = 1) } } - @Test fun verifyAndRecord_changeDetect() { RoborazziGradleProject(testProjectDir).apply {