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

Add Kover support #3624

Merged
merged 4 commits into from
Sep 30, 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
1 change: 1 addition & 0 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ object Deps {
val logback = ivy"ch.qos.logback:logback-classic:1.5.7"
val sonatypeCentralClient = ivy"com.lumidion::sonatype-central-client-requests:0.3.0"
val kotlinCompiler = ivy"org.jetbrains.kotlin:kotlin-compiler:1.9.24"
val koverVersion = "0.8.3"

object RuntimeDeps {
val errorProneCore = ivy"com.google.errorprone:error_prone_core:2.31.0"
Expand Down
17 changes: 17 additions & 0 deletions example/kotlinlib/linting/4-kover/bar/src/BarKotlin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package bar

fun action(one: Boolean, two: Boolean): String {
return if (one) {
if (two) {
"one, two"
} else {
"one"
}
} else {
if (two) {
"two"
} else {
"nothing"
}
}
}
10 changes: 10 additions & 0 deletions example/kotlinlib/linting/4-kover/bar/test/src/BarTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package bar

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

class BarTests : FunSpec({
test("kotlin - success") {
action(true, true) shouldBe "one, two"
}
})
74 changes: 74 additions & 0 deletions example/kotlinlib/linting/4-kover/build.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package build

import mill._, kotlinlib._
import kotlinlib.contrib.kover.KoverModule

object `package` extends RootModule with KotlinModule with KoverModule {

trait KotestTests extends TestModule.Junit5 {
override def forkArgs: T[Seq[String]] = Task {
super.forkArgs() ++ Seq("-Dkotest.framework.classpath.scanning.autoscan.disable=true")

}
override def ivyDeps = super.ivyDeps() ++ Agg(
ivy"io.kotest:kotest-runner-junit5-jvm:5.9.1"
)
}

def kotlinVersion = "1.9.24"

override def koverVersion = "0.8.3"

object test extends KotlinModuleTests with KotestTests with KoverTests

object bar extends KotlinModule with KoverModule {
def kotlinVersion = "1.9.24"
object test extends KotlinModuleTests with KotestTests with KoverTests
}
}

// This is a basic Mill build for a single `KotlinModule`, enhanced with
// Kover module. The root module extends the `KoverModule` and
// specifies the version of Kover version to use here: `0.8.3`. This
// version can be changed if there is a newer one. Now you can call the
// Kover targets to produce coverage reports.
// The sub test module extends `KoverTests` to transform the
// execution of the various testXXX targets to use Kover and produce
// coverage data.
// This lets us perform the coverage operations but before that you
// must first run the test.
// `./mill test` then `./mill show kover.htmlReport` and get your
// coverage in HTML format.
// Also reports for all modules can be collected in a single place by
// running `./mill show mill.kotlinlib.contrib.kover.Kover/htmlReportAll`.

/** Usage

> ./mill test # Run the tests and produce the coverage data
...
... foo.FooTestskotlin - success started

> ./mill resolve kover._ # List what tasks are available to run from kover
...
kover.htmlReport
...
kover.xmlReport
...

> ./mill show kover.htmlReport
...
...out/kover/htmlReport.dest/kover-report...

> cat out/kover/htmlReport.dest/kover-report/index.html
...
...Kover HTML Report: Overall Coverage Summary...

> ./mill show mill.kotlinlib.contrib.kover.Kover/htmlReportAll # collect reports from all modules
...
...out/mill/kotlinlib/contrib/kover/Kover/htmlReportAll.dest/kover-report...

> cat out/mill/kotlinlib/contrib/kover/Kover/htmlReportAll.dest/kover-report/index.html
...
...Kover HTML Report: Overall Coverage Summary...

*/
17 changes: 17 additions & 0 deletions example/kotlinlib/linting/4-kover/src/foo/FooKotlin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package foo

fun action(one: Boolean, two: Boolean): String {
return if (one) {
if (two) {
"one, two"
} else {
"one"
}
} else {
if (two) {
"two"
} else {
"nothing"
}
}
}
10 changes: 10 additions & 0 deletions example/kotlinlib/linting/4-kover/test/src/foo/FooTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package foo

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

class FooTests : FunSpec({
test("kotlin - success") {
action(true, true) shouldBe "one, two"
}
})
5 changes: 0 additions & 5 deletions example/scalalib/linting/2-contrib-scoverage/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ object `package` extends RootModule with ScoverageModule {
// must first run the test.
// `./mill test` then `./mill scoverage.consoleReport` and get your
// coverage into your console output.
//
// You can download this example project using the *download* link above
// if you want to try out the commands below yourself. The only requirement is
// that you have some version of the JVM installed; the `./mill` script takes
// care of any further dependencies that need to be downloaded.

/** Usage

Expand Down
9 changes: 8 additions & 1 deletion kotlinlib/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ package build.kotlinlib

// imports
import mill._
import mill.contrib.buildinfo.BuildInfo
import mill.scalalib._

// TODO change MillPublishScalaModule to MillStableScalaModule after mill version with kotlinlib is released,
// because currently there is no previous artifact version
object `package` extends RootModule with build.MillPublishScalaModule {
object `package` extends RootModule with build.MillPublishScalaModule with BuildInfo {

def moduleDeps = Seq(build.main, build.scalalib, build.testrunner, worker)
def testTransitiveDeps = super.testTransitiveDeps() ++ Seq(worker.impl.testDep())

def buildInfoPackageName = "mill.kotlinlib"
def buildInfoObjectName = "Versions"
def buildInfoMembers = Seq(
BuildInfo.Value("koverVersion", build.Deps.koverVersion, "Version of Kover.")
)

trait MillKotlinModule extends build.MillPublishScalaModule {
override def javacOptions = {
val release =
Expand Down
Loading
Loading