Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass in correct explicitlySpecified and selectors when creating TestDefinitions #5609

Open
antoine-mulet opened this issue Jun 10, 2020 · 4 comments

Comments

@antoine-mulet
Copy link

Simply something that has never been implemented it seems. For example Scalatest relies on these two fields to implement the tasks run logic so it's a shame they are currently hardcoded.

// TODO: To pass in correct explicitlySpecified and selectors
val tests =
for {
(df, di) <- discovered
fingerprint <- toFingerprints(di)
} yield new TestDefinition(df.name, fingerprint, false, Array(new SuiteSelector: Selector))

This is the first time I take a look at the sbt code but if someone can provide me with some guidance I would be happy to contribute.

@eed3si9n
Copy link
Member

@antoine-mulet Thanks for the report. Could you provide reproduction steps so we can reproduce your problem on our computers?

@antoine-mulet
Copy link
Author

@eed3si9n sorry if something wasn't clear. I didn't think a proper repro was necessary here because we are talking about an interface that has been partially implemented using hardcoded default values.

To give a bit more details, here is what I understand about the issue:

sbt TestDefinition

final class TestDefinition(
val name: String,
val fingerprint: Fingerprint,
val explicitlySpecified: Boolean,
val selectors: Array[Selector]
) {

maps to test-interface TaskDef

https://github.com/harrah/test-interface/blob/17a94641942546e21f4c6b300a3360be2d2888f6/src/main/java/sbt/testing/TaskDef.java

In there it is very clear what explicitlySpecified is supposed to be

https://github.com/harrah/test-interface/blob/17a94641942546e21f4c6b300a3360be2d2888f6/src/main/java/sbt/testing/TaskDef.java#L15-L43

and same for selectors

https://github.com/harrah/test-interface/blob/17a94641942546e21f4c6b300a3360be2d2888f6/src/main/java/sbt/testing/Selector.java

However explicitlySpecified and selectors are simply not implemented on the sbt side. So down the line when test frameworks like ScalaTest rely on those fields, it leads to bugs like scalatest/scalatest#417 for example.

That being said, to answer the original question, here is how you can reproduce the issue with ScalaTest:

  1. Define a Scalatest suite
import org.scalatest.DoNotDiscover
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

@DoNotDiscover
class FooTestSuite extends AnyFlatSpec with Matchers {

  it should "run" in {
    1 + 1 shouldBe 2
  }
}
  1. Run it with sbt

sbt "testOnly com.foo.test.FooTestSuite"

  1. The output shows that no tests were run
[info] ScalaTest
[info] Run completed in 23 minutes, 27 seconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.

And this is because explicitlySpecified was set to false by sbt (as always in the current implementation) while it should have been set to true to let the suite be discovered properly. The same way any logic relying on the correct values to be set for selectors would potentially lead to bugs.

Another way to double check the issue is to run the same sbt command in debug mode with breakpoints in the sbt / ScalaTest code to inspect the values of explicitlySpecified and selectors.

I hope everything is clearer with the explanations above, if still not please let me know.

@antoine-mulet
Copy link
Author

Hi @eed3si9n, do you have any comments? Is everything above clear?

Thanks,
Antoine

@eed3si9n
Copy link
Member

Thanks for unpacking this. @DoNotDiscover sounds like a good repro step for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants