Skip to content

Commit

Permalink
Simplified test helper code
Browse files Browse the repository at this point in the history
This also avoids defining a `T.command` inside of a class which does not extend `mill.define.Module`.
  • Loading branch information
lefou committed Nov 18, 2023
1 parent c8992cb commit df34422
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -175,42 +175,42 @@ object `native-mostly-static` extends ScalaJsCliMostlyStaticNativeImage
object tests extends ScalaModule {
def scalaVersion = scala213

object test extends ScalaTests {
object test extends ScalaTests with TestModule.Munit {
def ivyDeps = super.ivyDeps() ++ Seq(
ivy"org.scalameta::munit:0.7.29",
ivy"com.lihaoyi::os-lib:0.9.1",
ivy"com.lihaoyi::pprint:0.8.1"
)
def testFramework = "munit.Framework"

private final class TestHelper(
launcherTask: T[PathRef]
) {
def test(args: String*) = {
val argsTask = T.task {
val launcher = launcherTask().path
val extraArgs = Seq(
s"-Dtest.scala-js-cli.path=$launcher",
s"-Dtest.scala-js-cli.scala-js-version=$scalaJsVersion"
)
args ++ extraArgs
}
T.command {
testTask(argsTask, T.task(Seq.empty[String]))()
}

def testHelper(
launcherTask: Task[PathRef],
args: Seq[String]
): Task[(String, Seq[mill.testrunner.TestResult])] = {
val argsTask = T.task {
val launcher = launcherTask().path
val extraArgs = Seq(
s"-Dtest.scala-js-cli.path=$launcher",
s"-Dtest.scala-js-cli.scala-js-version=$scalaJsVersion"
)
args ++ extraArgs
}
testTask(argsTask, T.task(Seq.empty[String]))
}

def test(args: String*) =
jvm(args: _*)
def jvm(args: String*) =
new TestHelper(cli.standaloneLauncher).test(args: _*)
def native(args: String*) =
new TestHelper(native0.nativeImage).test(args: _*)
def nativeStatic(args: String*) =
new TestHelper(`native-static`.nativeImage).test(args: _*)
def nativeMostlyStatic(args: String*) =
new TestHelper(`native-mostly-static`.nativeImage).test(args: _*)
override def test(args: String*) = jvm(args: _*)

def jvm(args: String*): Command[(String, Seq[mill.testrunner.TestResult])] = T.command {
testHelper(cli.standaloneLauncher, args)
}
def native(args: String*) = T.command {
testHelper(native0.nativeImage, args)
}
def nativeStatic(args: String*) = T.command {
testHelper(`native-static`.nativeImage, args)
}
def nativeMostlyStatic(args: String*) = T.command {
testHelper(`native-mostly-static`.nativeImage, args)
}
}
}

Expand Down

0 comments on commit df34422

Please sign in to comment.