Skip to content

Commit

Permalink
Cleanup Kotlin tests (#4568)
Browse files Browse the repository at this point in the history
Consolidated HelloWorldTests and HelloWorkEmbeddableTests.

Pull request: #4568
  • Loading branch information
lefou authored Feb 15, 2025
1 parent ec4e0b7 commit 7deafef
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import io.kotest.matchers.shouldBe

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

test("testSuccess") {
test("testFailure") {
getHelloString() shouldBe "WRONG!"
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ import mill.api.ExecResult
import mill.define.Discover
import utest.*

object HelloWorldEmbeddableTests extends TestSuite {
object HelloKotlinTests extends TestSuite {

val kotlinVersions = Seq("1.9.24", "2.0.20", "2.1.0")
val crossMatrix = for {
kotlinVersion <- Seq("1.9.24", "2.0.20", "2.1.0")
embeddable <- Seq(false, true)
} yield (kotlinVersion, embeddable)

object HelloWorldKotlinEmbeddable extends TestBaseModule {
trait MainCross extends KotlinModule with Cross.Module[String] {
val junit5Version = sys.props.getOrElse("TEST_JUNIT5_VERSION", "5.9.1")

object HelloKotlin extends TestBaseModule {
// crossValue - test different Kotlin versions
// crossValue2 - test with/without the kotlin embeddable compiler
trait KotlinVersionCross extends KotlinModule with Cross.Module2[String, Boolean] {
def kotlinVersion = crossValue

override def kotlinCompilerEmbeddable: Task[Boolean] = Task { true }
override def kotlinCompilerEmbeddable: Task[Boolean] = Task { crossValue2 }

override def mainClass = Some("hello.HelloKt")

Expand All @@ -26,28 +33,35 @@ object HelloWorldEmbeddableTests extends TestSuite {
}
object kotest extends KotlinTests with TestModule.Junit5 {
override def ivyDeps = super.ivyDeps() ++ Seq(
ivy"io.kotest:kotest-runner-junit5-jvm:5.9.1"
ivy"io.kotest:kotest-runner-junit5-jvm:${junit5Version}"
)
}
}
object main extends Cross[MainCross](kotlinVersions)
object main extends Cross[KotlinVersionCross](crossMatrix)

lazy val millDiscover = Discover[this.type]
}

val resourcePath = os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "hello-world-kotlin"
val resourcePath = os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "hello-kotlin"

def testEval() = UnitTester(HelloKotlin, resourcePath)

def testEval() = UnitTester(HelloWorldKotlinEmbeddable, resourcePath)
def tests: Tests = Tests {

def compilerDep(embeddable: Boolean) =
if (embeddable) "org.jetbrains.kotlin" -> "kotlin-compiler-embeddable"
else "org.jetbrains.kotlin" -> "kotlin-compiler"

test("compile") {
val eval = testEval()

HelloWorldKotlinEmbeddable.main.crossModules.foreach(m => {
HelloKotlin.main.crossModules.foreach(m => {
val Right(compiler) = eval.apply(m.kotlinCompilerIvyDeps): @unchecked

assert(
compiler.value.map(_.dep.module).map(m => m.organization.value -> m.name.value)
.contains("org.jetbrains.kotlin" -> "kotlin-compiler-embeddable")
compiler.value.map(_.dep.module)
.map(m => m.organization.value -> m.name.value)
.contains(compilerDep(m.crossValue2))
)

val Right(result) = eval.apply(m.compile): @unchecked
Expand All @@ -57,15 +71,17 @@ object HelloWorldEmbeddableTests extends TestSuite {
)
})
}

test("testCompile") {
val eval = testEval()

HelloWorldKotlinEmbeddable.main.crossModules.foreach(m => {
HelloKotlin.main.crossModules.foreach(m => {
val Right(compiler) = eval.apply(m.test.kotlinCompilerIvyDeps): @unchecked

assert(
compiler.value.map(_.dep.module).map(m => m.organization.value -> m.name.value)
.contains("org.jetbrains.kotlin" -> "kotlin-compiler-embeddable")
compiler.value.map(_.dep.module)
.map(m => m.organization.value -> m.name.value)
.contains(compilerDep(m.crossValue2))
)

val Right(result1) = eval.apply(m.test.compile): @unchecked
Expand All @@ -75,29 +91,31 @@ object HelloWorldEmbeddableTests extends TestSuite {
)
})
}

test("test") {
val eval = testEval()

HelloWorldKotlinEmbeddable.main.crossModules.foreach(m => {
HelloKotlin.main.crossModules.foreach(m => {
val Left(ExecResult.Failure(_)) = eval.apply(m.test.test()): @unchecked
})
}
test("kotest") {
val eval = testEval()

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

val Left(ExecResult.Failure(_)) = eval.apply(m.kotest.test()): @unchecked
})
}

test("failures") {
val eval = testEval()

val mainJava = HelloWorldKotlinEmbeddable.moduleDir / "main/src/Hello.kt"
val mainJava = HelloKotlin.moduleDir / "main/src/Hello.kt"

HelloWorldKotlinEmbeddable.main.crossModules.foreach(m => {
HelloKotlin.main.crossModules.foreach(m => {

val Right(_) = eval.apply(m.compile): @unchecked

Expand Down
111 changes: 0 additions & 111 deletions kotlinlib/test/src/mill/kotlinlib/HelloWorldTests.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import utest.{TestSuite, Tests, test}

object KotlinJsKotlinVersionsTests extends TestSuite {

private val resourcePath = os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "kotlin-js"
private val kotlinLowestVersion = "1.8.20"
private val resourcePath = os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "kotlin-js"
private val kotlinHighestVersion = mill.kotlinlib.Versions.kotlinVersion
private val kotlinVersions = Seq(kotlinLowestVersion, kotlinHighestVersion)

Expand Down

0 comments on commit 7deafef

Please sign in to comment.