Skip to content

Commit

Permalink
Adds possibility to update smoke tests automatically
Browse files Browse the repository at this point in the history
Signed-off-by: Yauheni Khnykin <[email protected]>
  • Loading branch information
Hsilgos committed Oct 25, 2023
1 parent 1bdbe37 commit 98de6d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/internal/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ failure.
Changes affecting generated code require updating existing "reference" files, even if no new "smoke" tests are created.
This ensures "smoke" tests are passing, and also demonstrates the changes to "real" code to the reviewers of the change.

To update smoke tests automatically with new generated files the following command can be run: `DUMP_ACTUAL_DIR=$(pwd)/gluecodium/src/test/resources/smoke ./gradlew test`.

Functional tests
----------------

Expand Down
20 changes: 18 additions & 2 deletions gluecodium/src/test/java/com/here/gluecodium/SmokeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import java.util.Locale
@RunWith(Parameterized::class)
class SmokeTest(
private val featureDirectory: File,
private val dumpDirectory: File,
private val generatorName: String,
@Suppress("UNUSED_PARAMETER") featureName: String
) {
Expand Down Expand Up @@ -90,6 +91,7 @@ class SmokeTest(
val inputDirectory = File(featureDirectory, FEATURE_INPUT_FOLDER)
val auxDirectory = File(featureDirectory, FEATURE_AUX_FOLDER)
val outputDirectory = File(featureDirectory, FEATURE_OUTPUT_FOLDER)
val dumpDirectoryOutput = File(dumpDirectory, FEATURE_OUTPUT_FOLDER)
val validationShouldFail = File(inputDirectory, "validationfail.txt").exists()

val generatorDirectories = listOf(generatorName) + (ADDITIONAL_GENERATOR_DIRS[generatorName] ?: emptyList())
Expand Down Expand Up @@ -122,11 +124,21 @@ class SmokeTest(

if (generatedContent != null) {
val expected = it.readText()
val expectedWithImportantDifferences = ignoreUnimportantDifferences(expected)
val generatedWithImportantDifferences = ignoreUnimportantDifferences(generatedContent)

errorCollector.checkEquals(
"File content differs for file: $relativePath",
ignoreUnimportantDifferences(expected),
ignoreUnimportantDifferences(generatedContent)
expectedWithImportantDifferences,
generatedWithImportantDifferences
)

if (expectedWithImportantDifferences != generatedWithImportantDifferences) {
val dumpFile = File(dumpDirectoryOutput, relativePath)
if (dumpFile.canonicalFile != it.canonicalFile) {
dumpFile.writeText(generatedContent)
}
}
}
}
}
Expand Down Expand Up @@ -166,6 +178,9 @@ class SmokeTest(
return emptyList()
}

val dumpActualDirEnv = System.getenv("DUMP_ACTUAL_DIR")
val dumpActualDir = dumpActualDirEnv?.let { File(dumpActualDirEnv) }?:testResourcesDirectory

val featureDirectoryResources = testResourcesDirectory.listFiles()
if (featureDirectoryResources == null) {
fail("No test features were found")
Expand All @@ -177,6 +192,7 @@ class SmokeTest(
generatorNames.map { generatorName ->
arrayOf(
directory,
File(dumpActualDir, directory.name),
generatorName,
getFeatureName(testResourcesDirectory, directory)
)
Expand Down

0 comments on commit 98de6d9

Please sign in to comment.