Rewrite KonanTestSuite to Kotlin
This commit is contained in:
committed by
Pavel Punegov
parent
8fd7293b0a
commit
ac1d893857
@@ -180,8 +180,8 @@ task sanity {
|
||||
// Collect results in one json.
|
||||
task resultsTask() {
|
||||
doLast {
|
||||
Map<String, Map<String, RunExternalTestGroup.TestResult>> results = [:]
|
||||
def statistics = new RunExternalTestGroup.Statistics()
|
||||
Map<String, Map<String, TestResult>> results = [:]
|
||||
def statistics = new Statistics()
|
||||
tasks.withType(RunExternalTestGroup).matching { it.state.executed }.each {
|
||||
results.put(it.name, it.results)
|
||||
statistics.add(it.statistics)
|
||||
|
||||
@@ -46,3 +46,8 @@ dependencies {
|
||||
rootProject.dependencies {
|
||||
runtime project(path)
|
||||
}
|
||||
|
||||
compileGroovy {
|
||||
// Add Kotlin classes to a classpath for the Groovy compiler
|
||||
classpath += project.files(compileKotlin.destinationDir)
|
||||
}
|
||||
@@ -474,7 +474,7 @@ class RunKonanTest extends ExtKonanTest {
|
||||
|
||||
class RunStdlibTest extends RunKonanTest {
|
||||
public def inDevelopersRun = false
|
||||
public def statistics = new RunExternalTestGroup.Statistics()
|
||||
public def statistics = new Statistics()
|
||||
|
||||
RunStdlibTest() {
|
||||
super('buildKonanStdlibTests')
|
||||
@@ -651,57 +651,6 @@ class RunExternalTestGroup extends RunStandaloneKonanTest {
|
||||
RunExternalTestGroup() {
|
||||
}
|
||||
|
||||
static enum TestStatus {
|
||||
PASSED,
|
||||
FAILED,
|
||||
ERROR,
|
||||
SKIPPED
|
||||
}
|
||||
static class TestResult {
|
||||
TestStatus status = null
|
||||
String comment = null
|
||||
|
||||
TestResult(TestStatus status, String comment = ""){
|
||||
this.status = status;
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
||||
static class Statistics {
|
||||
int total = 0
|
||||
int passed = 0
|
||||
int failed = 0
|
||||
int error = 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 error(int count = 1) {
|
||||
error += count
|
||||
total += count
|
||||
}
|
||||
|
||||
void add(Statistics other) {
|
||||
total += other.total
|
||||
passed += other.passed
|
||||
failed += other.failed
|
||||
error += other.error
|
||||
skipped += other.skipped
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
List<String> buildCompileList() {
|
||||
// Already build by the previous step
|
||||
@@ -1059,129 +1008,4 @@ fun runTest() {
|
||||
return new TeamcityKonanTestSuite(name, statistics)
|
||||
return new KonanTestSuite(name, statistics)
|
||||
}
|
||||
|
||||
class KonanTestSuite {
|
||||
protected name;
|
||||
protected statistics;
|
||||
|
||||
KonanTestSuite(String name, Statistics statistics) {
|
||||
this.name = name
|
||||
this.statistics = statistics
|
||||
}
|
||||
|
||||
protected class KonanTestCase {
|
||||
protected name
|
||||
|
||||
KonanTestCase(String name) {
|
||||
this.name = name
|
||||
}
|
||||
|
||||
void start(){}
|
||||
|
||||
TestResult pass() {
|
||||
statistics.pass()
|
||||
return new TestResult(TestStatus.PASSED)
|
||||
}
|
||||
|
||||
TestResult fail(TestFailedException e) {
|
||||
statistics.fail()
|
||||
println(e.getMessage())
|
||||
return new TestResult(TestStatus.FAILED, "Exception: ${e.getMessage()}. Cause: ${e.getCause()?.getMessage()}")
|
||||
}
|
||||
|
||||
TestResult error(Exception e) {
|
||||
statistics.error()
|
||||
return new TestResult(TestStatus.ERROR, "Exception: ${e.getMessage()}. Cause: ${e.getCause()?.getMessage()}")
|
||||
}
|
||||
|
||||
TestResult skip() {
|
||||
statistics.skip()
|
||||
return new TestResult(TestStatus.SKIPPED)
|
||||
}
|
||||
}
|
||||
|
||||
KonanTestCase createTestCase(String name) {
|
||||
return new KonanTestCase(name)
|
||||
}
|
||||
|
||||
void start() {}
|
||||
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() {
|
||||
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) {
|
||||
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'")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
package org.jetbrains.kotlin
|
||||
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
|
||||
enum class TestStatus {
|
||||
PASSED,
|
||||
FAILED,
|
||||
ERROR,
|
||||
SKIPPED
|
||||
}
|
||||
|
||||
data class TestResult(val status: TestStatus, val comment: String = "")
|
||||
|
||||
data class Statistics(
|
||||
var passed: Int = 0,
|
||||
var failed: Int = 0,
|
||||
var error: Int = 0,
|
||||
var skipped: Int = 0) {
|
||||
|
||||
val total: Int
|
||||
get() = passed + failed + error + skipped
|
||||
|
||||
fun pass(count: Int = 1) { passed += count }
|
||||
|
||||
fun skip(count: Int = 1) { skipped += count }
|
||||
|
||||
fun fail(count: Int = 1) { failed += count }
|
||||
|
||||
fun error(count: Int = 1) { error += count }
|
||||
|
||||
fun add(other: Statistics) {
|
||||
passed += other.passed
|
||||
failed += other.failed
|
||||
error += other.error
|
||||
skipped += other.skipped
|
||||
}
|
||||
}
|
||||
|
||||
open class KonanTestSuite(val name: String, val statistics: Statistics) {
|
||||
|
||||
open inner class KonanTestCase(val name: String) {
|
||||
open fun start() {}
|
||||
|
||||
open fun pass(): TestResult {
|
||||
statistics.pass()
|
||||
return TestResult(TestStatus.PASSED)
|
||||
}
|
||||
|
||||
open fun fail(e: RuntimeException): TestResult {
|
||||
statistics.fail()
|
||||
println(e.message)
|
||||
return TestResult(TestStatus.FAILED, "Exception: ${e.message}. Cause: ${e.cause?.message}")
|
||||
}
|
||||
|
||||
open fun error(e: Exception): TestResult {
|
||||
statistics.error()
|
||||
return TestResult(TestStatus.ERROR, "Exception: ${e.message}. Cause: ${e.cause?.message}")
|
||||
}
|
||||
|
||||
open fun skip(): TestResult {
|
||||
statistics.skip()
|
||||
return TestResult(TestStatus.SKIPPED)
|
||||
}
|
||||
}
|
||||
|
||||
open fun createTestCase(name: String) = KonanTestCase(name)
|
||||
|
||||
open fun start() {}
|
||||
open fun finish() {}
|
||||
}
|
||||
|
||||
class TeamcityKonanTestSuite(name: String, statistics: Statistics) : KonanTestSuite(name, statistics) {
|
||||
|
||||
inner class TeamcityKonanTestCase(name: String) : KonanTestCase(name) {
|
||||
private fun teamcityFinish() {
|
||||
teamcityReport("testFinished name='$name'")
|
||||
}
|
||||
|
||||
override fun start() {
|
||||
teamcityReport("testStarted name='$name'")
|
||||
}
|
||||
|
||||
override fun pass(): TestResult {
|
||||
teamcityFinish()
|
||||
return super.pass()
|
||||
}
|
||||
|
||||
override fun fail(e: RuntimeException): TestResult {
|
||||
teamcityReport("testFailed type='comparisonFailure' name='$name' message='${toTeamCityFormat(e.message)}'")
|
||||
teamcityFinish()
|
||||
return super.fail(e)
|
||||
}
|
||||
|
||||
override fun error(e: Exception): TestResult {
|
||||
val writer = StringWriter()
|
||||
e.printStackTrace(PrintWriter(writer))
|
||||
val rawString = writer.toString()
|
||||
|
||||
teamcityReport("testFailed name='$name' message='${toTeamCityFormat(e.message)}' " +
|
||||
"details='${toTeamCityFormat(rawString)}'")
|
||||
teamcityFinish()
|
||||
return super.error(e)
|
||||
}
|
||||
|
||||
override fun skip(): TestResult {
|
||||
teamcityReport("testIgnored name='$name'")
|
||||
teamcityFinish()
|
||||
return super.skip()
|
||||
}
|
||||
}
|
||||
|
||||
override fun createTestCase(name: String) = TeamcityKonanTestCase(name)
|
||||
|
||||
private fun teamcityReport(msg: String) {
|
||||
println("##teamcity[$msg]")
|
||||
}
|
||||
|
||||
/**
|
||||
* Teamcity require escaping some symbols in pipe manner.
|
||||
* https://github.com/GitTools/GitVersion/issues/94
|
||||
*/
|
||||
fun toTeamCityFormat(inStr: String?): String = inStr?.let {
|
||||
it.replace("\\|", "||")
|
||||
.replace("\r", "|r")
|
||||
.replace("\n", "|n")
|
||||
.replace("'", "|'")
|
||||
.replace("\\[", "|[")
|
||||
.replace("]", "|]")
|
||||
} ?: "null"
|
||||
|
||||
override fun start() {
|
||||
teamcityReport("testSuiteStarted name='$name'")
|
||||
}
|
||||
|
||||
override fun finish() {
|
||||
teamcityReport("testSuiteFinished name='$name'")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user