diff --git a/README.md b/README.md index 6c3f9fb..70cf8ac 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A toolkit of great libraries to get started building Typelevel apps on JVM, Node.js, and Native! Our very own flavour of the [Scala Toolkit]. -```scala +```scala 3 //> using toolkit typelevel:default import cats.effect.* @@ -25,7 +25,7 @@ scala-cli --power new typelevel/toolkit.g8 * [http4s Ember client] * [Circe] and http4s integration * [Decline Effect] -* [Munit Cats Effect] +* [Weaver Test] [Scala Toolkit]: https://docs.scala-lang.org/toolkit/introduction.html [Cats]: https://typelevel.org/cats @@ -36,4 +36,4 @@ scala-cli --power new typelevel/toolkit.g8 [http4s Ember Client]: https://http4s.org/v0.23/docs/client.html [Circe]: https://circe.github.io/circe/ [Decline Effect]: https://ben.kirw.in/decline/effect.html -[Munit Cats Effect]: https://github.com/typelevel/munit-cats-effect +[Weaver Test]: https://github.com/typelevel/weaver-test diff --git a/build.sbt b/build.sbt index 608823d..5e60bc6 100644 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,7 @@ import laika.helium.config._ import laika.config.{ChoiceConfig, Selections, SelectionConfig} import java.io.File -ThisBuild / tlBaseVersion := "0.1" +ThisBuild / tlBaseVersion := "0.2" ThisBuild / startYear := Some(2023) ThisBuild / tlSitePublishBranch := Some("main") ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("17")) @@ -40,8 +40,7 @@ lazy val toolkitTest = crossProject(JVMPlatform, JSPlatform, NativePlatform) libraryDependencies ++= Seq( "org.typelevel" %%% "cats-core" % "2.13.0", "org.typelevel" %%% "cats-effect-testkit" % "3.7.0", - "org.scalameta" %%% "munit" % "1.3.0", // not % Test, on purpose :) - "org.typelevel" %%% "munit-cats-effect" % "2.2.0" + "org.typelevel" %%% "weaver-cats" % "0.12.0" // not % Test, on purpose :) ), libraryDependencySchemes += "org.scala-native" %% "test-interface_native0.5" % VersionScheme.Always, mimaPreviousArtifacts := Set() @@ -52,7 +51,7 @@ lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform) .settings( name := "tests", libraryDependencies ++= Seq( - "org.typelevel" %%% "munit-cats-effect" % "2.2.0" % Test, + "org.typelevel" %%% "weaver-cats" % "0.12.0" % Test, "co.fs2" %%% "fs2-io" % "3.13.0" % Test, "org.virtuslab.scala-cli" %% "cli" % "1.13.0" cross (CrossVersion.for2_13Use3) ), @@ -117,8 +116,8 @@ lazy val docs = project "Cats Effect" ), TextLink.external( - "https://github.com/typelevel/munit-cats-effect", - "Munit Cats Effect" + "https://github.com/typelevel/weaver-test", + "Weaver Test" ) ) ) diff --git a/docs/index.md b/docs/index.md index d3c963e..b860841 100644 --- a/docs/index.md +++ b/docs/index.md @@ -14,7 +14,7 @@ Typelevel toolkit is a meta library that currently includes these libraries: - [Http4s Ember client] - [Circe] and http4s integration - [Decline Effect] -- [Munit Cats Effect] +- [Weaver Test] and it's published for Scala 2.13 and 3.3+. @@ -85,7 +85,7 @@ Enumerations in your codebase, see [this comment] for more info. [Http4s Ember Client]: https://http4s.org/v0.23/docs/client.html [Circe]: https://circe.github.io/circe/ [Decline Effect]: https://ben.kirw.in/decline/effect.html -[Munit Cats Effect]: https://github.com/typelevel/munit-cats-effect +[Weaver Test]: https://github.com/typelevel/weaver-test [this Enumeration method]: https://github.com/scala/scala/blob/v2.13.8/src/library/scala/Enumeration.scala#L190-L215= [this comment]: https://github.com/typelevel/cats-effect/issues/3051#issuecomment-1167026949 diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala index e3382ed..6c52c0a 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -18,19 +18,22 @@ package org.typelevel.toolkit import cats.effect.kernel.Resource import cats.effect.IO -import cats.syntax.parallel._ +import cats.syntax.parallel.* import buildinfo.BuildInfo import fs2.Stream import fs2.io.file.Files import fs2.io.process.ProcessBuilder -import munit.Assertions.fail +import weaver.{Expectations, SourceLocation} +import weaver.Expectations.Helpers.{failure, success} object ScalaCliProcess { private val ClassPath: String = BuildInfo.classPath private val JavaHome: String = BuildInfo.javaHome - private def scalaCli(args: List[String]): IO[Unit] = ProcessBuilder( + private def scalaCli(args: List[String])(implicit + loc: SourceLocation + ): IO[Expectations] = ProcessBuilder( s"$JavaHome/bin/java", args.prependedAll(List("-cp", ClassPath, "scala.cli.ScalaCli")) ).spawn[IO] @@ -40,7 +43,7 @@ object ScalaCliProcess { process.stdout.through(fs2.text.utf8.decode).compile.string, process.stderr.through(fs2.text.utf8.decode).compile.string ).parFlatMapN { - case (0, _, _) => IO.unit + case (0, _, _) => IO.pure(success) case (exitCode, stdout, stdErr) => val errorMessage: String = List( Option(stdout).filter(_.nonEmpty).map(s => s"[STDOUT]: $s"), @@ -52,7 +55,7 @@ object ScalaCliProcess { case (summary, None) => summary } - IO.delay(fail(errorMessage)) + IO.pure(failure(errorMessage)) } ) @@ -79,12 +82,13 @@ object ScalaCliProcess { } .map(_.toString) - def command(args: List[String]): IO[Unit] = scalaCli(args) + def command(args: List[String])(implicit + loc: SourceLocation + ): IO[Expectations] = scalaCli(args) - def run(body: String): IO[Unit] = + def run(body: String)(implicit loc: SourceLocation): IO[Expectations] = writeToFile(body)(false).use(f => scalaCli("run" :: f :: Nil)) - def test(body: String): IO[Unit] = + def test(body: String)(implicit loc: SourceLocation): IO[Expectations] = writeToFile(body)(true).use(f => scalaCli("test" :: f :: Nil)) - } diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index 252c284..1597da5 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -16,17 +16,21 @@ package org.typelevel.toolkit -import munit.{CatsEffectSuite, TestOptions} +import cats.effect.IO import buildinfo.BuildInfo.scala3 -import scala.concurrent.duration._ +import weaver.* +import scala.concurrent.duration.* -class ToolkitCompilationTest extends CatsEffectSuite { +object ToolkitCompilationTest extends SimpleIOSuite { // 2 minutes may seem a lot, but consider that the first test for // each (scalaVersion, platform) will have to download the compiler // (if it's not the default), compile (that for native takes awhile) // and then finally run the code. - override def munitIOTimeout: Duration = 2.minute + private val TestTimeout = 4.minutes + + // This helps improve times on Native, more investigation is needed to understand why. + override val maxParallelism = 1 testRun("Toolkit should run a simple Hello Cats Effect") { if (scala3) @@ -67,26 +71,36 @@ class ToolkitCompilationTest extends CatsEffectSuite { |}""" } - testTest("Toolkit should execute a simple munit suite") { + testTest("Toolkit should execute a simple weaver suite") { if (scala3) - """|import cats.effect.* - |import munit.* + """|import cats.effect.IO + |import weaver.* | - |class Test extends CatsEffectSuite: - | test("test")(IO.unit)""" + |object Test extends SimpleIOSuite: + | test("test")(IO.pure(success))""" else - """|import cats.effect._ - |import munit._ + """|import cats.effect.IO + |import weaver._ | - |class Test extends CatsEffectSuite { - | test("test")(IO.unit) + |object Test extends SimpleIOSuite { + | test("test")(IO.pure(success)) |}""" } - def testRun(testName: TestOptions)(scriptBody: String): Unit = - test(testName)(ScalaCliProcess.run(scriptBody)) + private def withTimeout(test: IO[Expectations]): IO[Expectations] = + test.timeoutTo( + TestTimeout, + IO.pure(failure(s"Test exceeded timeout of $TestTimeout")) + ) + + def testRun(testName: String)(scriptBody: String): Unit = + test(testName) { + withTimeout(ScalaCliProcess.run(scriptBody)) + } - def testTest(testName: TestOptions)(scriptBody: String): Unit = - test(testName)(ScalaCliProcess.test(scriptBody)) + def testTest(testName: String)(scriptBody: String): Unit = + test(testName) { + withTimeout(ScalaCliProcess.test(scriptBody)) + } }