Skip to content

Commit a2fdaaf

Browse files
authored
🔀 Merge pull request #316 from Hombre-x/weaver-migration
Migrate test library and suite from MUnit to Weaver
2 parents 87b5b6e + eb8f4d7 commit a2fdaaf

File tree

5 files changed

+56
-39
lines changed

5 files changed

+56
-39
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
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].
44

5-
```scala
5+
```scala 3
66
//> using toolkit typelevel:default
77

88
import cats.effect.*
@@ -25,7 +25,7 @@ scala-cli --power new typelevel/toolkit.g8
2525
* [http4s Ember client]
2626
* [Circe] and http4s integration
2727
* [Decline Effect]
28-
* [Munit Cats Effect]
28+
* [Weaver Test]
2929

3030
[Scala Toolkit]: https://docs.scala-lang.org/toolkit/introduction.html
3131
[Cats]: https://typelevel.org/cats
@@ -36,4 +36,4 @@ scala-cli --power new typelevel/toolkit.g8
3636
[http4s Ember Client]: https://http4s.org/v0.23/docs/client.html
3737
[Circe]: https://circe.github.io/circe/
3838
[Decline Effect]: https://ben.kirw.in/decline/effect.html
39-
[Munit Cats Effect]: https://github.com/typelevel/munit-cats-effect
39+
[Weaver Test]: https://github.com/typelevel/weaver-test

build.sbt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import laika.helium.config._
22
import laika.config.{ChoiceConfig, Selections, SelectionConfig}
33
import java.io.File
44

5-
ThisBuild / tlBaseVersion := "0.1"
5+
ThisBuild / tlBaseVersion := "0.2"
66
ThisBuild / startYear := Some(2023)
77
ThisBuild / tlSitePublishBranch := Some("main")
88
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("17"))
@@ -40,8 +40,7 @@ lazy val toolkitTest = crossProject(JVMPlatform, JSPlatform, NativePlatform)
4040
libraryDependencies ++= Seq(
4141
"org.typelevel" %%% "cats-core" % "2.13.0",
4242
"org.typelevel" %%% "cats-effect-testkit" % "3.7.0",
43-
"org.scalameta" %%% "munit" % "1.3.0", // not % Test, on purpose :)
44-
"org.typelevel" %%% "munit-cats-effect" % "2.2.0"
43+
"org.typelevel" %%% "weaver-cats" % "0.12.0" // not % Test, on purpose :)
4544
),
4645
libraryDependencySchemes += "org.scala-native" %% "test-interface_native0.5" % VersionScheme.Always,
4746
mimaPreviousArtifacts := Set()
@@ -52,7 +51,7 @@ lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
5251
.settings(
5352
name := "tests",
5453
libraryDependencies ++= Seq(
55-
"org.typelevel" %%% "munit-cats-effect" % "2.2.0" % Test,
54+
"org.typelevel" %%% "weaver-cats" % "0.12.0" % Test,
5655
"co.fs2" %%% "fs2-io" % "3.13.0" % Test,
5756
"org.virtuslab.scala-cli" %% "cli" % "1.13.0" cross (CrossVersion.for2_13Use3)
5857
),
@@ -117,8 +116,8 @@ lazy val docs = project
117116
"Cats Effect"
118117
),
119118
TextLink.external(
120-
"https://github.com/typelevel/munit-cats-effect",
121-
"Munit Cats Effect"
119+
"https://github.com/typelevel/weaver-test",
120+
"Weaver Test"
122121
)
123122
)
124123
)

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Typelevel toolkit is a meta library that currently includes these libraries:
1414
- [Http4s Ember client]
1515
- [Circe] and http4s integration
1616
- [Decline Effect]
17-
- [Munit Cats Effect]
17+
- [Weaver Test]
1818

1919
and it's published for Scala 2.13 and 3.3+.
2020

@@ -85,7 +85,7 @@ Enumerations in your codebase, see [this comment] for more info.
8585
[Http4s Ember Client]: https://http4s.org/v0.23/docs/client.html
8686
[Circe]: https://circe.github.io/circe/
8787
[Decline Effect]: https://ben.kirw.in/decline/effect.html
88-
[Munit Cats Effect]: https://github.com/typelevel/munit-cats-effect
88+
[Weaver Test]: https://github.com/typelevel/weaver-test
8989

9090
[this Enumeration method]: https://github.com/scala/scala/blob/v2.13.8/src/library/scala/Enumeration.scala#L190-L215=
9191
[this comment]: https://github.com/typelevel/cats-effect/issues/3051#issuecomment-1167026949

tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ package org.typelevel.toolkit
1818

1919
import cats.effect.kernel.Resource
2020
import cats.effect.IO
21-
import cats.syntax.parallel._
21+
import cats.syntax.parallel.*
2222
import buildinfo.BuildInfo
2323
import fs2.Stream
2424
import fs2.io.file.Files
2525
import fs2.io.process.ProcessBuilder
26-
import munit.Assertions.fail
26+
import weaver.{Expectations, SourceLocation}
27+
import weaver.Expectations.Helpers.{failure, success}
2728

