rules_scala icon indicating copy to clipboard operation
rules_scala copied to clipboard

Running Individual Tests

Open KaoruDev opened this issue 5 years ago • 20 comments

I'm trying to run tests in a suite individually (i.e. in Intellij) by passing --test_arg=-t <test name> as per the scalatest docs. Alas, I get this exception:

==================== Test output for //bank-core/server:test:
Argument unrecognized by ScalaTest's Runner: /__main__/bazel-out/darwin-fastbuild/bin/package/test.jar.
================================================================================

is this expected?

KaoruDev avatar Sep 27 '19 19:09 KaoruDev

Can you write the full command line?

On Fri, 27 Sep 2019 at 22:29 Kaoru Kohashigawa [email protected] wrote:

I'm trying to run tests in a suite individually (i.e. in Intellij) by passing --test_arg=-t as per the scalatest docs. Alas, I get this exception:

==================== Test output for //bank-core/server:test: Argument unrecognized by ScalaTest's Runner: /main/bazel-out/darwin-fastbuild/bin/package/test.jar.

is this expected?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bazelbuild/rules_scala/issues/854?email_source=notifications&email_token=AAKQQF7CRNGDRMRBI3Q2ORTQLZNJHA5CNFSM4I3KBTV2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HOHPRJA, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKQQF3OHJUGOIETJE5LXGTQLZNJHANCNFSM4I3KBTVQ .

ittaiz avatar Sep 29 '19 09:09 ittaiz

Sure!

/usr/local/bin/bazel test  --test_filter=com.my.AppSpec --test_arg='-t "MyApp should start"'  -- //my/server:test

KaoruDev avatar Sep 29 '19 15:09 KaoruDev

What about:

/usr/local/bin/bazel test --test_filter=com.my.AppSpec --test_arg='-t "MyApp should start"' //my/server:test

Not sure why the last “—“ is needed in this case

On Sun, 29 Sep 2019 at 18:09 Kaoru Kohashigawa [email protected] wrote:

Sure!

/usr/local/bin/bazel test --test_filter=com.my.AppSpec --test_arg='-t "MyApp should start"' -- //my/server:test

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/bazelbuild/rules_scala/issues/854?email_source=notifications&email_token=AAKQQF6AFTPHTAVDXPHTPM3QMDAJZA5CNFSM4I3KBTV2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD73XLFY#issuecomment-536311191, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKQQF543BVWY3TAK4IBHQDQMDAJZANCNFSM4I3KBTVQ .

ittaiz avatar Oct 01 '19 04:10 ittaiz

same error 😞

KaoruDev avatar Oct 01 '19 11:10 KaoruDev

ok, I'm not well versed in scalatest unfortunately. How comfortable are you in debugging this? I can point you to a few directions and iterate with you but I'm afraid I won't have time to dive into this in the near future. If you're interested I'd be happy to help, Ittai

On Tue, Oct 1, 2019 at 2:18 PM Kaoru Kohashigawa [email protected] wrote:

same error 😞

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bazelbuild/rules_scala/issues/854?email_source=notifications&email_token=AAKQQF25MTV6INUAVRRCOJ3QMMWXXA5CNFSM4I3KBTV2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAA5EJY#issuecomment-536990247, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKQQF36XQY6BIWH2ZNTYFTQMMWXXANCNFSM4I3KBTVQ .

ittaiz avatar Oct 01 '19 11:10 ittaiz

no worries, I'm reading the Bazel rules sections to see if I can help out. I gotta poke around more before I can begin to formulate the right questions. Asking questions via this ticket the best way for you?

KaoruDev avatar Oct 01 '19 11:10 KaoruDev

Yes. Alternatively you can use the scala channel in the bazelbuild slack workspace. I try to be available there as well. Btw, I think that if you can dump the args to console out right before they go to scala test maybe it can be of interest to you: https://github.com/bazelbuild/rules_scala/blob/master/src/java/io/bazel/rulesscala/scala_test/Runner.java#L34 Essentially I think there might be 3 issues:

  1. You're passing in the wrong arg
  2. You're passing in the right arg but something in our handling malforms it before it gets to scalatest
  3. You're passing in the right arg but we're not propagating it to scalatest

On Tue, Oct 1, 2019 at 2:47 PM Kaoru Kohashigawa [email protected] wrote:

no worries, I'm reading the Bazel rules sections to see if I can help out. I gotta poke around more before I can begin to formulate the right questions. Asking questions via this ticket the best way for you?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bazelbuild/rules_scala/issues/854?email_source=notifications&email_token=AAKQQF3WPUGBSWOQRQKURDLQMM2FXA5CNFSM4I3KBTV2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAA7KQY#issuecomment-536999235, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKQQF56QSMCYJPHEZO3K4DQMM2FXANCNFSM4I3KBTVQ .

ittaiz avatar Oct 01 '19 11:10 ittaiz

👍 TIL a slack channel existed! Yeah, that's where I was looking at but couldn't make sense of the things around it, give me a few to level up my understanding of Bazel's rule APIs. Thanks @ittaiz !

KaoruDev avatar Oct 01 '19 11:10 KaoruDev

@KaoruDev did you figure this out? I think you just need two --test_args, one for the -t and the other for the test name

copumpkin avatar Apr 01 '20 15:04 copumpkin

no i have not, this is what I tried:

bazel test --test_output=streamed --test_arg="--test_filter=com.example.MySpec -t '#methodName'" -- my/target:test

KaoruDev avatar Apr 01 '20 16:04 KaoruDev

@KaoruDev - I was having similar issues and cloned rules_scala locally to see what args were being passed to Scalatest's Runner.

