mirror of
https://github.com/apple/pkl.git
synced 2026-03-20 08:14:15 +01:00
Make Test Report locale independent (#868)
Format numbers with `.` decimals
This commit is contained in:
@@ -21,6 +21,7 @@ import java.io.StringWriter
|
||||
import java.io.Writer
|
||||
import java.net.URI
|
||||
import java.nio.file.Path
|
||||
import java.util.Locale
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatCode
|
||||
import org.junit.jupiter.api.Test
|
||||
@@ -487,6 +488,50 @@ class CliTestRunnerTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `CliTestRunner locale independence test`(@TempDir tempDir: Path) {
|
||||
val originalLocale = Locale.getDefault()
|
||||
Locale.setDefault(Locale.GERMANY)
|
||||
|
||||
try {
|
||||
val code =
|
||||
"""
|
||||
amends "pkl:test"
|
||||
|
||||
facts {
|
||||
["localeTest"] {
|
||||
1 == 1
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trimIndent()
|
||||
val input = tempDir.resolve("test.pkl").writeString(code).toString()
|
||||
val out = StringWriter()
|
||||
val err = StringWriter()
|
||||
val opts =
|
||||
CliBaseOptions(sourceModules = listOf(input.toUri()), settings = URI("pkl:settings"))
|
||||
val testOpts = CliTestOptions()
|
||||
val runner = CliTestRunner(opts, testOpts, consoleWriter = out, errWriter = err)
|
||||
runner.run()
|
||||
|
||||
assertThat(out.toString().stripFileAndLines(tempDir))
|
||||
.isEqualTo(
|
||||
"""
|
||||
module test
|
||||
facts
|
||||
✔ localeTest
|
||||
|
||||
100.0% tests pass [1 passed], 100.0% asserts pass [1 passed]
|
||||
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
assertThat(err.toString()).isEqualTo("")
|
||||
} finally {
|
||||
Locale.setDefault(originalLocale)
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.stripFileAndLines(tmpDir: Path): String {
|
||||
// handle platform differences in handling of file URIs
|
||||
// (file:/// on *nix vs. file:/ on Windows)
|
||||
|
||||
Reference in New Issue
Block a user