KonanTest: infrostructure enhancements.
- test status in enum. - fails are bit different from errors. it takes reports generated in output directory and sum statistics and publish result on slack.
This commit is contained in:
committed by
vvlevchenko
parent
19dbdf3137
commit
16df5c4299
@@ -0,0 +1,5 @@
|
|||||||
|
package kotlin.test
|
||||||
|
|
||||||
|
class TestFailedException(val msg:String):RuntimeException(msg)
|
||||||
|
|
||||||
|
fun <T> assertEquals(a:T, b:T, msg:String) { if (a != b) throw TestFailedException(msg) }
|
||||||
@@ -146,11 +146,16 @@ abstract class KonanTest extends DefaultTask {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (goldValue != null && goldValue != out.toString()) {
|
if (goldValue != null && goldValue != out.toString()) {
|
||||||
throw new RuntimeException("test failed.")
|
throw new TestFailedException("test failed.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestFailedException extends RuntimeException {
|
||||||
|
public TestFailedException(String s) {
|
||||||
|
super(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ParallelizableTask
|
@ParallelizableTask
|
||||||
class RunKonanTest extends KonanTest {
|
class RunKonanTest extends KonanTest {
|
||||||
void compileTest(List<String> filesToCompile, String exe) {
|
void compileTest(List<String> filesToCompile, String exe) {
|
||||||
@@ -206,20 +211,26 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
goldValue = "OK"
|
goldValue = "OK"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static enum TestStatus {
|
||||||
|
PASSED,
|
||||||
|
FAILED,
|
||||||
|
ERROR,
|
||||||
|
SKIPPED
|
||||||
|
}
|
||||||
static class TestResult {
|
static class TestResult {
|
||||||
String status = null
|
TestStatus status = null
|
||||||
String comment = null
|
String comment = null
|
||||||
|
|
||||||
TestResult(String status, String comment = ""){
|
TestResult(TestStatus status, String comment = ""){
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Statistics {
|
static class Statistics {
|
||||||
int total = 0
|
int total = 0
|
||||||
int passed = 0
|
int passed = 0
|
||||||
int failed = 0
|
int failed = 0
|
||||||
|
int error = 0
|
||||||
int skipped = 0
|
int skipped = 0
|
||||||
|
|
||||||
void pass(int count = 1) {
|
void pass(int count = 1) {
|
||||||
@@ -237,10 +248,16 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
total += count
|
total += count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void error(int count = 1) {
|
||||||
|
error += count
|
||||||
|
total += count
|
||||||
|
}
|
||||||
|
|
||||||
void add(Statistics other) {
|
void add(Statistics other) {
|
||||||
total += other.total
|
total += other.total
|
||||||
passed += other.passed
|
passed += other.passed
|
||||||
failed += other.failed
|
failed += other.failed
|
||||||
|
error += other.error
|
||||||
skipped += other.skipped
|
skipped += other.skipped
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,11 +278,22 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
}
|
}
|
||||||
createLauncherFile("$outputDirectory/_launcher.kt", boxPackage)
|
createLauncherFile("$outputDirectory/_launcher.kt", boxPackage)
|
||||||
result.add("$outputDirectory/_launcher.kt")
|
result.add("$outputDirectory/_launcher.kt")
|
||||||
|
result.add(project.file("testUtils.kt"))
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
void createLauncherFile(String file, String pkg) {
|
void createLauncherFile(String file, String pkg) {
|
||||||
createFile(file, "fun main(args : Array<String>) { print(${pkg}box()) }")
|
createFile(file, """
|
||||||
|
import kotlin.test.TestFailedException
|
||||||
|
|
||||||
|
fun main(args : Array<String>) {
|
||||||
|
try {
|
||||||
|
print(${pkg}box())
|
||||||
|
} catch (e:TestFailedException) {
|
||||||
|
print("FAIL")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""")
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> findLinesWithPrefixesRemoved(String text, String prefix) {
|
List<String> findLinesWithPrefixesRemoved(String text, String prefix) {
|
||||||
@@ -325,15 +353,19 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
if (isEnabledForNativeBackend(source)) {
|
if (isEnabledForNativeBackend(source)) {
|
||||||
try {
|
try {
|
||||||
super.executeTest()
|
super.executeTest()
|
||||||
currentResult = new TestResult("PASSED")
|
currentResult = new TestResult(TestStatus.PASSED)
|
||||||
statistics.pass()
|
statistics.pass()
|
||||||
} catch (Exception ex) {
|
} catch (TestFailedException e) {
|
||||||
currentResult = new TestResult("FAILED",
|
currentResult = new TestResult(TestStatus.FAILED,
|
||||||
"Exception: ${ex.getMessage()}. Cause: ${ex.getCause()?.getMessage()}")
|
"Cause: ${e.getCause()?.getMessage()}")
|
||||||
statistics.fail()
|
statistics.fail()
|
||||||
|
} catch (Exception ex) {
|
||||||
|
currentResult = new TestResult(TestStatus.ERROR,
|
||||||
|
"Exception: ${ex.getMessage()}. Cause: ${ex.getCause()?.getMessage()}")
|
||||||
|
statistics.error()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
currentResult = new TestResult("SKIPPED")
|
currentResult = new TestResult(TestStatus.SKIPPED)
|
||||||
statistics.skip()
|
statistics.skip()
|
||||||
}
|
}
|
||||||
println("TEST $currentResult.status\n")
|
println("TEST $currentResult.status\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user