I think the issue is with this line: https://github.com/bazelbuild/rules_scala/blob/master/src/java/io/bazel/rulesscala/scala_test/Runner.java#L39 It will add -s com.example.MySpec when you add --test_filter=com.example.MySpec and from what I gather that will run all of the tests in the spec: http://www.scalatest.org/user_guide/using_the_runner

The workaround for me was to remove --test_filter=com.example.MySpec and to just specify -z like: bazel test //services:tests --test_arg='-z' --test_arg='my test name substring'

Let me know if this works for you.

cridmann avatar Apr 14 '20 01:04 cridmann

oh nice ok that did it, so if I wanted Intellij to support this would this now be an Intellij bug?

KaoruDev avatar Apr 14 '20 12:04 KaoruDev

I think it can go either way honestly though given the work over there your chances are low on the IntelliJ side. Also the fact that our runner doesn’t support the bazel idiom sounds problematic.

On Tue, 14 Apr 2020 at 15:26 Kaoru Kohashigawa [email protected] wrote:

oh nice ok that did it, so I wanted Intellij to support this would this now be an Intellij bug?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bazelbuild/rules_scala/issues/854#issuecomment-613412730, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKQQF67OVDL5M44MKS7ZX3RMRJABANCNFSM4I3KBTVQ .

--

Ittai Zeidman

40 Hanamal street, Tel Aviv, Israel

http://www.wix.com

ittaiz avatar Apr 14 '20 12:04 ittaiz

I was going for remote debugging with intellij as well.

It works when I put the following args "-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" into

jvm_flags of scala_test https://github.com/bazelbuild/rules_scala/blob/master/docs/scala_test.md

However, when I try to just add it onto an adhoc command (and remove it from the jvm_flags), I get address already in use errors, presumably because it's forking the jvm and passing along the args.

bazel test //services:tests --test_arg=-z --test_arg='my test' --jvmopt='-Xdebug' --jvmopt='-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005' --test_output=streamed

Any ideas around this one? I'll keep exploring as well.

cridmann avatar Apr 14 '20 16:04 cridmann

Okay figured that out too: bazel test //services:tests --test_arg=-z --test_arg='my test' --java_debug --test_output=streamed

It'll start the test and listen for a connection. I then start intellij with a remote debug config of "Attach to remote JVM". Works like a charm.

cridmann avatar Apr 14 '20 16:04 cridmann

I also got the same error when running the tests from my intelliJ plugin and command line.

It happened when i was trying to run all scala tests in my bazel projects:

bazel test //...

The error looks like this:

**exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //scala/..../impl:InProcessInferencerTest
-----------------------------------------------------------------------------
Argument unrecognized by ScalaTest's Runner: /private/var/tmp/_bazel_rfan/....../InProcessInferencerTest.jar.**

It seems that rules_scala did not place the correct argument between the ScalaTest runner and the actual test jar built by bazel.

rfan-debug avatar Jul 06 '21 19:07 rfan-debug

I also got the same error when running the tests from my intelliJ plugin and command line.

It happened when i was trying to run all scala tests in my bazel projects:

bazel test //...

The error looks like this:

**exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //scala/..../impl:InProcessInferencerTest
-----------------------------------------------------------------------------
Argument unrecognized by ScalaTest's Runner: /private/var/tmp/_bazel_rfan/....../InProcessInferencerTest.jar.**

It seems that rules_scala did not place the correct argument between the ScalaTest runner and the actual test jar built by bazel.

@rfan-debug any chance you can make a small repro project to demonstrate this problem?

liucijus avatar Jul 07 '21 05:07 liucijus

I also got the same error when running the tests from my intelliJ plugin and command line. It happened when i was trying to run all scala tests in my bazel projects:

bazel test //...

The error looks like this:

**exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //scala/..../impl:InProcessInferencerTest
-----------------------------------------------------------------------------
Argument unrecognized by ScalaTest's Runner: /private/var/tmp/_bazel_rfan/....../InProcessInferencerTest.jar.**

It seems that rules_scala did not place the correct argument between the ScalaTest runner and the actual test jar built by bazel.

@rfan-debug any chance you can make a small repro project to demonstrate this problem?

@liucijus We found out the issue after creating a small demo repo. The issue came from the .bazelrc file. It contains a line:

# We need this to see outputs of Go tests.
test --test_arg=-test.v

The repo used to contain Go code only and recently we added scala code in, and then this test flag caused the odd behaviors i mentioned in the previous comment when it runs scala_test. We are still thinking about how to let this flag be used for Go test only.

Here is my demo repo: https://github.com/rfan-debug/bazel-scala-test

rfan-debug avatar Jul 07 '21 17:07 rfan-debug

# We need this to see outputs of Go tests.
test --test_arg=-test.v

The repo used to contain Go code only and recently we added scala code in, and then this test flag caused the odd behaviors i mentioned in the previous comment when it runs scala_test. We are still thinking about how to let this flag be used for Go test only.

Here is my demo repo: https://github.com/rfan-debug/bazel-scala-test

@rfan-debug any chance you can change how you configure go tests? I see there is a similar discussion https://github.com/bazelbuild/rules_go/issues/2344

liucijus avatar Jul 09 '21 07:07 liucijus

That's a good pointer! Thank you!

rfan-debug avatar Jul 09 '21 15:07 rfan-debug

@liucijus @KaoruDev can we please close that issue ? I can confirm that this issue is now resolved with latest rules_scala / Intellij / IJ Bazel plugin ! Thanks!

scoquelin avatar Dec 21 '23 19:12 scoquelin