2829
object ScalaCliProcess {
2930

3031
private val ClassPath: String = BuildInfo.classPath
3132
private val JavaHome: String = BuildInfo.javaHome
3233

33-
private def scalaCli(args: List[String]): IO[Unit] = ProcessBuilder(
34+
private def scalaCli(args: List[String])(implicit
35+
loc: SourceLocation
36+
): IO[Expectations] = ProcessBuilder(
3437
s"$JavaHome/bin/java",
3538
args.prependedAll(List("-cp", ClassPath, "scala.cli.ScalaCli"))
3639
).spawn[IO]
@@ -39,8 +42,8 @@ object ScalaCliProcess {
3942
process.exitValue,
4043
process.stdout.through(fs2.text.utf8.decode).compile.string,
4144
process.stderr.through(fs2.text.utf8.decode).compile.string
42-
).parFlatMapN {
43-
case (0, _, _) => IO.unit
45+
).parMapN {
46+
case (0, _, _) => success
4447
case (exitCode, stdout, stdErr) =>
4548
val errorMessage: String = List(
4649
Option(stdout).filter(_.nonEmpty).map(s => s"[STDOUT]: $s"),
@@ -52,7 +55,7 @@ object ScalaCliProcess {
5255
case (summary, None) => summary
5356
}
5457

55-
IO.delay(fail(errorMessage))
58+
failure(errorMessage)
5659
}
5760
)
5861

@@ -79,12 +82,13 @@ object ScalaCliProcess {
7982
}
8083
.map(_.toString)
8184

82-
def command(args: List[String]): IO[Unit] = scalaCli(args)
85+
def command(args: List[String])(implicit
86+
loc: SourceLocation
87+
): IO[Expectations] = scalaCli(args)
8388

84-
def run(body: String): IO[Unit] =
89+
def run(body: String)(implicit loc: SourceLocation): IO[Expectations] =
8590
writeToFile(body)(false).use(f => scalaCli("run" :: f :: Nil))
8691

87-
def test(body: String): IO[Unit] =
92+
def test(body: String)(implicit loc: SourceLocation): IO[Expectations] =
8893
writeToFile(body)(true).use(f => scalaCli("test" :: f :: Nil))
89-
9094
}

tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@
1616

1717
package org.typelevel.toolkit
1818

19-
import munit.{CatsEffectSuite, TestOptions}
19+
import cats.effect.IO
2020
import buildinfo.BuildInfo.scala3
21-
import scala.concurrent.duration._
21+
import weaver.*
22+
import scala.concurrent.duration.*
2223

23-
class ToolkitCompilationTest extends CatsEffectSuite {
24+
object ToolkitCompilationTest extends SimpleIOSuite {
2425

25-
// 2 minutes may seem a lot, but consider that the first test for
26+
// 4 minutes may seem a lot, but consider that the first test for
2627
// each (scalaVersion, platform) will have to download the compiler
2728
// (if it's not the default), compile (that for native takes awhile)
2829
// and then finally run the code.
29-
override def munitIOTimeout: Duration = 2.minute
30+
private val TestTimeout = 4.minutes
31+
32+
// We can disable parallelism for this suite, since it is CPU-bound anyway.
33+
override val maxParallelism = 1
3034

3135
testRun("Toolkit should run a simple Hello Cats Effect") {
3236
if (scala3)
@@ -67,26 +71,36 @@ class ToolkitCompilationTest extends CatsEffectSuite {
6771
|}"""
6872
}
6973

70-
testTest("Toolkit should execute a simple munit suite") {
74+
testTest("Toolkit should execute a simple weaver suite") {
7175
if (scala3)
72-
"""|import cats.effect.*
73-
|import munit.*
76+
"""|import cats.effect.IO
77+
|import weaver.*
7478
|
75-
|class Test extends CatsEffectSuite:
76-
| test("test")(IO.unit)"""
79+
|object Test extends SimpleIOSuite:
80+
| test("test")(IO.pure(success))"""
7781
else
78-
"""|import cats.effect._
79-
|import munit._
82+
"""|import cats.effect.IO
83+
|import weaver._
8084
|
81-
|class Test extends CatsEffectSuite {
82-
| test("test")(IO.unit)
85+
|object Test extends SimpleIOSuite {
86+
| test("test")(IO.pure(success))
8387
|}"""
8488
}
8589

86-
def testRun(testName: TestOptions)(scriptBody: String): Unit =
87-
test(testName)(ScalaCliProcess.run(scriptBody))
90+
private def withTimeout(test: IO[Expectations]): IO[Expectations] =
91+
test.timeoutTo(
92+
TestTimeout,
93+
IO.pure(failure(s"Test exceeded timeout of $TestTimeout"))
94+
)
95+
96+
def testRun(testName: String)(scriptBody: String): Unit =
97+
test(testName) {
98+
withTimeout(ScalaCliProcess.run(scriptBody))
99+
}
88100

89-
def testTest(testName: TestOptions)(scriptBody: String): Unit =
90-
test(testName)(ScalaCliProcess.test(scriptBody))
101+
def testTest(testName: String)(scriptBody: String): Unit =
102+
test(testName) {
103+
withTimeout(ScalaCliProcess.test(scriptBody))
104+
}
91105

92106
}

0 commit comments

Comments
 (0)