[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:
+18
-8
@@ -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(
|
private fun createTestTask(
|
||||||
project: Project,
|
project: Project,
|
||||||
testName: String,
|
testName: String,
|
||||||
@@ -285,14 +300,9 @@ private fun createTestTask(
|
|||||||
workingDir.mkdirs()
|
workingDir.mkdirs()
|
||||||
}
|
}
|
||||||
|
|
||||||
doLast {
|
val reportWithPrefixes = workingDir.resolve("report-with-prefixes.xml")
|
||||||
// TODO: Better to use proper XML parsing.
|
val reportTask = project.tasks.register("${testName}Report", ReportWithPrefixes::class.java, testName, xmlReport, reportWithPrefixes)
|
||||||
var contents = xmlReport.readText()
|
finalizedBy(reportTask)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user