Skip to content
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

Fix ScalaTest testOnly include option #3557

Merged
merged 2 commits into from
Sep 16, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package mill.scalalib

import org.scalatest.Tag
import org.scalatest.freespec.AnyFreeSpec

object TaggedTest extends Tag("tagged")

class ScalaTestSpec extends AnyFreeSpec {

"A Set" - {
Expand All @@ -15,6 +18,10 @@ class ScalaTestSpec extends AnyFreeSpec {
Set.empty.head
}
}

"should be tagged" taggedAs(TaggedTest) in {
assert(true)
}
}
}
}
36 changes: 33 additions & 3 deletions scalalib/test/src/mill/scalalib/TestRunnerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import mill.{Agg, T}
import os.Path
import sbt.testing.Status
import utest._
import utest.framework.TestPath

import java.io.{ByteArrayOutputStream, PrintStream}
import scala.xml.{Elem, NodeSeq, XML}
Expand Down Expand Up @@ -147,15 +146,46 @@ object TestRunnerTests extends TestSuite {
test("ScalaTest") {
test("test") - UnitTester(testrunner, resourcePath).scoped { eval =>
val Right(result) = eval(testrunner.scalatest.test())
assert(result.value._2.size == 2)
junitReportIn(eval.outPath, "scalatest").shouldHave(2 -> Status.Success)
assert(result.value._2.size == 3)
junitReportIn(eval.outPath, "scalatest").shouldHave(3 -> Status.Success)
}
test("discoveredTestClasses") - UnitTester(testrunner, resourcePath).scoped { eval =>
val Right(result) = eval.apply(testrunner.scalatest.discoveredTestClasses)
val expected = Seq("mill.scalalib.ScalaTestSpec")
assert(result.value == expected)
expected
}

test("testOnly") - {
def testOnly(eval: UnitTester, args: Seq[String], size: Int) = {
val Right(result) = eval.apply(testrunner.scalatest.testOnly(args: _*))
val testOnly = result.value.asInstanceOf[(String, Seq[mill.testrunner.TestResult])]
assert(
testOnly._2.size == size
)
}
test("all") - UnitTester(testrunner, resourcePath).scoped { eval =>
testOnly(eval, Seq("mill.scalalib.ScalaTestSpec"), 3)
}
test("include") - UnitTester(testrunner, resourcePath).scoped { eval =>
testOnly(eval, Seq("mill.scalalib.ScalaTestSpec", "--", "-n", "tagged"), 1)
}
test("exclude") - UnitTester(testrunner, resourcePath).scoped { eval =>
testOnly(eval, Seq("mill.scalalib.ScalaTestSpec", "--", "-l", "tagged"), 2)
}
test("includeAndExclude") - UnitTester(testrunner, resourcePath).scoped { eval =>
val Left(Result.Failure(msg, _)) =
eval.apply(testrunner.scalatest.testOnly(
"mill.scalalib.ScalaTestSpec",
"--",
"-n",
"tagged",
"-l",
"tagged"
))
assert(msg.contains("Test selector does not match any test"))
}
}
}

test("ZioTest") {
Expand Down
2 changes: 1 addition & 1 deletion testrunner/src/mill/testrunner/TestRunnerUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ import scala.jdk.CollectionConverters.IteratorHasAsScala
yield new TaskDef(
cls.getName.stripSuffix("$"),
fingerprint,
true,
false,
Array(new SuiteSelector)
)
)
Expand Down
Loading