Skip to content

Commit 7545297

Browse files
committed
Add tests for the zio-test test framework
1 parent 8d0120c commit 7545297

File tree

1 file changed

+84
-12
lines changed

1 file changed

+84
-12
lines changed

modules/integration/src/test/scala/scala/cli/integration/TestTestDefinitions.scala

Lines changed: 84 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ abstract class TestTestDefinitions extends ScalaCliSuite with TestScalaVersionAr
99
_: TestScalaVersion =>
1010
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions
1111
private val utestVersion = "0.8.3"
12+
private val zioTestVersion = "2.1.17"
1213

1314
def successfulTestInputs(directivesString: String =
1415
s"//> using dep org.scalameta::munit::$munitVersion"): TestInputs = TestInputs(
@@ -811,23 +812,81 @@ abstract class TestTestDefinitions extends ScalaCliSuite with TestScalaVersionAr
811812
}
812813
}
813814

815+
test(s"zio-test warning when zio-test-sbt was not passed") {
816+
TestUtil.retryOnCi() {
817+
val expectedMessage = "Hello from zio"
818+
TestInputs(os.rel / "Zio.test.scala" ->
819+
s"""//> using test.dep dev.zio::zio-test::$zioTestVersion
820+
|import zio._
821+
|import zio.test._
822+
|
823+
|object SimpleSpec extends ZIOSpecDefault {
824+
| override def spec: Spec[TestEnvironment with Scope, Any] =
825+
| suite("SimpleSpec")(
826+
| test("print hello and assert true") {
827+
| for {
828+
| _ <- Console.printLine("$expectedMessage")
829+
| } yield assertTrue(true)
830+
| }
831+
| )
832+
|}
833+
|""".stripMargin).fromRoot { root =>
834+
val r = os.proc(TestUtil.cli, "test", ".", extraOptions)
835+
.call(cwd = root, check = false, stderr = os.Pipe)
836+
expect(r.exitCode == 1)
837+
val expectedWarning =
838+
"zio-test found in the class path, zio-test-sbt should be added to run zio tests"
839+
expect(r.err.trim().contains(expectedWarning))
840+
}
841+
}
842+
}
843+
814844
for {
815845
platformOptions <- Seq(
816846
Nil, // JVM
817847
Seq("--native"),
818848
Seq("--js")
819849
)
820850
platformDescription = platformOptions.headOption.map(o => s" ($o)").getOrElse(" (JVM)")
821-
}
851+
} {
852+
test(s"zio-test$platformDescription") {
853+
TestUtil.retryOnCi() {
854+
val expectedMessage = "Hello from zio"
855+
TestInputs(os.rel / "Zio.test.scala" ->
856+
s"""//> using test.dep dev.zio::zio-test::$zioTestVersion
857+
|//> using test.dep dev.zio::zio-test-sbt::$zioTestVersion
858+
|import zio._
859+
|import zio.test._
860+
|
861+
|object SimpleSpec extends ZIOSpecDefault {
862+
| override def spec: Spec[TestEnvironment with Scope, Any] =
863+
| suite("SimpleSpec")(
864+
| test("print hello and assert true") {
865+
| for {
866+
| _ <- Console.printLine("$expectedMessage")
867+
| } yield assertTrue(true)
868+
| }
869+
| )
870+
|}
871+
|""".stripMargin).fromRoot { root =>
872+
val r = os.proc(TestUtil.cli, "test", ".", extraOptions, platformOptions).call(cwd = root)
873+
val output = r.out.trim()
874+
expect(output.contains(expectedMessage))
875+
expect(countSubStrings(output, expectedMessage) == 1)
876+
}
877+
}
878+
}
879+
822880
test(s"multiple test frameworks$platformDescription") {
823-
val scalatestMessage = "Hello from ScalaTest"
824-
val munitMessage = "Hello from Munit"
825-
val utestMessage = "Hello from utest"
881+
val expectedMessages @ Seq(scalatestMessage, munitMessage, utestMessage, zioMessage) =
882+
Seq("Hello from ScalaTest", "Hello from Munit", "Hello from utest", "Hello from zio")
826883
TestInputs(
827884
os.rel / "project.scala" ->
828885
s"""//> using test.dep org.scalatest::scalatest::3.2.19
829886
|//> using test.dep org.scalameta::munit::$munitVersion
830887
|//> using dep com.lihaoyi::utest::$utestVersion
888+
|//> using test.dep dev.zio::zio-test::$zioTestVersion
889+
|//> using test.dep dev.zio::zio-test-sbt::$zioTestVersion
831890
|""".stripMargin,
832891
os.rel / "scalatest.test.scala" ->
833892
s"""import org.scalatest.flatspec.AnyFlatSpec
@@ -859,18 +918,31 @@ abstract class TestTestDefinitions extends ScalaCliSuite with TestScalaVersionAr
859918
| println("$utestMessage")
860919
| }
861920
| }
862-
|}""".stripMargin
921+
|}""".stripMargin,
922+
os.rel / "Zio.test.scala" ->
923+
s"""import zio._
924+
|import zio.test._
925+
|
926+
|object SimpleSpec extends ZIOSpecDefault {
927+
| override def spec: Spec[TestEnvironment with Scope, Any] =
928+
| suite("SimpleSpec")(
929+
| test("print hello and assert true") {
930+
| for {
931+
| _ <- Console.printLine("$zioMessage")
932+
| } yield assertTrue(true)
933+
| }
934+
| )
935+
|}
936+
|""".stripMargin
863937
).fromRoot { root =>
864938
val r = os.proc(TestUtil.cli, "test", extraOptions, ".", platformOptions).call(cwd = root)
865939
val output = r.out.trim()
866940
expect(output.nonEmpty)
867-
expect(output.contains(scalatestMessage))
868-
expect(countSubStrings(output, scalatestMessage) == 1)
869-
expect(output.contains(munitMessage))
870-
expect(countSubStrings(output, munitMessage) == 1)
871-
expect(output.contains(utestMessage))
872-
expect(countSubStrings(output, utestMessage) == 1)
873-
println(output)
941+
expectedMessages.foreach { expectedMessage =>
942+
expect(output.contains(expectedMessage))
943+
expect(countSubStrings(output, expectedMessage) == 1)
944+
}
874945
}
875946
}
947+
}
876948
}

0 commit comments

Comments
 (0)