backend.native/tests: Add JSON output to run-external task
This commit is contained in:
+1
-1
@@ -21,7 +21,7 @@ kotstd/kotstd.iml
|
|||||||
*.kt.S
|
*.kt.S
|
||||||
*.kt.exe
|
*.kt.exe
|
||||||
*.log
|
*.log
|
||||||
testOutput
|
test.output
|
||||||
|
|
||||||
# Ignore Gradle GUI config
|
# Ignore Gradle GUI config
|
||||||
gradle-app.setting
|
gradle-app.setting
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import groovy.json.JsonOutput
|
||||||
import org.jetbrains.kotlin.*
|
import org.jetbrains.kotlin.*
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
@@ -8,7 +9,7 @@ dependencies {
|
|||||||
cli_bc project(path: ':backend.native', configuration: 'cli_bc')
|
cli_bc project(path: ':backend.native', configuration: 'cli_bc')
|
||||||
}
|
}
|
||||||
|
|
||||||
def testOutputRoot = rootProject.file("testOutput").absolutePath
|
def testOutputRoot = rootProject.file("test.output").absolutePath
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
// Root directories for test output (logs, compiled files, statistics etc). Only single path must be in each set.
|
// Root directories for test output (logs, compiled files, statistics etc). Only single path must be in each set.
|
||||||
@@ -31,7 +32,6 @@ task clean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
task regenerate_external_tests() {
|
task regenerate_external_tests() {
|
||||||
doLast {
|
doLast {
|
||||||
def externalTestsProject = childProjects["external"]
|
def externalTestsProject = childProjects["external"]
|
||||||
@@ -86,24 +86,28 @@ task run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
task run_external () {
|
task run_external () {
|
||||||
project.subprojects {
|
// TODO Consider test output directory cleaning before execution.
|
||||||
dependsOn(it.tasks.withType(RunExternalTestGroup).matching { it.enabled })
|
// TODO Consider using some logger instead of println
|
||||||
}
|
def testTasks = childProjects["external"].tasks.withType(RunExternalTestGroup).matching { it.enabled }
|
||||||
|
dependsOn(testTasks)
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
def logFile = childProjects["external"].file(logFileName)
|
Map<String, Map<String, RunExternalTestGroup.TestResult>> results = [:]
|
||||||
def logText = logFile.text
|
def statistics = new RunExternalTestGroup.Statistics()
|
||||||
|
testTasks.matching { it.state.executed }.each {
|
||||||
|
results.put(it.name, it.results)
|
||||||
|
statistics.add(it.statistics)
|
||||||
|
}
|
||||||
|
|
||||||
def passed = logText.count("|PASSED|")
|
def output = ["statistics" : statistics, "tests" : results]
|
||||||
def failed = logText.count("|FAILED|")
|
def json = JsonOutput.toJson(output)
|
||||||
def skipped = logText.count("|SKIPPED|")
|
def reportFile = new File(sourceSets.testOutputExternal.output.getDirs().getSingleFile(), "results.json")
|
||||||
|
reportFile.write(JsonOutput.prettyPrint(json))
|
||||||
def report = "\nDONE.\n\n" +
|
println("DONE.\n\n" +
|
||||||
"PASSED: $passed\n" +
|
"TOTAL: $statistics.total\n" +
|
||||||
"FAILED: $failed\n" +
|
"PASSED: $statistics.passed\n" +
|
||||||
"TOTAL (FAILED + PASSED): ${passed + failed}\n" +
|
"FAILED: $statistics.failed\n" +
|
||||||
"SKIPPED : $skipped"
|
"SKIPPED: $statistics.skipped")
|
||||||
logFile.append(report)
|
|
||||||
println(report)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package org.jetbrains.kotlin
|
package org.jetbrains.kotlin
|
||||||
|
|
||||||
import groovy.json.JsonBuilder
|
import groovy.json.JsonOutput
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.tasks.ParallelizableTask
|
import org.gradle.api.tasks.ParallelizableTask
|
||||||
import org.gradle.api.tasks.TaskAction
|
import org.gradle.api.tasks.TaskAction
|
||||||
@@ -141,19 +141,48 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
def outputSourceSetName = "testOutputExternal"
|
def outputSourceSetName = "testOutputExternal"
|
||||||
String filter = project.findProperty("filter")
|
String filter = project.findProperty("filter")
|
||||||
String goldValue = "OK"
|
String goldValue = "OK"
|
||||||
|
Map<String, TestResult> results = [:]
|
||||||
|
Statistics statistics = new Statistics()
|
||||||
|
|
||||||
class TestResult {
|
static class TestResult {
|
||||||
String name = null
|
|
||||||
String status = null
|
String status = null
|
||||||
String comment = null
|
String comment = null
|
||||||
|
|
||||||
TestResult(String name, String status, String comment){
|
TestResult(String status, String comment = ""){
|
||||||
this.name = name;
|
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class Statistics {
|
||||||
|
int total = 0
|
||||||
|
int passed = 0
|
||||||
|
int failed = 0
|
||||||
|
int skipped = 0
|
||||||
|
|
||||||
|
void pass(int count = 1) {
|
||||||
|
passed += count
|
||||||
|
total += count
|
||||||
|
}
|
||||||
|
|
||||||
|
void skip(int count = 1) {
|
||||||
|
skipped += count
|
||||||
|
total += count
|
||||||
|
}
|
||||||
|
|
||||||
|
void fail(int count = 1) {
|
||||||
|
failed += count
|
||||||
|
total += count
|
||||||
|
}
|
||||||
|
|
||||||
|
void add(Statistics other) {
|
||||||
|
total += other.total
|
||||||
|
passed += other.passed
|
||||||
|
failed += other.failed
|
||||||
|
skipped += other.skipped
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO refactor
|
// TODO refactor
|
||||||
List<String> buildCompileList() {
|
List<String> buildCompileList() {
|
||||||
def result = []
|
def result = []
|
||||||
@@ -259,53 +288,33 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the tests.
|
// Run the tests.
|
||||||
def current = 0
|
|
||||||
def passed = 0
|
|
||||||
def skipped = 0
|
|
||||||
def failed = 0
|
|
||||||
def total = ktFiles.size()
|
|
||||||
def results = []
|
|
||||||
def currentResult = null
|
def currentResult = null
|
||||||
|
statistics = new Statistics()
|
||||||
ktFiles.each {
|
ktFiles.each {
|
||||||
current++
|
|
||||||
source = project.relativePath(it)
|
source = project.relativePath(it)
|
||||||
println("TEST: $it.name ($current/$total, passed: $passed, skipped: $skipped)")
|
println("TEST: $it.name ($statistics.total/$ktFiles.size, passed: $statistics.passed, skipped: $statistics.skipped)")
|
||||||
if (isEnabledForNativeBackend(source)) {
|
if (isEnabledForNativeBackend(source)) {
|
||||||
try {
|
try {
|
||||||
super.executeTest()
|
super.executeTest()
|
||||||
currentResult = new TestResult(it.name, "PASSED", "")
|
currentResult = new TestResult("PASSED")
|
||||||
passed++
|
statistics.pass()
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
currentResult = new TestResult(it.name, "FAILED",
|
currentResult = new TestResult("FAILED",
|
||||||
"Exception: ${ex.getMessage()}. Cause: ${ex.getCause()?.getMessage()}")
|
"Exception: ${ex.getMessage()}. Cause: ${ex.getCause()?.getMessage()}")
|
||||||
failed++
|
statistics.fail()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
currentResult = new TestResult(it.name, "SKIPPED", "")
|
currentResult = new TestResult("SKIPPED")
|
||||||
skipped++
|
statistics.skip()
|
||||||
}
|
}
|
||||||
println("TEST $currentResult.status\n")
|
println("TEST $currentResult.status\n")
|
||||||
results.add(currentResult)
|
results.put(it.name, currentResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the report.
|
// Save the report.
|
||||||
def reportFile = project.file("${outputDirectory}/results.json")
|
def reportFile = project.file("${outputDirectory}/results.json")
|
||||||
def json = new JsonBuilder()
|
def json = JsonOutput.toJson(["statistics" : statistics, "tests" : results])
|
||||||
json {
|
reportFile.write(JsonOutput.prettyPrint(json))
|
||||||
"statistics" "total" : total, "passed" : passed, "failed" : failed, "skipped" : skipped
|
println("TOTAL PASSED: $statistics.passed/$statistics.total (SKIPPED: $statistics.skipped)")
|
||||||
|
|
||||||
"tests" {
|
|
||||||
results.each { result ->
|
|
||||||
"$result.name" {
|
|
||||||
"status" result.status
|
|
||||||
"comment" result.comment
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
reportFile.write(json.toPrettyString())
|
|
||||||
println("TOTAL PASSED: $passed/$total (SKIPPED: $skipped)")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user