kotlin.test: 'fail' returns Nothing, 'assertFails' returns Throwable (not nullable).

Js tests now fail at the first failed assertion.
#KT-10289 Fixed
#KT-10369 Fixed
This commit is contained in:
Ilya Gorbunov
2016-01-13 04:16:42 +03:00
parent 8fdd8179b9
commit f91c01919b
9 changed files with 36 additions and 20 deletions
+3
View File
@@ -27,6 +27,9 @@ public class NumberFormatException(message: String? = null) : RuntimeException(m
@library
public class NullPointerException(message: String? = null) : RuntimeException(message) {}
@library
public class AssertionError(message: String? = null) : Error(message) {}
@library
public interface Runnable {
public open fun run() : Unit;
+11 -2
View File
@@ -18,14 +18,23 @@ public var asserter: Asserter = QUnitAsserter()
public class QUnitAsserter(): Asserter {
public override fun assertTrue(lazyMessage: () -> String?, actual: Boolean) {
QUnit.ok(actual, lazyMessage())
assertTrue(actual, lazyMessage())
}
public override fun assertTrue(message: String?, actual: Boolean) {
QUnit.ok(actual, message)
if (!actual) failWithMessage(message)
}
public override fun fail(message: String?) {
public override fun fail(message: String?): Nothing {
QUnit.ok(false, message)
failWithMessage(message)
}
private fun failWithMessage(message: String?): Nothing {
if (message == null)
throw AssertionError()
else
throw AssertionError(message)
}
}
+8 -3
View File
@@ -21,11 +21,15 @@ var JsTests = (function () {
var assert = function (isTrue, message) {
if (!isTrue) {
reporter.reportError(message);
throw failedTest;
fail(message);
}
};
var fail = function (message) {
reporter.reportError(message);
throw failedTest;
};
var init = function () {
init = function() {};
Kotlin.modules["JS_TESTS"].kotlin.test.init();
@@ -49,6 +53,7 @@ var JsTests = (function () {
};
return {
test: test,
assert: assert
assert: assert,
fail: fail
}
})();
+4 -3
View File
@@ -7,10 +7,11 @@ fun init() {
}
public class JsTestsAsserter() : Asserter {
public override fun fail(message: String?) {
assert(false, message)
}
public override fun fail(message: String?): Nothing = failWithMessage(message)
}
@native("JsTests.assert")
public fun assert(value: Boolean, message: String?): Unit = noImpl
@native("JsTests.fail")
private fun failWithMessage(message: String?): Nothing = noImpl
+1
View File
@@ -200,6 +200,7 @@
Kotlin.UnsupportedOperationException = createClassNowWithMessage(Kotlin.RuntimeException);
Kotlin.IndexOutOfBoundsException = createClassNowWithMessage(Kotlin.RuntimeException);
Kotlin.IOException = createClassNowWithMessage(Kotlin.Exception);
Kotlin.AssertionError = createClassNowWithMessage(Kotlin.Error);
Kotlin.throwNPE = function (message) {
throw new Kotlin.NullPointerException(message);