Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Test Report locale independent #868

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions pkl-cli/src/test/kotlin/org/pkl/cli/CliTestRunnerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.Writer;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import org.pkl.core.TestResults;
import org.pkl.core.TestResults.TestResult;
Expand Down Expand Up @@ -144,7 +145,10 @@ private void makeStatsLine(
sb.append(
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) {
sb.append(" [").append(failed).append('/').append(total).append(" failed]");
Expand Down