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
Fix #1256: Add JUnit support #1841
Conversation
Co-authored-by: Lorenzo Gabriele <lorenzolespaul@gmail.com>
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.
This looks good for the most part. I have a few comments. Most are minor. The most important comment is about using Future
in the Bootstrapper
API, even if we don't support async tests yet.
junit-runtime/src/main/scala/org/junit/internal/ArrayComparisonFailure.scala
Outdated
Show resolved
Hide resolved
junit-runtime/src/main/scala/scala/scalanative/junit/Bootstrapper.scala
Outdated
Show resolved
Hide resolved
junit-runtime/src/main/scala/scala/scalanative/junit/JUnitTask.scala
Outdated
Show resolved
Hide resolved
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!
Sorry I found one more problem in the async
package object and how it's used.
junit-test/shared/src/test/scala/scala/scalanative/junit/AsyncTest.scala
Outdated
Show resolved
Hide resolved
junit-async/native/src/main/scala/scala/scalanative/junit/async/package.scala
Outdated
Show resolved
Hide resolved
junit-async/native/src/main/scala/scala/scalanative/junit/async/package.scala
Outdated
Show resolved
Hide resolved
I saw a comment about normalized names but I think this takes care of it unless this setting is not used. https://github.com/scala-native/scala-native/blob/master/build.sbt#L23 |
Yep, basically that was the part that introduced the problem. It converts the camelCase name to kebab-case. So, |
@errikos Cool, I saw the code after it changed to |
Add JUnit support for Scala Native and its projects. See `docs/user/testing.rst` for usage instructions. The feature was mostly ported from Scala.js, with some adaptations for Scala Native. ### Notes - The existing Scala Native test runner (`TestMain`) does not support multiple testing frameworks. For that reason, we now spawn one `TestMain` process per testing framework. This can be addressed in a future PR. - There is a runtime bug that is triggered by the `(String, Throwable)` constructor of `org.junit.AssumptionViolatedException`. The bug is only present in JUnit self-tests. At runtime, the native test runner exits unexpectedly when the AssumptionViolation is tested. This is why the aforementioned constructor is not available at the moment. Some details: - The constructor is always made reachable, no matter if it is used or not. This suggests maybe some bug in the reachability analysis and/or code generation. - After some digging around, I found out that the one to blame is the `Throwable` argument. When the argument is changed to anything else (or removed entirely), then everything works as expected. That is, the constructor is only made reachable when used and the runtime error goes away. ### Testing - The `test-all` command alias now also runs the JUnit self-tests. - There is an example JUnit test added in `unit-tests/src/test/scala/junit/JUnitExampleTest.scala`. ### Usage To enable JUnit support for a Scala Native project, add the following lines to your `build.sbt` file: ```scala libraryDependencies += "org.scala-native" %%% "junit-runtime" % "0.4.0-SNAPSHOT" addCompilerPlugin("org.scala-native" % "junit-plugin" % "0.4.0-SNAPSHOT" cross CrossVersion.full) ``` If you want to get more detailed output from the JUnit runtime, also include the following line: ```scala testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-s", "-v") ``` You may then use `test` or `testOnly` in the sbt shell to run all or specific tests, respectively.
Add JUnit support for Scala Native and its projects. See
docs/user/testing.rst
for usage instructions.The feature was mostly ported from Scala.js, with some adaptations for Scala Native.
Notes
TestMain
) does not support multiple testing frameworks. For that reason, we now spawn oneTestMain
process per testing framework. This can be addressed in a future PR.(String, Throwable)
constructor oforg.junit.AssumptionViolatedException
. The bug is only present in JUnit self-tests. At runtime, the native test runner exits unexpectedly when the AssumptionViolation is tested. This is why the aforementioned constructor is not available at the moment. Some details:Throwable
argument. When the argument is changed to anything else (or removed entirely), then everything works as expected. That is, the constructor is only made reachable when used and the runtime error goes away.Testing
test-all
command alias now also runs the JUnit self-tests.unit-tests/src/test/scala/junit/JUnitExampleTest.scala
.Usage
To enable JUnit support for a Scala Native project, add the following lines to your
build.sbt
file:If you want to get more detailed output from the JUnit runtime, also include the following line:
You may then use
test
ortestOnly
in the sbt shell to run all or specific tests, respectively.