bloop icon indicating copy to clipboard operation
bloop copied to clipboard

Passing arguments from CLI to Scalatest runner does not work

Open kammoh opened this issue 4 years ago • 12 comments

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:

  • The --args flag and/or variations of quotations
  • bloop "1.4.8" and "v1.4.8-19-4d9f966b"
  • JDK 8 and 11
  • bloop test xyz -- -J-Dkey=value

kammoh avatar Apr 15 '21 17:04 kammoh

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

tgodzik avatar Apr 15 '21 17:04 tgodzik

Faced the same problem today.

olegbonar avatar Oct 05 '21 11:10 olegbonar

I confirmed the issue is still in bloop 1.4.12

davidmlw avatar Jan 25 '22 05:01 davidmlw

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.

tgodzik avatar Jan 25 '22 17:01 tgodzik

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.

davidmlw avatar Feb 12 '22 13:02 davidmlw

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.

tgodzik avatar Feb 14 '22 11:02 tgodzik

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 avatar Feb 14 '22 12:02 davidmlw

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.

davidmlw avatar Feb 14 '22 15:02 davidmlw

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

tgodzik avatar Feb 14 '22 16:02 tgodzik

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

davidmlw avatar May 10 '22 15:05 davidmlw

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

maxkorolev avatar Nov 08 '23 12:11 maxkorolev