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
#1259: Simple Test Framework for SBT #1335
Conversation
b297e88
to
527e148
Compare
@jdegoes, I'm kinda stuck trying to get lazy val testRunnerTesting = crossProject(JVMPlatform)
.in(file("test-sbt-testing"))
.settings(stdSettings("zio-test-sbt-testing"))
.settings(testFrameworks += new TestFramework("zio.test.runner.ZTestFramework"))
.dependsOn(testRunner % "test->test;compile->compile") The sub-project contains a single RunnableSpec object
Which shows that the test framework is picked up, but the spec is not discovered... |
Ok, I think I figured it out. |
@dkarlinsky Could it be name mangling or some other thing that's causing the problem?
|
|
||
sealed abstract class ExecutedSpecStructure { | ||
def stats: Stats | ||
def traverse[R]( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to reinvent foldM
, will look more further down.
} | ||
} | ||
|
||
sealed abstract class ZTestResult(val stats: Stats) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can reuse Assertion
here. It has the same structure (you are using constants for Ignore
and Success
).
Otherwise we have 2 data structures with a similar hierarchy (success, ignore, failure w/value).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this makes sense now.
test-sbt/shared/src/main/scala/zio/test/runner/ZSpecStructure.scala
Outdated
Show resolved
Hide resolved
@jdegoes don't think so.
As you can see |
test-sbt/shared/src/main/scala/zio/test/runner/ZTestFramework.scala
Outdated
Show resolved
Hide resolved
test-sbt/shared/src/main/scala/zio/test/runner/ZTestFramework.scala
Outdated
Show resolved
Hide resolved
test-sbt/shared/src/main/scala/zio/test/runner/ZTestRunner.scala
Outdated
Show resolved
Hide resolved
test-sbt/shared/src/main/scala/zio/test/runner/ZTestRunner.scala
Outdated
Show resolved
Hide resolved
object Reflect { | ||
type EnableReflectiveInstantiation = | ||
org.portablescala.reflect.annotation.EnableReflectiveInstantiation | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N/A
|
||
/** | ||
* A `RunnableSpec` has a main function and can be run by the JVM / Scala.js. | ||
*/ | ||
@EnableReflectiveInstantiation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes ZIO test have a dependency on portable reflection library. Hmm, we have to think if it's worth it or not. Does it support Dotty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it might not...
It says: Scala 2.10.x, 2.11.x, 2.12.x and 2.13.0-M4
on their readme.
In any case it looks like I'm still missing some pieces to have sbt run specs under Scala.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scalatest recently ported & published for dotty, might want to look at what they do. (Also, dotty works just fine with 2.12 test frameworks under DottyCompat mode, might not need any special support)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, let's leave it in for now, we can decide for sure later! Maybe some small Scala.js code is all we need to do the reflection (iterate keys in global
/ window
).
test-sbt/jvm/src/test/scala/zio/test/runner/ZTestFrameworkSpec.scala
Outdated
Show resolved
Hide resolved
@dkarlinsky Great detective work! I think this is a bug in SBT. However, we can work around it in ZIO test. We can change abstract class RunnableSpec {
type Label
type Test
def runner: TestRunner[Label, Test]
def spec = Spec[Label, Test]
/**
* A simple main function that can be used to run the spec.
*
* TODO: Parse command line options.
*/
final def main(args: Array[String]): Unit = { val _ = runner.unsafeRunSync(spec) }
/**
* Returns an effect that executes the spec, producing the results of the execution.
*/
final val run: UIO[ExecutedSpec[Label]] = runner.run(spec)
}
object RunnableSpec {
type Aux[L, T] = RunnableSpec { type Label = L; type Test = T }
def apply[L, T](runner0: TestRunner[L, T])(spec0: => Spec[Label, Test]): RunnableSpec =
new RunnableSpec {
type Label = L
type Test = T
def runner = runner0
def spec = spec0
}
} Now What do you think? |
test-sbt/shared/src/main/scala/zio/test/runner/ZTestRunner.scala
Outdated
Show resolved
Hide resolved
test-sbt/shared/src/main/scala/zio/test/runner/ZTestRunner.scala
Outdated
Show resolved
Hide resolved
This looks very nice as a constructor for a new |
test-sbt-testing/js/src/test/scala/zio/test/runner/DummyJSSpec.scala
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,14 @@ | |||
package zio.test.runner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add this to the top-level examples
project that depends on both ZIO Core and ZIO Tests. It can have examples of both ZIO Test and ZIO proper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea for this project was to be able to manually run testRunnerTestingJVM/test
to test the sbt runner.
I guess I could to the same on the examples project...
Hmm, can you try this: abstract class AbstractRunnableSpec { ... } // As before
type RunnableSpec[L, T] = AbstractRunnableSpec { type Label = L; type Test = T } Then perhaps the user can do: class MyRunnableSpec extends RunnableSpec(MyRunner) {
...
} If we have the appropriate 2 parameter list constructor. |
WIP: couldn't make sbt actually run a RunnableSpec yet
This required adding @EnableReflectiveInstantiation to RunnableSpec
moved tests from shared to jvm.
…- switching to DefaultRunnableSpec for now
* making RunnableSpec on parametrized
improved test output
I don't think abstract class AbstractRunnableSpec[L, T](runner0: TestRunner[L, T])(spec0: => Spec[L, T]) extends RunnableSpec {
override type Label = L
override type Test = T
override def runner = runner0
override def spec =spec0
} Then |
@dkarlinsky Extending it should work; We use a lot of classes with type parameters that extend base Scalatest classes and they're discovered as expected. I'd expect the bug with type parameter handling to apply only to the class that you're searching for, not to subclasses. (Coincidentally, using defs in |
This is a good idea. So let's define the following: abstract class AbstractRunnableSpec {
type Label
type Test
def runner: TestRunner[Label, Test]
def spec: Spec[Label, Test])
...
}
abstract class RunnableSpec[L, T](runner: TestRunner[L, T])(spec0: => Spec[L, T]) extends AbstractRunnableSpec[L, T] {
type Label = L
type Test = T
def spec = spec0
} Now we have the same syntax as before, just with a workaround for the bug. Sound good? /cc @Kaishh |
@jdegoes I think I'm done with all the functionality and requested changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic!
@dkarlinsky Awesome work! ZIO Test is one more step closer to fully operational... |
#1259