Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix testing as Java application (#3432)
Hello, I'm currently working on integrating Mill over the BSP plugin for IntelliJ (https://github.com/JetBrains/hirschgarten - now the BSP plugin code is merged with Bazel-related plugins). I have stumbled upon an issue, where the `Test <module.name> as Java application` action did not work with a testing suite. It only performed a Query JVM environment task and tests were not run (later on it turned out that it was caused by the `zincWorker` in `MillJvmBuildServer#jvmRunTestEnvironment`, which could not find the correct test main class). After digging into firstly the BSP plugin's code and later on Mill's code, I discovered that in the `MillJvmBuildServer#jvmRunTestEnvironment` there is testing logic lacking. It did not manage to fetch the correct test-specific main class, classpath and main arguments necessary for the testing as a local Java application. I figured out that in order to make it work, I needed to leverage the `TestModule`'s logic - I reproduced the `MillJvmBuildServer#testTask` logic of creating the java process' arguments and used it in a new `TestModule#getTestEnvironmentVars` function, which is then used in the `MillJvmBuildServer#jvmRunTestEnvironment` in case of a `TestModule with JavaModule` module (note: the code reproduction I've done might not be the most graceful solution - please let me know if I can do it better). Then the test-specific main class, classpath and main arguments I mentioned are assigned to adequate fields of the function's result - `JvmEnvironmentItem`, which is finally used on the BSP plugin side, which launches the actual local Java application. I tested the solution with an example Mill project (generated with the g8 template). With BSP plugin installed, I imported the project with the new importing via BSP plugin option (it's still WIP and not yet available in official Scala plugin distribution). Then I checked that indeed the `Test <module.name> as Java application` gutter triggers the tests and their result is displayed in the terminal. If you need any help with e.g. setting up the BSP plugin, I'm happy to help
- Loading branch information