Skip to content

Manage test framework dependencies in TestModule traits #4968

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

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions example/scalalib/testing/1-test-suite/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package build
import mill._, scalalib._

object foo extends ScalaModule {
def scalaVersion = "2.13.8"
def scalaVersion = "2.13.15"
object test extends ScalaTests {
def mvnDeps = Seq(mvn"com.lihaoyi::utest:0.8.5")
def testFramework = "utest.runner.Framework"
Expand Down Expand Up @@ -63,10 +63,10 @@ compiling 2 ... source...
//
//// SNIPPET:BUILD2
object bar extends ScalaModule {
def scalaVersion = "2.13.8"
def scalaVersion = "2.13.15"

object test extends ScalaTests with TestModule.Utest {
def mvnDeps = Seq(mvn"com.lihaoyi::utest:0.8.5")
def utestVersion = "0.8.5"
}
}

Expand Down
10 changes: 4 additions & 6 deletions scalajslib/test/src/mill/scalajslib/CompileLinkTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ object CompileLinkTests extends TestSuite {
)

object `test-utest` extends ScalaJSTests with TestModule.Utest {
override def sources = Task.Sources { this.moduleDir / "src/utest" }
val utestVersion = if (JvmWorkerUtil.isScala3(crossScalaVersion)) "0.7.7" else "0.7.5"
override def mvnDeps = Seq(
mvn"com.lihaoyi::utest::$utestVersion"
)
override def sources = Task.Sources { "src/utest" }
override def utestVersion =
if (JvmWorkerUtil.isScala3(crossScalaVersion)) "0.7.7" else "0.7.5"
}

object `test-scalatest` extends ScalaJSTests with TestModule.ScalaTest {
override def sources = Task.Sources { this.moduleDir / "src/scalatest" }
override def sources = Task.Sources { "src/scalatest" }
override def mvnDeps = Seq(
mvn"org.scalatest::scalatest::3.1.2"
)
Expand Down
3 changes: 1 addition & 2 deletions scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ object MultiModuleTests extends TestSuite {
override def moduleDeps = Seq(shared)
override def mainClass = Some("Main")
object test extends ScalaJSTests with TestModule.Utest {
override def mvnDeps =
Seq(mvn"com.lihaoyi::utest::${sys.props.getOrElse("TEST_UTEST_VERSION", ???)}")
override def utestVersion = sys.props.getOrElse("TEST_UTEST_VERSION", ???)
}
}

Expand Down
6 changes: 2 additions & 4 deletions scalajslib/test/src/mill/scalajslib/NodeJSConfigTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import scala.util.Properties
object NodeJSConfigTests extends TestSuite {
val scalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???)
val scalaJSVersion = sys.props.getOrElse("TEST_SCALAJS_VERSION", ???)
val utestVersion = sys.props.getOrElse("TEST_UTEST_VERSION", ???)
val testUtestVersion = sys.props.getOrElse("TEST_UTEST_VERSION", ???)
val nodeArgsEmpty = List()
val nodeArgs2G = List("--max-old-space-size=2048")
val nodeArgs4G = List("--max-old-space-size=4096")
Expand Down Expand Up @@ -44,9 +44,7 @@ object NodeJSConfigTests extends TestSuite {

object `test-utest` extends ScalaJSTests with TestModule.Utest {
override def sources = Task.Sources { this.moduleDir / "src/utest" }
override def mvnDeps = Seq(
mvn"com.lihaoyi::utest::$utestVersion"
)
override def utestVersion = testUtestVersion
override def jsEnvConfig = Task { JsEnvConfig.NodeJs(args = nodeArgs) }
}
}
Expand Down
94 changes: 86 additions & 8 deletions scalalib/src/mill/scalalib/TestModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,20 @@ object TestModule {

/**
* TestModule using TestNG Framework to run tests.
* You need to provide the testng dependency yourself.
* You can override the [[testngVersion]] task or provide the UTest-dependency yourself.
*/
trait TestNg extends TestModule {

/** The TestNG version to use, or empty, if you want to provide the TestNG-dependency yourself. */
def testngVersion: T[String] = Task { "" }
override def testFramework: T[String] = "mill.testng.TestNGFramework"
override def mandatoryMvnDeps: T[Seq[Dep]] = Task {
super.mandatoryMvnDeps() ++ Seq(
mvn"com.lihaoyi:mill-contrib-testng:${mill.api.BuildInfo.millVersion}"
)
) ++
Seq(testngVersion())
.filter(!_.isBlank())
.map(v => mvn"org.testng:testng:${v.trim()}")
}
}

Expand All @@ -286,9 +292,18 @@ object TestModule {
* You may want to provide the junit dependency explicitly to use another version.
*/
trait Junit4 extends TestModule {

/** The JUnit4 version to use, or empty, if you want to provide the Junit-dependency yourself. */
def junit4Version: T[String] = Task { "" }
override def testFramework: T[String] = "com.novocode.junit.JUnitFramework"
override def mandatoryMvnDeps: T[Seq[Dep]] = Task {
super.mandatoryMvnDeps() ++ Seq(mvn"${mill.scalalib.api.Versions.sbtTestInterface}")
super.mandatoryMvnDeps() ++
Seq(
mvn"${mill.scalalib.api.Versions.sbtTestInterface}"
) ++
Seq(junit4Version())
.filter(!_.isBlank())
.map(v => mvn"junit:junit:${v.trim()}")
}
}

Expand Down Expand Up @@ -380,50 +395,113 @@ object TestModule {

/**
* TestModule that uses Specs2 Framework to run tests.
* You need to provide the specs2 dependencies yourself.
* You can override the [[specs2Version]] task or provide the Specs2-dependency yourself.
*/
trait Specs2 extends ScalaModuleBase with TestModule {

/** The Specs2 version to use, or the empty string, if you want to provide the Specs2-dependency yourself. */
def specs2Version: T[String] = Task { "" }
override def testFramework: T[String] = "org.specs2.runner.Specs2Framework"
override def scalacOptions = Task {
super.scalacOptions() ++ Seq("-Yrangepos")
}
override def mandatoryMvnDeps: T[Seq[Dep]] = Task {
super.mandatoryMvnDeps() ++
Seq(specs2Version())
.filter(!_.isBlank())
.map(v => mvn"org.specs2::specs2-core::${v.trim()}")
}
}

/**
* TestModule that uses UTest Framework to run tests.
* You need to provide the utest dependencies yourself.
* You can override the [[utestVersion]] task or provide the UTest-dependency yourself.
*/
trait Utest extends TestModule {

/** The UTest version to use, or the empty string, if you want to provide the UTest-dependency yourself. */
def utestVersion: T[String] = Task { "" }
override def testFramework: T[String] = "utest.runner.Framework"
override def mandatoryMvnDeps: T[Seq[Dep]] = Task {
super.mandatoryMvnDeps() ++
Seq(utestVersion())
.filter(!_.isBlank())
.map(v => mvn"com.lihaoyi::utest::${v.trim()}")
}
}

/**
* TestModule that uses MUnit to run tests.
* You need to provide the munit dependencies yourself.
* You can override the [[munitVersion]] task or provide the MUnit-dependency yourself.
*/
trait Munit extends TestModule {

/** The MUnit version to use, or the empty string, if you want to provide the MUnit-dependency yourself. */
def munitVersion: T[String] = Task { "" }
override def testFramework: T[String] = "munit.Framework"
override def mandatoryMvnDeps: T[Seq[Dep]] = Task {
super.mandatoryMvnDeps() ++
Seq(munitVersion())
.filter(!_.isBlank())
.map(v => mvn"org.scalameta::munit::${v.trim()}")
}
}

/**
* TestModule that uses Weaver to run tests.
* You need to provide the weaver dependencies yourself.
* You can override the [[weaverVersion]] task or provide the Weaver-dependency yourself.
* https://github.com/disneystreaming/weaver-test
*/
trait Weaver extends TestModule {

/** The Weaver version to use, or the empty string, if you want to provide the Weaver-dependency yourself. */
def weaverVersion: T[String] = Task { "" }
override def testFramework: T[String] = "weaver.framework.CatsEffect"
override def mandatoryMvnDeps: T[Seq[Dep]] = Task {
super.mandatoryMvnDeps() ++
Seq(weaverVersion())
.filter(!_.isBlank())
.map(v => mvn"com.disneystreaming::weaver-scalacheck::${v.trim()}")
}
}

/**
* TestModule that uses ZIO Test Framework to run tests.
* You need to provide the zio-test dependencies yourself.
* You can override the [[zioTestVersion]] task or provide the Weaver-dependency yourself.
*/
trait ZioTest extends TestModule {

/** The ZIO Test version to use, or the empty string, if you want to provide the ZIO Test-dependency yourself. */
def zioTestVersion: T[String] = Task { "" }
override def testFramework: T[String] = "zio.test.sbt.ZTestFramework"
override def mandatoryMvnDeps: T[Seq[Dep]] = Task {
super.mandatoryMvnDeps() ++
Seq(zioTestVersion())
.filter(!_.isBlank())
.flatMap(v =>
Seq(
mvn"dev.zio::zio-test:${v.trim()}",
mvn"dev.zio::zio-test-sbt:${v.trim()}"
)
)
}
}

/**
* TestModule that uses ScalaCheck Test Framework to run tests.
* You can override the [[scalaCheckVersion]] task or provide the dependency yourself.
*/
trait ScalaCheck extends TestModule {

/** The ScalaCheck version to use, or the empty string, if you want to provide the dependency yourself. */
def scalaCheckVersion: T[String] = Task { "" }
override def testFramework: T[String] = "org.scalacheck.ScalaCheckFramework"
override def mandatoryMvnDeps: T[Seq[Dep]] = Task {
super.mandatoryMvnDeps() ++
Seq(scalaCheckVersion())
.filter(!_.isBlank())
.map(v => mvn"org.scalacheck::scalacheck:${v.trim()}")
}
}

def handleResults(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object ScalaVersionsRangesTests extends TestSuite {
trait CoreCrossModule extends CrossScalaModule
with CrossScalaVersionRanges {
object test extends ScalaTests with TestModule.Utest {
def mvnDeps = Seq(mvn"com.lihaoyi::utest:0.8.5")
override def utestVersion = "0.8.5"
}
}

Expand Down
6 changes: 1 addition & 5 deletions scalalib/test/src/mill/scalalib/TestClassLoaderTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ object TestClassLoaderTests extends TestSuite {
def scalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???)

object test extends ScalaTests with TestModule.Utest {
override def mvnDeps = Task {
super.mvnDeps() ++ Seq(
mvn"com.lihaoyi::utest:${sys.props.getOrElse("TEST_UTEST_VERSION", ???)}"
)
}
override def utestVersion = sys.props.getOrElse("TEST_UTEST_VERSION", ???)
}

lazy val millDiscover = Discover[this.type]
Expand Down
14 changes: 3 additions & 11 deletions scalalib/test/src/mill/scalalib/TestRunnerTestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import sbt.testing.Status
import utest.*

import scala.xml.{Elem, NodeSeq, XML}
import mill.define.Target

object TestRunnerTestUtils {
object testrunner extends TestRunnerTestModule {
Expand Down Expand Up @@ -40,13 +41,9 @@ object TestRunnerTestUtils {
def scalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???)

object utest extends ScalaTests with TestModule.Utest {
override def utestVersion = sys.props.getOrElse("TEST_UTEST_VERSION", ???)
override def testForkGrouping = computeTestForkGrouping(discoveredTestClasses())
override def testParallelism = enableParallelism
override def mvnDeps = Task {
super.mvnDeps() ++ Seq(
mvn"com.lihaoyi::utest:${sys.props.getOrElse("TEST_UTEST_VERSION", ???)}"
)
}
}

object scalatest extends ScalaTests with TestModule.ScalaTest {
Expand Down Expand Up @@ -81,12 +78,7 @@ object TestRunnerTestUtils {
object ziotest extends ScalaTests with TestModule.ZioTest {
override def testForkGrouping = computeTestForkGrouping(discoveredTestClasses())
override def testParallelism = enableParallelism
override def mvnDeps = Task {
super.mvnDeps() ++ Seq(
mvn"dev.zio::zio-test:${sys.props.getOrElse("TEST_ZIOTEST_VERSION", ???)}",
mvn"dev.zio::zio-test-sbt:${sys.props.getOrElse("TEST_ZIOTEST_VERSION", ???)}"
)
}
override def zioTestVersion: Target[String] = sys.props.getOrElse("TEST_ZIOTEST_VERSION", ???)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object CompileRunTests extends TestSuite {
val scala213 = sys.props.getOrElse("TEST_SCALA_2_13_VERSION_FOR_SCALANATIVE_4_2", ???)
val scala33 = sys.props.getOrElse("TEST_SCALA_3_3_VERSION", ???)
val scalaNative05 = sys.props.getOrElse("TEST_SCALANATIVE_0_5_VERSION", ???)
val utestVersion = sys.props.getOrElse("TEST_UTEST_VERSION", ???)
val testUtestVersion = sys.props.getOrElse("TEST_UTEST_VERSION", ???)

object HelloNativeWorld extends TestBaseModule {
implicit object ReleaseModeToSegments
Expand Down Expand Up @@ -58,9 +58,7 @@ object CompileRunTests extends TestSuite {

object test extends ScalaNativeTests with TestModule.Utest {
override def sources = Task.Sources { this.moduleDir / "src/utest" }
override def mvnDeps = super.mvnDeps() ++ Seq(
mvn"com.lihaoyi::utest::$utestVersion"
)
override def utestVersion: Target[String] = testUtestVersion
}
}

Expand Down