Fix #1256: Add JUnit support #1841
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.
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.