buildSrc: Save test results to JSON

This commit is contained in:
Ilya Matveev
2017-01-24 16:05:23 +03:00
committed by ilmat192
parent a4c4b1e7af
commit c04233aebb
2 changed files with 48 additions and 18 deletions
-5
View File
@@ -1,10 +1,5 @@
import com.google.common.collect.Lists
import groovy.io.FileType
import org.jetbrains.kotlin.* import org.jetbrains.kotlin.*
import java.nio.file.*
import java.util.regex.Matcher
configurations { configurations {
cli_bc cli_bc
} }
@@ -1,5 +1,6 @@
package org.jetbrains.kotlin package org.jetbrains.kotlin
import groovy.json.JsonBuilder
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,6 +142,17 @@ class RunExternalTestGroup extends RunKonanTest {
String filter = project.findProperty("filter") String filter = project.findProperty("filter")
String goldValue = "OK" String goldValue = "OK"
class TestResult {
String name = null
String status = null
String comment = null
TestResult(String name, String status, String comment){
this.name = name;
this.status = status;
this.comment = comment;
}
}
// TODO refactor // TODO refactor
List<String> buildCompileList() { List<String> buildCompileList() {
@@ -212,13 +224,13 @@ class RunExternalTestGroup extends RunKonanTest {
def text = project.file(fileName).text def text = project.file(fileName).text
def targetBackend = findLinesWithPrefixesRemoved(text, "// TARGET_BACKEND") def targetBackend = findLinesWithPrefixesRemoved(text, "// TARGET_BACKEND")
if (targetBackend.size() != 0) { if (targetBackend.size() != 0) {
// There is some target backend. Check if it is NATIVE or not // There is some target backend. Check if it is NATIVE or not.
for (String s : targetBackend) { for (String s : targetBackend) {
if (s.contains("NATIVE")){ return true } if (s.contains("NATIVE")){ return true }
} }
return false return false
} else { } else {
// No target backend. Check if NATIVE backend is ignored // No target backend. Check if NATIVE backend is ignored.
def ignoredBackends = findLinesWithPrefixesRemoved(text, "// IGNORE_BACKEND: ") def ignoredBackends = findLinesWithPrefixesRemoved(text, "// IGNORE_BACKEND: ")
for (String s : ignoredBackends) { for (String s : ignoredBackends) {
if (s.contains("NATIVE")) { return false } if (s.contains("NATIVE")) { return false }
@@ -231,9 +243,8 @@ class RunExternalTestGroup extends RunKonanTest {
@Override @Override
void executeTest() { void executeTest() {
createOutputDirectory() createOutputDirectory()
def logFile = project.file("${outputDirectory}/result.md")
logFile.append("\n$groupDirectory\n\n") // Form the test list.
logFile.append("|Test|Status|Comment|\n|----|------|-------|\n")
def ktFiles = project.file(groupDirectory).listFiles(new FileFilter() { def ktFiles = project.file(groupDirectory).listFiles(new FileFilter() {
@Override @Override
boolean accept(File pathname) { boolean accept(File pathname) {
@@ -246,12 +257,15 @@ class RunExternalTestGroup extends RunKonanTest {
it.name =~ pattern it.name =~ pattern
} }
} }
// Run the tests.
def current = 0 def current = 0
def passed = 0 def passed = 0
def skipped = 0 def skipped = 0
def failed = 0
def total = ktFiles.size() def total = ktFiles.size()
def status = null def results = []
def comment = null def currentResult = null
ktFiles.each { ktFiles.each {
current++ current++
source = project.relativePath(it) source = project.relativePath(it)
@@ -259,18 +273,39 @@ class RunExternalTestGroup extends RunKonanTest {
if (isEnabledForNativeBackend(source)) { if (isEnabledForNativeBackend(source)) {
try { try {
super.executeTest() super.executeTest()
status = "PASSED"; comment = "" currentResult = new TestResult(it.name, "PASSED", "")
passed++ passed++
} catch (Exception ex) { } catch (Exception ex) {
status = "FAILED"; comment = "Exception: ${ex.getMessage()}. Cause: ${ex.getCause()?.getMessage()}" currentResult = new TestResult(it.name, "FAILED",
"Exception: ${ex.getMessage()}. Cause: ${ex.getCause()?.getMessage()}")
failed++
} }
} else { } else {
status = "SKIPPED"; comment = "" currentResult = new TestResult(it.name, "SKIPPED", "")
skipped++ skipped++
} }
println("TEST $status\n") println("TEST $currentResult.status\n")
logFile.append("|$it.name|$status|$comment|\n") results.add(currentResult)
} }
println("TOTAL PASSED: $passed/$current (SKIPPED: $skipped)")
// Save the report.
def reportFile = project.file("${outputDirectory}/results.json")
def json = new JsonBuilder()
json {
"statistics" "total" : total, "passed" : passed, "failed" : failed, "skipped" : skipped
"tests" {
results.each { result ->
"$result.name" {
"status" result.status
"comment" result.comment
}
}
}
}
reportFile.write(json.toPrettyString())
println("TOTAL PASSED: $passed/$total (SKIPPED: $skipped)")
} }
} }