From 8ac1fed0f3694e673a4f90f7b4d88051871476f7 Mon Sep 17 00:00:00 2001 From: Pavel Punegov <32519625+PavelPunegov@users.noreply.github.com> Date: Thu, 23 Nov 2017 18:43:08 +0300 Subject: [PATCH] Build results file even if some tasks failed with exception --- backend.native/tests/build.gradle | 50 +++++++++++++++++-------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 434ac74358c..359dbfc9461 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -138,19 +138,43 @@ task run() { dependsOn(tasks.withType(KonanTest).matching { !(it instanceof RunExternalTestGroup) && it.enabled }) } +// Collect results in one json. +task resultsTask() { + doLast { + Map> results = [:] + def statistics = new RunExternalTestGroup.Statistics() + tasks.withType(RunExternalTestGroup).matching { it.state.executed }.each { + results.put(it.name, it.results) + statistics.add(it.statistics) + } + + def output = ["statistics": statistics, "tests": results] + def json = JsonOutput.toJson(output) + def reportFile = new File(sourceSets.testOutputExternal.output.getDirs().getSingleFile(), "results.json") + reportFile.write(JsonOutput.prettyPrint(json)) + println("DONE.\n\n" + + "TOTAL: $statistics.total\n" + + "PASSED: $statistics.passed\n" + + "FAILED: $statistics.failed\n" + + "ERROR: $statistics.error\n" + + "SKIPPED: $statistics.skipped") + } +} + Set createExternalTests(File testRoot, Closure taskConfiguration) { def result = new HashSet() testRoot.eachDirRecurse { // Skip build directory and directories without *.kt files. - if (it.name == "build" || it.listFiles().count {it.name.endsWith(".kt") && it.isFile()} == 0) { + if (it.name == "build" || it.listFiles().count { it.name.endsWith(".kt") && it.isFile() } == 0) { return } def taskDirectory = project.relativePath(it) def taskName = taskDirectory.replaceAll("[-/\\\\]", '_') - def task = (RunExternalTestGroup)project.task("$taskName", type: RunExternalTestGroup){ + def task = (RunExternalTestGroup) project.task("$taskName", type: RunExternalTestGroup) { groupDirectory = "$taskDirectory" + finalizedBy resultsTask } taskConfiguration(task) result.add(task) @@ -177,27 +201,7 @@ task run_external () { testTasks = testTasks.matching { it.name.startsWith(prefix) } } dependsOn(testTasks) - - // Collect results in one json. - doLast { - Map> results = [:] - def statistics = new RunExternalTestGroup.Statistics() - testTasks.matching { it.state.executed }.each { - results.put(it.name, it.results) - statistics.add(it.statistics) - } - - def output = ["statistics" : statistics, "tests" : results] - def json = JsonOutput.toJson(output) - def reportFile = new File(sourceSets.testOutputExternal.output.getDirs().getSingleFile(), "results.json") - reportFile.write(JsonOutput.prettyPrint(json)) - println("DONE.\n\n" + - "TOTAL: $statistics.total\n" + - "PASSED: $statistics.passed\n" + - "FAILED: $statistics.failed\n" + - "ERROR: $statistics.error\n" + - "SKIPPED: $statistics.skipped") - } +// finalizedBy resultsTask } task daily() {