[K/N] Use finalization task to generate report for runtime tests

The approach with doLast doesn't work if the test binary failed.
This patch uses a finalization task instead to ensure that we
process the XML report regardless of whether the tests pass
or fail.
This commit is contained in:
Ilya Matveev
2021-06-07 21:29:29 +07:00
committed by Space
parent f08d473d3c
commit 1530a0823f
@@ -179,6 +179,21 @@ open class LinkNativeTest @Inject constructor(
}
}
open class ReportWithPrefixes @Inject constructor(
@Input val testName: String,
@InputFile val inputReport: File,
@OutputFile val outputReport: File
) : DefaultTask() {
@TaskAction
fun process() {
// TODO: Better to use proper XML parsing.
var contents = inputReport.readText()
contents = contents.replace("<testsuite name=\"", "<testsuite name=\"${testName}.")
contents = contents.replace("classname=\"", "classname=\"${testName}.")
outputReport.writeText(contents)
}
}
private fun createTestTask(
project: Project,
testName: String,
@@ -285,14 +300,9 @@ private fun createTestTask(
workingDir.mkdirs()
}
doLast {
// TODO: Better to use proper XML parsing.
var contents = xmlReport.readText()
contents = contents.replace("<testsuite name=\"", "<testsuite name=\"${testName}.")
contents = contents.replace("classname=\"", "classname=\"${testName}.")
val rewrittenReport = workingDir.resolve("report-with-prefixes.xml")
rewrittenReport.writeText(contents)
}
val reportWithPrefixes = workingDir.resolve("report-with-prefixes.xml")
val reportTask = project.tasks.register("${testName}Report", ReportWithPrefixes::class.java, testName, xmlReport, reportWithPrefixes)
finalizedBy(reportTask)
}
}