buildSrc: split tests into testSuites for teamcity

This commit is contained in:
Ilya Matveev
2017-02-21 15:48:56 +03:00
committed by ilmat192
parent 84cb52afed
commit 9e2fe888e4
@@ -350,10 +350,12 @@ fun main(args : Array<String>) {
// Run the tests. // Run the tests.
def currentResult = null def currentResult = null
statistics = new Statistics() statistics = new Statistics()
def testSuite = createTestSuite(name, statistics)
testSuite.start()
ktFiles.each { ktFiles.each {
source = project.relativePath(it) source = project.relativePath(it)
def testCase = testCase(it.name, statistics)
println("TEST: $it.name ($statistics.total/${ktFiles.size()}, passed: $statistics.passed, skipped: $statistics.skipped)") println("TEST: $it.name ($statistics.total/${ktFiles.size()}, passed: $statistics.passed, skipped: $statistics.skipped)")
def testCase = testSuite.createTestCase(it.name)
testCase.start() testCase.start()
if (isEnabledForNativeBackend(source)) { if (isEnabledForNativeBackend(source)) {
try { try {
@@ -373,6 +375,7 @@ fun main(args : Array<String>) {
} }
results.put(it.name, currentResult) results.put(it.name, currentResult)
} }
testSuite.finish()
// Save the report. // Save the report.
def reportFile = project.file("${outputDirectory}/results.json") def reportFile = project.file("${outputDirectory}/results.json")
@@ -381,20 +384,28 @@ fun main(args : Array<String>) {
println("TOTAL PASSED: $statistics.passed/$statistics.total (SKIPPED: $statistics.skipped)") println("TOTAL PASSED: $statistics.passed/$statistics.total (SKIPPED: $statistics.skipped)")
} }
KonanTestCase testCase(String name, Statistics statistics) { KonanTestSuite createTestSuite(String name, Statistics statistics) {
if (System.getenv("TEAMCITY_BUILD_PROPERTIES_FILE") != null) if (System.getenv("TEAMCITY_BUILD_PROPERTIES_FILE") != null)
return new TeamcityKonanTestCase(name, statistics) return new TeamcityKonanTestSuite(name, statistics)
return new KonanTestCase(name, statistics) return new KonanTestSuite(name, statistics)
} }
class KonanTestCase { class KonanTestSuite {
protected name; protected name;
protected statistics; protected statistics;
KonanTestCase(String name, Statistics statistics) {
KonanTestSuite(String name, Statistics statistics) {
this.name = name this.name = name
this.statistics = statistics this.statistics = statistics
} }
protected class KonanTestCase {
protected name
KonanTestCase(String name) {
this.name = name
}
void start(){} void start(){}
TestResult pass() { TestResult pass() {
@@ -417,13 +428,23 @@ fun main(args : Array<String>) {
} }
} }
class TeamcityKonanTestCase extends KonanTestCase { KonanTestCase createTestCase(String name) {
TeamcityKonanTestCase(String name, Statistics statistics) { return new KonanTestCase(name)
super(name, statistics)
} }
private teamcityReport(String msg) { void start() {}
println("##teamcity[$msg]") void finish() {}
}
class TeamcityKonanTestSuite extends KonanTestSuite {
TeamcityKonanTestSuite(String suiteName, Statistics statistics) {
super(suiteName, statistics)
}
class TeamcityKonanTestCase extends KonanTestSuite.KonanTestCase {
TeamcityKonanTestCase(String name) {
super(name)
} }
private teamcityFinish() { private teamcityFinish() {
@@ -439,27 +460,12 @@ fun main(args : Array<String>) {
return super.pass() return super.pass()
} }
/**
* Teamcity require escaping some symbols in pipe manner.
* https://github.com/GitTools/GitVersion/issues/94
*/
String toTeamCityFormat(String inStr) {
return inStr.replaceAll("\\|", "||")
.replaceAll("\r", "|r")
.replaceAll("\n", "|n")
.replaceAll("'", "|'")
.replaceAll("\\[", "|[")
.replaceAll("]", "|]")
}
TestResult fail(TestFailedException e) { TestResult fail(TestFailedException e) {
teamcityReport("testFailed type='comparisonFailure' name='$name' message='${toTeamCityFormat(e.getMessage())}'") teamcityReport("testFailed type='comparisonFailure' name='$name' message='${toTeamCityFormat(e.getMessage())}'")
teamcityFinish() teamcityFinish()
return super.fail(e) return super.fail(e)
} }
TestResult error(Exception e) { TestResult error(Exception e) {
def writer = new StringWriter() def writer = new StringWriter()
e.printStackTrace(new PrintWriter(writer)) e.printStackTrace(new PrintWriter(writer))
@@ -476,4 +482,34 @@ fun main(args : Array<String>) {
return super.skip() return super.skip()
} }
} }
TeamcityKonanTestCase createTestCase(String name) {
return new TeamcityKonanTestCase(name)
}
private teamcityReport(String msg) {
println("##teamcity[$msg]")
}
/**
* Teamcity require escaping some symbols in pipe manner.
* https://github.com/GitTools/GitVersion/issues/94
*/
String toTeamCityFormat(String inStr) {
return inStr.replaceAll("\\|", "||")
.replaceAll("\r", "|r")
.replaceAll("\n", "|n")
.replaceAll("'", "|'")
.replaceAll("\\[", "|[")
.replaceAll("]", "|]")
}
void start() {
teamcityReport("testSuiteStarted name='$name'")
}
void finish() {
teamcityReport("testSuiteFinished name='$name'")
}
}
} }