Skip to content

Commit f3cdd81

Browse files
authored
test(abg): update generated file in place (#1332)
Before this change, if the generated Kotlin file didn't match the expected one, a new file was created under a different path. It was then hard to just accept the changes i.e. use what was actually produced as the expected file. This change makes the test edit the file in place.
1 parent abcd2d6 commit f3cdd81

File tree

1 file changed

+6
-17
lines changed
  • action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator

1 file changed

+6
-17
lines changed

action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/Utils.kt

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,28 @@ package io.github.typesafegithub.workflows.actionbindinggenerator
33
import io.github.typesafegithub.workflows.actionbindinggenerator.generation.ActionBinding
44
import io.kotest.assertions.fail
55
import io.kotest.matchers.shouldBe
6-
import io.kotest.matchers.shouldNot
7-
import io.kotest.matchers.string.contain
86
import java.nio.file.Paths
97

108
fun ActionBinding.shouldMatchFile(path: String) {
11-
val expectedFile =
9+
val file =
1210
Paths.get("src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/bindingsfromunittests/$path")
1311
.toFile()
14-
val actualFile = expectedFile.resolveSibling(expectedFile.nameWithoutExtension + "Actual.kt")
1512
val expectedContent =
1613
when {
17-
expectedFile.canRead() -> expectedFile.readText().removeWindowsNewLines()
14+
file.canRead() -> file.readText().removeWindowsNewLines()
1815
else -> ""
1916
}
2017
val actualContent = kotlinCode.removeWindowsNewLines()
2118

2219
filePath shouldBe "github-workflows-kt/src/gen/kotlin/io/github/typesafegithub/workflows/actions/johnsmith/$path"
2320

24-
val packageName = "io.github.typesafegithub.workflows.actions.johnsmith"
25-
expectedContent shouldNot contain("package $packageName.actual")
26-
2721
if (System.getenv("GITHUB_ACTIONS") == "true") {
2822
actualContent shouldBe expectedContent
29-
} else if (actualContent == expectedContent) {
30-
actualFile.delete()
31-
} else {
32-
actualFile.writeText(
33-
// change the package to avoid compilation errors because of duplicate classes / functions
34-
actualContent.replace("package $packageName", "package $packageName.actual"),
35-
)
23+
} else if (actualContent != expectedContent) {
24+
file.writeText(actualContent)
3625
fail(
37-
"The Binding's kotlin code in ${actualFile.name} doesn't match ${expectedFile.name}\n" +
38-
"See folder ${expectedFile.parentFile.canonicalPath}",
26+
"The binding's Kotlin code in ${file.name} doesn't match the expected one.\n" +
27+
"The file has been updated to match what's expected.",
3928
)
4029
}
4130
}

0 commit comments

Comments
 (0)