Skip to content

Commit

Permalink
Filter out anonymous classes during test discovery (#3911)
Browse files Browse the repository at this point in the history
Mitigates #3910 by hackily
filtering out all anonymous classes, but non-anonymous non-test classes
still cause the problem

Added a unit test to check this specific misbehavior
  • Loading branch information
lihaoyi authored Nov 5, 2024
1 parent 3a3ac49 commit 68269b8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package hello.tests

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import hello.getHelloString

class FooTest : FunSpec({
test("testFailure") {
getHelloString() shouldBe "Hello, world!"
}

test("testSuccess") {
getHelloString() shouldBe "WRONG!"
}
})
22 changes: 22 additions & 0 deletions kotlinlib/test/src/mill/kotlinlib/HelloWorldTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ object HelloWorldTests extends TestSuite {
ivy"org.jetbrains.kotlin:kotlin-test-junit:${this.kotlinVersion()}"
)
}
object kotest extends KotlinTests with TestModule.Junit5 {
override def ivyDeps = super.ivyDeps() ++ Agg(
ivy"io.kotest:kotest-runner-junit5-jvm:5.9.1"
)
}
}
object main extends Cross[MainCross](kotlinVersions)
}
Expand Down Expand Up @@ -68,6 +73,23 @@ object HelloWorldTests extends TestSuite {
)
})
}
test("kotest") {
val eval = testEval()

HelloWorldKotlin.main.crossModules.foreach(m => {
val Right(discovered) = eval.apply(m.kotest.discoveredTestClasses)
assert(discovered.value == Seq("hello.tests.FooTest"))

val Left(Result.Failure(_, Some(v1))) = eval.apply(m.kotest.test())

assert(
v1._2(0).fullyQualifiedName == "hello.tests.FooTest",
v1._2(0).status == "Success",
v1._2(1).fullyQualifiedName == "hello.tests.FooTest",
v1._2(1).status == "Failure"
)
})
}
test("failures") {
val eval = testEval()

Expand Down
12 changes: 6 additions & 6 deletions testrunner/src/mill/testrunner/TestRunnerUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ import scala.jdk.CollectionConverters.IteratorHasAsScala
.flatten
)
}
// I think this is a bug in sbt-junit-interface. AFAICT, JUnit is not
// meant to pick up non-static inner classes as test suites, and doing
// so makes the jimfs test suite fail
//
// https://stackoverflow.com/a/17468590
.filter { case (c, f) => !c.isMemberClass && !c.isAnonymousClass }

testClasses
}
Expand Down Expand Up @@ -109,12 +115,6 @@ import scala.jdk.CollectionConverters.IteratorHasAsScala

val runner = framework.runner(args.toArray, Array[String](), cl)
val testClasses = discoverTests(cl, framework, testClassfilePath)
// I think this is a bug in sbt-junit-interface. AFAICT, JUnit is not
// meant to pick up non-static inner classes as test suites, and doing
// so makes the jimfs test suite fail
//
// https://stackoverflow.com/a/17468590
.filter { case (c, f) => !c.isMemberClass }

val tasks = runner.tasks(
for ((cls, fingerprint) <- testClasses.iterator.toArray if classFilter(cls))
Expand Down

0 comments on commit 68269b8

Please sign in to comment.