mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +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.io.Writer
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
import java.util.Locale
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.assertj.core.api.Assertions.assertThatCode
|
import org.assertj.core.api.Assertions.assertThatCode
|
||||||
import org.junit.jupiter.api.Test
|
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 {
|
private fun String.stripFileAndLines(tmpDir: Path): String {
|
||||||
// handle platform differences in handling of file URIs
|
// handle platform differences in handling of file URIs
|
||||||
// (file:/// on *nix vs. file:/ on Windows)
|
// (file:/// on *nix vs. file:/ on Windows)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.pkl.core.stdlib.test.report;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.pkl.core.TestResults;
|
import org.pkl.core.TestResults;
|
||||||
import org.pkl.core.TestResults.TestResult;
|
import org.pkl.core.TestResults.TestResult;
|
||||||
@@ -144,7 +145,10 @@ public final class SimpleReport implements TestReport {
|
|||||||
sb.append(
|
sb.append(
|
||||||
color,
|
color,
|
||||||
() ->
|
() ->
|
||||||
sb.append(String.format("%.1f%%", passRate)).append(" ").append(kind).append(" pass"));
|
sb.append(String.format(Locale.ROOT, "%.1f%%", passRate))
|
||||||
|
.append(" ")
|
||||||
|
.append(kind)
|
||||||
|
.append(" pass"));
|
||||||
|
|
||||||
if (isFailed) {
|
if (isFailed) {
|
||||||
sb.append(" [").append(failed).append('/').append(total).append(" failed]");
|
sb.append(" [").append(failed).append('/').append(total).append(" failed]");
|
||||||
|
|||||||
Reference in New Issue
Block a user