buildSrc: split tests into testSuites for teamcity
This commit is contained in:
@@ -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,64 +384,113 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
void start(){}
|
protected class KonanTestCase {
|
||||||
|
protected name
|
||||||
|
|
||||||
TestResult pass() {
|
KonanTestCase(String name) {
|
||||||
statistics.pass()
|
this.name = name
|
||||||
return new TestResult(TestStatus.PASSED)
|
}
|
||||||
|
|
||||||
|
void start(){}
|
||||||
|
|
||||||
|
TestResult pass() {
|
||||||
|
statistics.pass()
|
||||||
|
return new TestResult(TestStatus.PASSED)
|
||||||
|
}
|
||||||
|
|
||||||
|
TestResult fail(TestFailedException e) {
|
||||||
|
statistics.fail()
|
||||||
|
return new TestResult(TestStatus.FAILED, "Cause: ${e.getCause()?.getMessage()}")
|
||||||
|
}
|
||||||
|
|
||||||
|
TestResult error(Exception e) {
|
||||||
|
statistics.error()
|
||||||
|
return new TestResult(TestStatus.ERROR, "Exception: ${e.getMessage()}. Cause: ${e.getCause()?.getMessage()}")
|
||||||
|
}
|
||||||
|
|
||||||
|
TestResult skip() {
|
||||||
|
return new TestResult(TestStatus.SKIPPED)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResult fail(TestFailedException e) {
|
KonanTestCase createTestCase(String name) {
|
||||||
statistics.fail()
|
return new KonanTestCase(name)
|
||||||
return new TestResult(TestStatus.FAILED, "Cause: ${e.getCause()?.getMessage()}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResult error(Exception e) {
|
void start() {}
|
||||||
statistics.error()
|
void finish() {}
|
||||||
return new TestResult(TestStatus.ERROR, "Exception: ${e.getMessage()}. Cause: ${e.getCause()?.getMessage()}")
|
|
||||||
}
|
|
||||||
|
|
||||||
TestResult skip() {
|
|
||||||
return new TestResult(TestStatus.SKIPPED)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TeamcityKonanTestCase extends KonanTestCase {
|
class TeamcityKonanTestSuite extends KonanTestSuite {
|
||||||
TeamcityKonanTestCase(String name, Statistics statistics) {
|
TeamcityKonanTestSuite(String suiteName, Statistics statistics) {
|
||||||
super(name, statistics)
|
super(suiteName, statistics)
|
||||||
|
}
|
||||||
|
|
||||||
|
class TeamcityKonanTestCase extends KonanTestSuite.KonanTestCase {
|
||||||
|
|
||||||
|
TeamcityKonanTestCase(String name) {
|
||||||
|
super(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
private teamcityFinish() {
|
||||||
|
teamcityReport("testFinished name='$name'")
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() {
|
||||||
|
teamcityReport("testStarted name='$name'")
|
||||||
|
}
|
||||||
|
|
||||||
|
TestResult pass() {
|
||||||
|
teamcityFinish()
|
||||||
|
return super.pass()
|
||||||
|
}
|
||||||
|
|
||||||
|
TestResult fail(TestFailedException e) {
|
||||||
|
teamcityReport("testFailed type='comparisonFailure' name='$name' message='${toTeamCityFormat(e.getMessage())}'")
|
||||||
|
teamcityFinish()
|
||||||
|
return super.fail(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
TestResult error(Exception e) {
|
||||||
|
def writer = new StringWriter()
|
||||||
|
e.printStackTrace(new PrintWriter(writer))
|
||||||
|
def rawString = writer.toString()
|
||||||
|
|
||||||
|
teamcityReport("testFailed name='$name' message='${toTeamCityFormat(e.getMessage())}' details='${toTeamCityFormat(rawString)}'")
|
||||||
|
teamcityFinish()
|
||||||
|
return super.error(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
TestResult skip() {
|
||||||
|
teamcityReport("testIgnored name='$name'")
|
||||||
|
teamcityFinish()
|
||||||
|
return super.skip()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TeamcityKonanTestCase createTestCase(String name) {
|
||||||
|
return new TeamcityKonanTestCase(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
private teamcityReport(String msg) {
|
private teamcityReport(String msg) {
|
||||||
println("##teamcity[$msg]")
|
println("##teamcity[$msg]")
|
||||||
}
|
}
|
||||||
|
|
||||||
private teamcityFinish() {
|
|
||||||
teamcityReport("testFinished name='$name'")
|
|
||||||
}
|
|
||||||
|
|
||||||
void start() {
|
|
||||||
teamcityReport("testStarted name='$name'")
|
|
||||||
}
|
|
||||||
|
|
||||||
TestResult pass() {
|
|
||||||
teamcityFinish()
|
|
||||||
return super.pass()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Teamcity require escaping some symbols in pipe manner.
|
* Teamcity require escaping some symbols in pipe manner.
|
||||||
* https://github.com/GitTools/GitVersion/issues/94
|
* https://github.com/GitTools/GitVersion/issues/94
|
||||||
@@ -450,30 +502,14 @@ fun main(args : Array<String>) {
|
|||||||
.replaceAll("'", "|'")
|
.replaceAll("'", "|'")
|
||||||
.replaceAll("\\[", "|[")
|
.replaceAll("\\[", "|[")
|
||||||
.replaceAll("]", "|]")
|
.replaceAll("]", "|]")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResult fail(TestFailedException e) {
|
void start() {
|
||||||
teamcityReport("testFailed type='comparisonFailure' name='$name' message='${toTeamCityFormat(e.getMessage())}'")
|
teamcityReport("testSuiteStarted name='$name'")
|
||||||
teamcityFinish()
|
|
||||||
return super.fail(e)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void finish() {
|
||||||
TestResult error(Exception e) {
|
teamcityReport("testSuiteFinished name='$name'")
|
||||||
def writer = new StringWriter()
|
|
||||||
e.printStackTrace(new PrintWriter(writer))
|
|
||||||
def rawString = writer.toString()
|
|
||||||
|
|
||||||
teamcityReport("testFailed name='$name' message='${toTeamCityFormat(e.getMessage())}' details='${toTeamCityFormat(rawString)}'")
|
|
||||||
teamcityFinish()
|
|
||||||
return super.error(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
TestResult skip() {
|
|
||||||
teamcityReport("testIgnored name='$name'")
|
|
||||||
teamcityFinish()
|
|
||||||
return super.skip()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user