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

#1259: Simple Test Framework for SBT #1335

Merged
merged 22 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
537b377
#1259: Simple Test Framework for SBT
NeQuissimus Apr 5, 2019
59ad98d
scalafmt fix for sbt
dkarlinsky Aug 3, 2019
719eaff
fixing test framework registration in sbt
dkarlinsky Aug 3, 2019
3891b04
Using portablescala-reflect for loading specs, for scalajs support;
dkarlinsky Aug 3, 2019
0f0467c
scalafmt fix for build.sbt
dkarlinsky Aug 3, 2019
94c85b7
sbt: added testRunnerJS and testRunnerJVM to aggregate;
dkarlinsky Aug 4, 2019
6f52570
scalafmt fixes
dkarlinsky Aug 4, 2019
398274d
sbt doesn't seem support parametrized classes in SubclassFingerprint …
dkarlinsky Aug 4, 2019
47e6976
removed the dash from test framework name
dkarlinsky Aug 4, 2019
32bd619
reusing the platform of the spec's runner to run the spec
dkarlinsky Aug 4, 2019
16245a5
scalafmt fix
dkarlinsky Aug 4, 2019
89e92bb
getting rid of ZSpecStructure, using spec.foldM() to report results
dkarlinsky Aug 4, 2019
b793b60
* not using specs2 for testing;
dkarlinsky Aug 4, 2019
56d6151
Tests now run from SBT testJVM;
dkarlinsky Aug 5, 2019
bf54bf7
scalafmt fix
dkarlinsky Aug 5, 2019
3e7670f
Exposed rendered results (intermediate format) in DefaultTestReporter…
dkarlinsky Aug 5, 2019
b179055
Adding AbstractRunnableSpec to make extending more streamlined
dkarlinsky Aug 6, 2019
c67b19a
scalafmt fixes
dkarlinsky Aug 6, 2019
e8e7f91
moved DummySpec, used to test sbt runner to examples project
dkarlinsky Aug 6, 2019
78bf297
implemented scala.js test runner;
dkarlinsky Aug 6, 2019
1635011
scalafmt fixes
dkarlinsky Aug 6, 2019
83d6653
reversed the hierarchy between RunnableSpec and AbstractRunnableSpec
dkarlinsky Aug 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 45 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ inThisBuild(
addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt")
addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck")
addCommandAlias("compileJVM", ";coreJVM/test:compile;stacktracerJVM/test:compile")
addCommandAlias("testJVM", ";coreTestsJVM/test;stacktracerJVM/test;streamsTestsJVM/test;testJVM/test:run")
addCommandAlias(
"testJVM",
";coreTestsJVM/test;stacktracerJVM/test;streamsTestsJVM/test;testJVM/test:run;testRunnerJVM/test:run"
)
addCommandAlias("testJS", ";coreTestsJS/test;stacktracerJS/test;streamsTestsJS/test;testJS/test:run")

lazy val root = project
Expand All @@ -55,7 +58,9 @@ lazy val root = project
testJVM,
testJS,
stacktracerJS,
stacktracerJVM
stacktracerJVM,
testRunnerJS,
testRunnerJVM
)
.enablePlugins(ScalaJSPlugin)

Expand Down Expand Up @@ -124,6 +129,11 @@ lazy val test = crossProject(JSPlatform, JVMPlatform)
.in(file("test"))
.dependsOn(core, streams)
.settings(stdSettings("zio-test"))
.settings(
libraryDependencies ++= Seq(
"org.portable-scala" %%% "portable-scala-reflect" % "0.1.0"
)
)

lazy val testJVM = test.jvm
lazy val testJS = test.js.settings(
Expand All @@ -148,6 +158,39 @@ lazy val stacktracerJVM = stacktracer.jvm
.settings(dottySettings)
.settings(replSettings)

lazy val testRunner = crossProject(JVMPlatform, JSPlatform)
.in(file("test-sbt"))
.settings(stdSettings("zio-test-sbt"))
.settings(
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.portable-scala" %%% "portable-scala-reflect" % "0.1.0"
),
mainClass in (Test, run) := Some("zio.test.runner.ZTestFrameworkSpec")
)
.jsSettings(libraryDependencies ++= Seq("org.scala-js" %% "scalajs-test-interface" % "0.6.28"))
.jvmSettings(libraryDependencies ++= Seq("org.scala-sbt" % "test-interface" % "1.0"))
.dependsOn(core % "test->test;compile->compile")
.dependsOn(test % "test->test;compile->compile")
.dependsOn(coreTests % "test->test;compile->compile")

lazy val testRunnerJVM = testRunner.jvm
lazy val testRunnerJS = testRunner.js

