Merge pull request #5350 from mrArkwright/fix-4451

introduce SysProp sbt.testing.legacyreport
This commit is contained in:
eugene yokota 2020-01-09 13:30:24 -05:00 committed by GitHub
commit 9b931c4bf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 11 deletions

View File

@ -70,6 +70,7 @@ object SysProp {
def client: Boolean = getOrFalse("sbt.client")
def ci: Boolean = getOrFalse("sbt.ci")
def allowRootDir: Boolean = getOrFalse("sbt.rootdir")
def legacyTestReport: Boolean = getOrFalse("sbt.testing.legacyreport")
def watchMode: String =
sys.props.get("sbt.watch.mode").getOrElse("auto")

View File

@ -10,6 +10,7 @@ package plugins
import Def.Setting
import Keys._
import sbt.internal.SysProp
/**
* An experimental plugin that adds the ability for junit-xml to be generated.
@ -30,6 +31,10 @@ object JUnitXmlReportPlugin extends AutoPlugin {
// It might be a good idea to derive this setting into specific test scopes.
override lazy val projectSettings: Seq[Setting[_]] =
Seq(
testListeners += new JUnitXmlTestsListener(target.value.getAbsolutePath, streams.value.log)
testListeners += new JUnitXmlTestsListener(
target.value.getAbsolutePath,
SysProp.legacyTestReport,
streams.value.log
)
)
}

View File

@ -5,11 +5,11 @@ import Defaults._
val checkReport = taskKey[Unit]("Check the test reports")
val checkNoReport = taskKey[Unit]("Check that no reports are present")
val oneSecondReportFile = "target/test-reports/a.pkg.OneSecondTest.xml"
val failingReportFile = "target/test-reports/another.pkg.FailingTest.xml"
val oneSecondReportFile = "target/test-reports/TEST-a.pkg.OneSecondTest.xml"
val failingReportFile = "target/test-reports/TEST-another.pkg.FailingTest.xml"
val flatSuiteReportFile = "target/test-reports/my.scalatest.MyFlatSuite.xml"
val nestedSuitesReportFile = "target/test-reports/my.scalatest.MyNestedSuites.xml"
val flatSuiteReportFile = "target/test-reports/TEST-my.scalatest.MyFlatSuite.xml"
val nestedSuitesReportFile = "target/test-reports/TEST-my.scalatest.MyNestedSuites.xml"
val scalatest = "org.scalatest" %% "scalatest" % "3.0.5"
val junitinterface = "com.novocode" % "junit-interface" % "0.11"

View File

@ -33,9 +33,11 @@ import sbt.protocol.testing.TestResult
* report format.
* @param outputDir path to the dir in which a folder with results is generated
*/
class JUnitXmlTestsListener(val outputDir: String, logger: Logger) extends TestsListener {
// This constructor is for binary compatibility with older versions of sbt.
def this(outputDir: String) = this(outputDir, null)
class JUnitXmlTestsListener(val outputDir: String, legacyTestReport: Boolean, logger: Logger)
extends TestsListener {
// These constructors are for binary compatibility with older versions of sbt.
def this(outputDir: String, logger: Logger) = this(outputDir, false, logger)
def this(outputDir: String) = this(outputDir, false, null)
/**Current hostname so we know which machine executed the tests*/
val hostname: String = {
@ -248,14 +250,14 @@ class JUnitXmlTestsListener(val outputDir: String, logger: Logger) extends Tests
d.truncatedTo(ChronoUnit.SECONDS).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
private def writeSuite(): Unit = {
val legacyFile =
val file = if (legacyTestReport) {
new File(targetDir, s"${normalizeName(withTestSuite(_.name))}.xml").getAbsolutePath
val file =
} else {
new File(targetDir, s"TEST-${normalizeName(withTestSuite(_.name))}.xml").getAbsolutePath
}
// TODO would be nice to have a logger and log this with level debug
// System.err.println("Writing JUnit XML test report: " + file)
val testSuiteResult = withTestSuite(_.stop())
XML.save(legacyFile, testSuiteResult, "UTF-8", xmlDecl = true, null)
XML.save(file, testSuiteResult, "UTF-8", xmlDecl = true, null)
testSuite.remove()
}