Skip to content

Commit

Permalink
Sanitize test data
Browse files Browse the repository at this point in the history
  • Loading branch information
kunyavskiy committed Sep 5, 2023
1 parent 8ab37af commit 64fb8e1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/cds/src/test/kotlin/org/icpclive/cds/CdsLoadersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,19 @@ object CdsLoadersTest {
result
}
}
val actual = json.encodeToString(result)
val expected = expectedFile.toFile().takeIf { it.exists() }?.readText() ?: ""
fun sanitize(s: String) = s.trim().replace(" +$", "").replace(System.lineSeparator(), "\n")
val actual = sanitize(json.encodeToString(result))
val expected = sanitize(expectedFile.toFile().takeIf { it.exists() }?.readText() ?: "")
if (actual != expected) {
if (updateTestData) {
expectedFile.toFile().printWriter().use {
it.print(actual)
it.print(actual.replace("\n", System.lineSeparator()))
}
}
throw AssertionFailedError(
"Actual result doesn't match expected in file ${expectedFile}",
"Actual result doesn't match expected in file ${expectedFile}\n" +
"Expected: $expected\n" +
"Actual: $actual\n",
expected,
actual,
)
Expand Down

0 comments on commit 64fb8e1

Please sign in to comment.