/**
* Examples sub-project that is not included in the root project.
* To run tests :
* `sbt "examplesJVM/test"`
*/
lazy val examples = crossProject(JVMPlatform, JSPlatform)
.in(file("examples"))
.settings(stdSettings("examples"))
.settings(testFrameworks += new TestFramework("zio.test.runner.ZTestFramework"))
.dependsOn(testRunner % "test->test;compile->compile")

lazy val examplesJS = examples.js
lazy val examplesJVM = examples.jvm

lazy val benchmarks = project.module
.dependsOn(coreJVM, streamsJVM)
.enablePlugins(JmhPlugin)
Expand Down
14 changes: 14 additions & 0 deletions examples/js/src/test/scala/zio/examples/test/ExampleJsSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package zio.examples.test

import zio.test.{DefaultRunnableSpec, Predicate, assert, suite, test}

object ExampleJsSpec extends DefaultRunnableSpec (
suite("some suite")(
test("failing test") {
assert(1, Predicate.equals(2))
},
test("passing test") {
assert(1, Predicate.equals(1))
}
)
)
14 changes: 14 additions & 0 deletions examples/jvm/src/test/scala/zio/examples/test/ExampleSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package zio.examples.test

import zio.test.{DefaultRunnableSpec, Predicate, assert, suite, test}

object ExampleSpec extends DefaultRunnableSpec(
suite("some suite") (
test("failing test") {
assert(1, Predicate.equals(2))
},
test("passing test") {
assert(1, Predicate.equals(1))
}
)
)
37 changes: 37 additions & 0 deletions test-sbt/js/src/main/scala/zio/test/runner/ZTestFramework.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2019 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.test.runner

import sbt.testing._

final class ZTestFramework extends Framework {
override val name = s"${Console.UNDERLINED}ZIO Test${Console.RESET}"

val fingerprints: Array[Fingerprint] = Array(RunnableSpecFingerprint)

override def runner(args: Array[String], remoteArgs: Array[String], testClassLoader: ClassLoader): Runner =
new ZTestRunner(args, remoteArgs, testClassLoader, "master")

override def slaveRunner(
args: Array[String],
remoteArgs: Array[String],
testClassLoader: ClassLoader,
send: String => Unit
): Runner =
new ZTestRunner(args, remoteArgs, testClassLoader, "slave")

}
52 changes: 52 additions & 0 deletions test-sbt/js/src/main/scala/zio/test/runner/ZTestRunner.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2019 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.test.runner

import sbt.testing._
import zio.{ Exit, Runtime }

final class ZTestRunner(
val args: Array[String],
val remoteArgs: Array[String],
testClassLoader: ClassLoader,
runnerType: String
) extends Runner {
def done(): String = "Done"
def tasks(defs: Array[TaskDef]): Array[Task] =
defs.map(new ZTestTask(_, testClassLoader, runnerType))

override def receiveMessage(msg: String): Option[String] = None

override def serializeTask(task: Task, serializer: TaskDef => String): String =
serializer(task.taskDef)

override def deserializeTask(task: String, deserializer: String => TaskDef): Task =
new ZTestTask(deserializer(task), testClassLoader, runnerType)
}

class ZTestTask(taskDef: TaskDef, testClassLoader: ClassLoader, runnerType: String)
extends BaseTestTask(taskDef, testClassLoader) {

def execute(eventHandler: EventHandler, loggers: Array[Logger], continuation: Array[Task] => Unit): Unit =
Runtime((), spec.platform).unsafeRunAsync(run(eventHandler, loggers)) { exit =>
exit match {
case Exit.Failure(cause) => Console.err.println(s"$runnerType failed: " + cause.prettyPrint)
case _ =>
}
continuation(Array())
}
}
28 changes: 28 additions & 0 deletions test-sbt/jvm/src/main/scala/zio/test/runner/ZTestFramework.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2019 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.test.runner

import sbt.testing._

final class ZTestFramework extends Framework {
override val name = s"${Console.UNDERLINED}ZIO Test${Console.RESET}"

val fingerprints: Array[Fingerprint] = Array(RunnableSpecFingerprint)

override def runner(args: Array[String], remoteArgs: Array[String], testClassLoader: ClassLoader): ZTestRunner =
new ZTestRunner(args, remoteArgs, testClassLoader)
}
27 changes: 27 additions & 0 deletions test-sbt/jvm/src/main/scala/zio/test/runner/ZTestRunner.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2019 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.test.runner

import sbt.testing._

final class ZTestRunner(val args: Array[String], val remoteArgs: Array[String], testClassLoader: ClassLoader)
extends Runner {
def done(): String = "Done"
def tasks(defs: Array[TaskDef]): Array[Task] = defs.map(new ZTestTask(_, testClassLoader))
}

class ZTestTask(taskDef: TaskDef, testClassLoader: ClassLoader) extends BaseTestTask(taskDef, testClassLoader)