-
Notifications
You must be signed in to change notification settings - Fork 280
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
base: main
Are you sure you want to change the base?
Conversation
@bioball I also updated the description with (maybe) hopefuly information 🙃 |
) | ||
assertThat(err.toString()).isEqualTo("") | ||
|
||
Locale.setDefault(originalLocale) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assertions will throw errors, which means that Locale.setDefault(...)
won't get called if any of these tests fail.
Let's put lines 496 through 527 in a try/finally
, where Locale.setDefault
is in the finally so we can ensure that this test cleans up the state that it's mucking with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note that mutating global JVM state is only safe as long as test execution is single-threaded (which is the default in Gradle).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assertions will throw errors, which means that Locale.setDefault(...) won't get called if any of these tests fail.
In case the test fails, won't the jvm "shutdown" anyways (and report the error)?
So doesn't this even matter to restore the default in that case?
Also note that mutating global JVM state is only safe as long as test execution is single-threaded (which is the default in Gradle).
Do we have the default here? 😅
When I running tests, it looks like Gradle runs the test parallel.
At least for different Gradle modules.
So I guess changing the Locale might also change the behviour on other modules/tests that runs at that time, correct? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, each Test
task starts one JVM and runs tests in a single thread. I'm not aware of Pkl overriding this default. Multiple Test
tasks may nevertheless run in parallel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Left one comment.
Also, run ./gradlew spotlessApply
to fix formatting errors.
fixes #861
According to AI (and javadoc 😅) the problem is that String.format takes Locale.getDefault if not specified. Indeed I have set de-EN on my machine so it takes comma decimals instead of dot decimals.
I haven't tested this yet, just created it on mobile...This is my macobok setting (not sure if relevant or the correct screen):
If I run the newly added test without
Locale.ROOT
inSimpleReport
, I get the following error:Running with that
Locale.ROOT
:BUILD SUCCESSFUL in 37s
🎉AI summary
This pull request includes changes to improve locale independence in the
CliTestRunner
and to ensure consistent locale usage in theSimpleReport
class. The most important changes include adding a locale independence test forCliTestRunner
and specifying the root locale for formatting inSimpleReport
.Locale independence improvements:
pkl-cli/src/test/kotlin/org/pkl/cli/CliTestRunnerTest.kt
: Added a new testCliTestRunner locale independence test
to verify thatCliTestRunner
works correctly regardless of the default locale.pkl-core/src/main/java/org/pkl/core/stdlib/test/report/SimpleReport.java
: Importedjava.util.Locale
to use for specifying locale in formatting.pkl-core/src/main/java/org/pkl/core/stdlib/test/report/SimpleReport.java
: Modified themakeStatsLine
method to useLocale.ROOT
inString.format
to ensure consistent formatting regardless of the default locale.