Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for Cobertura XML report task to help integration #3093

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Expand Up @@ -38,6 +38,9 @@ object ScoverageReportWorkerApi {
object ReportType {
final case object Html extends FileReportType { val folderName: String = "htmlReport" }
final case object Xml extends FileReportType { val folderName: String = "xmlReport" }
final case object XmlCobertura extends FileReportType {
val folderName: String = "xmlCoberturaReport"
}
final case object Console extends ReportType
}
}
20 changes: 11 additions & 9 deletions contrib/scoverage/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ modules introduce a few new tasks and changes the behavior of an existing one.

[source,bash]
----
mill foo.scoverage.compile # compiles your module with test instrumentation
# (you don't have to run this manually, running the test task will force its invocation)
mill foo.scoverage.compile # compiles your module with test instrumentation
# (you don't have to run this manually, running the test task will force its invocation)

mill foo.test # tests your project and collects metrics on code coverage
mill foo.scoverage.htmlReport # uses the metrics collected by a previous test run to generate a coverage report in html format
mill foo.scoverage.xmlReport # uses the metrics collected by a previous test run to generate a coverage report in xml format
mill foo.test # tests your project and collects metrics on code coverage
mill foo.scoverage.htmlReport # uses the metrics collected by a previous test run to generate a coverage report in html format
mill foo.scoverage.xmlReport # uses the metrics collected by a previous test run to generate a coverage report in xml format
mill foo.scoverage..xmlCoberturaReportAll # uses the metrics collected by a previous test run to generate a coverage report in Cobertura's xml format
lefou marked this conversation as resolved.
Show resolved Hide resolved
----

The measurement data is by default available at `out/foo/scoverage/data/dest`,
Expand All @@ -64,10 +65,11 @@ This provides you with various reporting functions:

[source,bash]
----
mill __.test # run tests for all modules
mill scoverage.htmlReportAll # generates report in html format for all modules
mill scoverage.xmlReportAll # generates report in xml format for all modules
mill scoverage.consoleReportAll # reports to the console for all modules
mill __.test # run tests for all modules
mill scoverage.htmlReportAll # generates report in html format for all modules
mill scoverage.xmlReportAll # generates report in xml format for all modules
mill scoverage.xmlCoberturaReportAll # generates report in Cobertura's xml format for all modules
mill scoverage.consoleReportAll # reports to the console for all modules
----

The aggregated report will be available at either `out/scoverage/htmlReportAll.dest/`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule =>

def htmlReport(): Command[Unit] = T.command { doReport(ReportType.Html) }
def xmlReport(): Command[Unit] = T.command { doReport(ReportType.Xml) }
def xmlCoberturaReport(): Command[Unit] = T.command { doReport(ReportType.XmlCobertura) }
def consoleReport(): Command[Unit] = T.command { doReport(ReportType.Console) }

override def skipIdea: Boolean = true // being a synthetic module, no need to appear in the IDE
Expand Down
10 changes: 10 additions & 0 deletions contrib/scoverage/src/mill/contrib/scoverage/ScoverageReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import os.Path
* - mill __.test # run tests for all modules
* - mill scoverage.htmlReportAll # generates report in html format for all modules
* - mill scoverage.xmlReportAll # generates report in xml format for all modules
* - mill scoverage.xmlCoberturaReportAll # generates report in Cobertura's xml format for all modules
* - mill scoverage.consoleReportAll # reports to the console for all modules
*
* The aggregated report will be available at either `out/scoverage/htmlReportAll.dest/`
Expand Down Expand Up @@ -65,6 +66,15 @@ trait ScoverageReport extends Module {
reportTask(evaluator, ReportType.Xml, sources, dataTargets)()
}

/** Generates report in Cobertura's xml format for all modules */
def xmlCoberturaReportAll(
evaluator: Evaluator,
sources: String = "__.allSources",
dataTargets: String = "__.scoverage.data"
): Command[PathRef] = T.command {
reportTask(evaluator, ReportType.XmlCobertura, sources, dataTargets)()
}

/** Reports to the console for all modules */
def consoleReportAll(
evaluator: Evaluator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,22 @@ trait HelloWorldTests extends utest.TestSuite {
""
}
}
"xmlCoberturaReport" - workspaceTest(HelloWorld) { eval =>
val Right((_, _)) = eval.apply(HelloWorld.core.test.compile)
val res = eval.apply(HelloWorld.core.scoverage.xmlCoberturaReport())
if (
res.isLeft && testScalaVersion.startsWith("3.2") && testScoverageVersion.startsWith(
"2."
)
) {
s"""Disabled for Scoverage ${testScoverageVersion} on Scala ${testScalaVersion}, as it fails with "No source root found" message"""
} else {
assert(res.isRight)
val Right((_, evalCount)) = res
assert(evalCount > 0)
""
}
}
"console" - workspaceTest(HelloWorld) { eval =>
val Right((_, _)) = eval.apply(HelloWorld.core.test.compile)
val Right((_, evalCount)) = eval.apply(HelloWorld.core.scoverage.consoleReport())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package mill.contrib.scoverage.worker

import mill.contrib.scoverage.api.ScoverageReportWorkerApi
import _root_.scoverage.report.{CoverageAggregator, ScoverageHtmlWriter, ScoverageXmlWriter}
import _root_.scoverage.report.{
CoberturaXmlWriter,
CoverageAggregator,
ScoverageHtmlWriter,
ScoverageXmlWriter
}
import mill.api.Ctx
import mill.contrib.scoverage.api.ScoverageReportWorkerApi.ReportType

Expand Down Expand Up @@ -31,6 +36,9 @@ class ScoverageReportWorkerImpl extends ScoverageReportWorkerApi {
case ReportType.Xml =>
new ScoverageXmlWriter(sourceFolders, folder.toIO, false)
.write(coverage)
case ReportType.XmlCobertura =>
new CoberturaXmlWriter(sourceFolders, folder.toIO)
.write(coverage)
case ReportType.Console =>
ctx.log.info(s"Statement coverage.: ${coverage.statementCoverageFormatted}%")
ctx.log.info(s"Branch coverage....: ${coverage.branchCoverageFormatted}%")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package mill.contrib.scoverage.worker

import mill.contrib.scoverage.api.ScoverageReportWorkerApi
import _root_.scoverage.reporter.{CoverageAggregator, ScoverageHtmlWriter, ScoverageXmlWriter}
import _root_.scoverage.reporter.{
CoberturaXmlWriter,
CoverageAggregator,
ScoverageHtmlWriter,
ScoverageXmlWriter
}
import mill.api.Ctx
import mill.contrib.scoverage.api.ScoverageReportWorkerApi.ReportType

Expand Down Expand Up @@ -30,6 +35,9 @@ class ScoverageReportWorkerImpl extends ScoverageReportWorkerApi {
case ReportType.Xml =>
new ScoverageXmlWriter(sourceFolders, folder.toIO, false, None)
.write(coverage)
case ReportType.XmlCobertura =>
new CoberturaXmlWriter(sourceFolders, folder.toIO, None)
.write(coverage)
case ReportType.Console =>
ctx.log.info(s"Statement coverage.: ${coverage.statementCoverageFormatted}%")
ctx.log.info(s"Branch coverage....: ${coverage.branchCoverageFormatted}%")
Expand Down