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

Conversation

StefMa
Copy link
Contributor

@StefMa StefMa commented Dec 24, 2024

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):
Screenshot 2024-12-24 at 7 05 15 AM

If I run the newly added test without Locale.ROOT in SimpleReport, I get the following error:
Screenshot 2024-12-24 at 7 06 36 AM

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 the SimpleReport class. The most important changes include adding a locale independence test for CliTestRunner and specifying the root locale for formatting in SimpleReport.

Locale independence improvements:

@StefMa
Copy link
Contributor Author

StefMa commented Dec 24, 2024

@bioball I also updated the description with (maybe) hopefuly information 🙃

@StefMa StefMa mentioned this pull request Dec 24, 2024
)
assertThat(err.toString()).isEqualTo("")

Locale.setDefault(originalLocale)
Copy link
Contributor

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

Copy link
Contributor

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).

Copy link
Contributor Author

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? 🤔

Copy link
Contributor

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.

Copy link
Contributor

@bioball bioball left a 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.

@StefMa StefMa requested a review from bioball December 24, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Running test fails
3 participants