scalacenter / bloop

Bloop is a build server and CLI tool to compile, test and run Scala fast from any editor or build tool.
https://scalacenter.github.io/bloop/
Apache License 2.0
909 stars 201 forks source link

Passing arguments from CLI to Scalatest runner does not work #1490

Open kammoh opened 3 years ago

kammoh commented 3 years ago

CLI runner arguments are not passed to Scalatest. Previously reported (and not fixed) in #1288.

$ bloop test root --only MySpec -- -Dkey=value
MySpec:
configMap=Map()

It works perfectly fine with sbt:

$ sbt "root/testOnly MySpec -- -Dkey=value"
[info] compiling ...
MySpec:
configMap=Map(key -> value)

Tried and not worked:

tgodzik commented 3 years ago

Thanks for reporting! I will try to take a look at it at some point unless anyone else is able to take a look :s

olegbonar commented 3 years ago

Faced the same problem today.

davidmlw commented 2 years ago

I confirmed the issue is still in bloop 1.4.12

tgodzik commented 2 years ago

What did you try? Just checked it and it seems to work with: bloop test root-test -o CubeCalculatorTest -- -J-Dhello=1 in the scalatest example project.

davidmlw commented 2 years ago

I confirmed the -- -J-Dkey=value does not work. See https://github.com/davidmlw/bloop-test/runs/5168231480

I create a basic scala project and sbt passes but bloop not.

tgodzik commented 2 years ago

That's actually weird, the process does have it set /usr/lib/jvm/temurin-11-jdk-amd64/bin/java -Dkey=Hello -Duser.dir=/home/runner/work/bloop-test/bloop-test

Does it work if you do sys.env.get("key") ?

It did work for me in that case, though I am not familiar with ConfigMap and I am not sure when it should be populated.

davidmlw commented 2 years ago

See this run https://github.com/davidmlw/bloop-test/runs/5183749554 Bloop test passes the property -J-Dkey=Hello to java process, but not to scala test configMap. Sbt test passes the -Dkey=Hello to scala test configMap but not to java process. In the bloop test, the key value is found in System.getProperty("key"). In the sbt test, the 'key' is not found, nor the user.key, but 'user.dir' is found.

bloop test foo -o FooTester -- -Dkey=Hello -J-Duser.key=helllllo
sbt 'testOnly FooTester -- -Dkey=hello -Duser.key=helllllo'
println(s"java version: ${System.getProperty("java.version")}")
println(s"runtime version: ${System.getProperty("java.runtime.version")}")
println(s"user.dir: ${System.getProperty("user.dir")}")
println(s"user.key: ${System.getProperty("user.key")}")
println(s"key: ${System.getProperty("key")}")
println(s"env user.dir: ${sys.env.get("user.dir")}")
println(s"env key: ${sys.env.get("key")}")
davidmlw commented 2 years ago

This run was passed with -Dkey=Hello -J-Dkey=Hello, one for test framework, one for JVM. https://github.com/davidmlw/bloop-test/runs/5186157948#step:6:138 [D] Running test suites with arguments: List() The log shows the test framework didn't receive the -Dkey=Hello.

https://github.com/scalacenter/bloop/blob/81973d639aac92360c3a98043d335d4a39fc834f/frontend/src/main/scala/bloop/engine/tasks/TestTask.scala#L89-L91

it seems that frameworkArgs were not properly passed

This line has not been exectuted https://github.com/scalacenter/bloop/blob/81973d639aac92360c3a98043d335d4a39fc834f/frontend/src/main/scala/bloop/engine/tasks/TestTask.scala#L228 The options is not Nil and we found just one framework, the line should be printed, but it was not.

tgodzik commented 2 years ago

We might need to forward the jvm parameters to the test framework one then. Thanks for investigating!

davidmlw commented 2 years ago

I confirmed the issue is still in bloop 1.5.0, as shown here https://github.com/davidmlw/bloop-test/runs/6372828263

maxkorolev commented 1 year ago

I have the same issue for bloop 1.5.11. If anybody knows a workaround please let me know 😇