[Wasm] stdlib API: make kotlin.assert internal
Being disabled by default and not well-documented, these functions cause confusion among early adopters as to why their code don't work properly. Assert APIs need a proper design across Kotlin platforms. Since APIs are not available in common code and K/JS, it is premature to have such a general feature in a new experimental platform. Compiler tests: * Mute tests that rely on assert. * Replace JVM-specific assert calls with require calls and unmute passed K/JS tests. Merge-request: KT-MR-8636 Merged-by: Svyatoslav Kuzmich <svyatoslav.kuzmich@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
a8f547d080
commit
abf70a586c
@@ -1,3 +1,4 @@
|
||||
// IGNORE_BACKEND: WASM
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
@@ -40,11 +40,11 @@ abstract class TestFnBase(val type: String) {
|
||||
abstract fun testBad(x: Any)
|
||||
|
||||
protected fun assertIs(x: Any, condition: Boolean) {
|
||||
assert(condition) { "x is $type: failed for $x" }
|
||||
require(condition) { "x is $type: failed for $x" }
|
||||
}
|
||||
|
||||
protected fun assertIsNot(x: Any, condition: Boolean) {
|
||||
assert(condition) { "x !is $type: failed for $x" }
|
||||
require(condition) { "x !is $type: failed for $x" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ inline fun <reified T> assertReifiedIs(x: Any, type: String) {
|
||||
catch (e: Throwable) {
|
||||
throw AssertionError("$x is $type: should not throw exceptions, got $e")
|
||||
}
|
||||
assert(answer) { "$x is $type: failed" }
|
||||
require(answer) { "$x is $type: failed" }
|
||||
}
|
||||
|
||||
inline fun <reified T> assertReifiedIsNot(x: Any, type: String) {
|
||||
@@ -54,7 +54,7 @@ inline fun <reified T> assertReifiedIsNot(x: Any, type: String) {
|
||||
catch (e: Throwable) {
|
||||
throw AssertionError("$x !is $type: should not throw exceptions, got $e")
|
||||
}
|
||||
assert(answer) { "$x !is $type: failed" }
|
||||
require(answer) { "$x !is $type: failed" }
|
||||
}
|
||||
|
||||
abstract class TestFnBase(val type: String) {
|
||||
|
||||
@@ -16,7 +16,7 @@ inline fun <reified T> assertReifiedIs(x: Any, type: String) {
|
||||
catch (e: Throwable) {
|
||||
throw AssertionError("$x is $type: should not throw exceptions, got $e")
|
||||
}
|
||||
assert(answer) { "$x is $type: failed" }
|
||||
require(answer) { "$x is $type: failed" }
|
||||
}
|
||||
|
||||
inline fun <reified T> assertReifiedIsNot(x: Any, type: String) {
|
||||
@@ -27,7 +27,7 @@ inline fun <reified T> assertReifiedIsNot(x: Any, type: String) {
|
||||
catch (e: Throwable) {
|
||||
throw AssertionError("$x !is $type: should not throw exceptions, got $e")
|
||||
}
|
||||
assert(answer) { "$x !is $type: failed" }
|
||||
require(answer) { "$x !is $type: failed" }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
@@ -38,7 +38,7 @@ val fns = arrayOf<Any>(::fn0, ::fn1, ::fn2, ::fn3, ::fn4, ::fn5, ::fn6, ::fn7, :
|
||||
inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) {
|
||||
try {
|
||||
val x = cast()
|
||||
assert(x == null) { "$operation: should return null, got $x" }
|
||||
require(x == null) { "$operation: should return null, got $x" }
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
throw AssertionError("$operation: should not throw exceptions, got $e")
|
||||
@@ -48,7 +48,7 @@ inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) {
|
||||
inline fun safeAsReturnsNonNull(operation: String, cast: () -> Any?) {
|
||||
try {
|
||||
val x = cast()
|
||||
assert(x != null) { "$operation: should return non-null" }
|
||||
require(x != null) { "$operation: should return non-null" }
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
throw AssertionError("$operation: should not throw exceptions, got $e")
|
||||
|
||||
@@ -11,7 +11,7 @@ fun fn1(x: Any) {}
|
||||
inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) {
|
||||
try {
|
||||
val x = cast()
|
||||
assert(x == null) { "$operation: should return null, got $x" }
|
||||
require(x == null) { "$operation: should return null, got $x" }
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
throw AssertionError("$operation: should not throw exceptions, got $e")
|
||||
@@ -21,7 +21,7 @@ inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) {
|
||||
inline fun safeAsReturnsNonNull(operation: String, cast: () -> Any?) {
|
||||
try {
|
||||
val x = cast()
|
||||
assert(x != null) { "$operation: should return non-null" }
|
||||
require(x != null) { "$operation: should return non-null" }
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
throw AssertionError("$operation: should not throw exceptions, got $e")
|
||||
|
||||
+10
-15
@@ -1,8 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_STDLIB
|
||||
|
||||
fun unsupported(): Nothing = throw UnsupportedOperationException()
|
||||
@@ -41,7 +36,7 @@ inline fun asSucceeds(operation: String, cast: () -> Unit) {
|
||||
inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) {
|
||||
try {
|
||||
val x = cast()
|
||||
assert(x == null) { "$operation: should return null, got $x" }
|
||||
require(x == null) { "$operation: should return null, got $x" }
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
throw AssertionError("$operation: should not throw exceptions, got $e")
|
||||
@@ -51,7 +46,7 @@ inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) {
|
||||
inline fun safeAsReturnsNonNull(operation: String, cast: () -> Any?) {
|
||||
try {
|
||||
val x = cast()
|
||||
assert(x != null) { "$operation: should return non-null" }
|
||||
require(x != null) { "$operation: should return non-null" }
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
throw AssertionError("$operation: should not throw exceptions, got $e")
|
||||
@@ -111,10 +106,10 @@ inline fun <reified T> reifiedSafeAsReturnsNull(x: Any?, operation: String) {
|
||||
fun box(): String {
|
||||
val w: Any = Weird()
|
||||
|
||||
assert(w is Iterator<*>) { "w is Iterator<*>" }
|
||||
assert(w !is MutableIterator<*>) { "w !is MutableIterator<*>" }
|
||||
assert(w is MutableIterable<*>) { "w is MutableIterable<*>" }
|
||||
assert(w is MutableMap.MutableEntry<*, *>) { "w is MutableMap.MutableEntry<*, *>" }
|
||||
require(w is Iterator<*>) { "w is Iterator<*>" }
|
||||
require(w !is MutableIterator<*>) { "w !is MutableIterator<*>" }
|
||||
require(w is MutableIterable<*>) { "w is MutableIterable<*>" }
|
||||
require(w is MutableMap.MutableEntry<*, *>) { "w is MutableMap.MutableEntry<*, *>" }
|
||||
|
||||
asSucceeds("w as Iterator<*>") { w as Iterator<*> }
|
||||
asFailsWithCCE("w as MutableIterator<*>") { w as MutableIterator<*> }
|
||||
@@ -126,10 +121,10 @@ fun box(): String {
|
||||
safeAsReturnsNonNull("w as? MutableIterable<*>") { w as? MutableIterable<*> }
|
||||
safeAsReturnsNonNull("w as? MutableMap.MutableEntry<*, *>") { w as? MutableMap.MutableEntry<*, *> }
|
||||
|
||||
assert(reifiedIs<Iterator<*>>(w)) { "reifiedIs<Iterator<*>>(w)" }
|
||||
assert(reifiedIsNot<MutableIterator<*>>(w)) { "reifiedIsNot<MutableIterator<*>>(w)" }
|
||||
assert(reifiedIs<MutableIterable<*>>(w)) { "reifiedIs<MutableIterable<*>>(w)" }
|
||||
assert(reifiedIs<MutableMap.MutableEntry<*, *>>(w)) { "reifiedIs<MutableMap.MutableEntry<*, *>>(w)" }
|
||||
require(reifiedIs<Iterator<*>>(w)) { "reifiedIs<Iterator<*>>(w)" }
|
||||
require(reifiedIsNot<MutableIterator<*>>(w)) { "reifiedIsNot<MutableIterator<*>>(w)" }
|
||||
require(reifiedIs<MutableIterable<*>>(w)) { "reifiedIs<MutableIterable<*>>(w)" }
|
||||
require(reifiedIs<MutableMap.MutableEntry<*, *>>(w)) { "reifiedIs<MutableMap.MutableEntry<*, *>>(w)" }
|
||||
|
||||
reifiedAsSucceeds<Iterator<*>>(w, "reified w as Iterator<*>")
|
||||
reifiedAsFailsWithCCE<MutableIterator<*>>(w, "reified w as MutableIterator<*>")
|
||||
|
||||
Vendored
+1
-3
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND: JS, JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// WITH_STDLIB
|
||||
|
||||
package a.b
|
||||
@@ -22,7 +20,7 @@ fun test() {
|
||||
}
|
||||
|
||||
val size = a.toList().size
|
||||
assert(size == 5) { "actual size: $size"}
|
||||
require(size == 5) { "actual size: $size"}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
+2
-2
@@ -15,10 +15,10 @@ fun dougleRange(x: Double?, y: Double) = x?.rangeTo(y)
|
||||
|
||||
inline fun <reified T, R> testSafeRange(x: T, y: T, expectStr: String, safeRange: (T?, T) -> R?) {
|
||||
val rNull = safeRange(null, y)
|
||||
assert (rNull == null) { "${T::class.simpleName}: Expected: null, got $rNull" }
|
||||
require (rNull == null) { "${T::class.simpleName}: Expected: null, got $rNull" }
|
||||
|
||||
val rxy = safeRange(x, y)
|
||||
assert (rxy?.toString() == expectStr) { "${T::class.simpleName}: Expected: $expectStr, got $rxy" }
|
||||
require (rxy?.toString() == expectStr) { "${T::class.simpleName}: Expected: $expectStr, got $rxy" }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// IGNORE_BACKEND: WASM
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
|
||||
+3
-8
@@ -1,8 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_STDLIB
|
||||
|
||||
inline fun<reified T> isinstance(x: Any?): Boolean {
|
||||
@@ -10,9 +5,9 @@ inline fun<reified T> isinstance(x: Any?): Boolean {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assert(isinstance<String>("abc"))
|
||||
assert(isinstance<Int>(1))
|
||||
assert(!isinstance<Int>("abc"))
|
||||
require(isinstance<String>("abc"))
|
||||
require(isinstance<Int>(1))
|
||||
require(!isinstance<Int>("abc"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+1
-6
@@ -1,8 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_STDLIB
|
||||
|
||||
inline fun<reified T> createArray(n: Int, crossinline block: () -> T): Array<T> {
|
||||
@@ -13,6 +8,6 @@ fun box(): String {
|
||||
|
||||
val x = createArray<Int>(5) { 3 }
|
||||
|
||||
assert(x.all { it == 3 })
|
||||
require(x.all { it == 3 })
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_STDLIB
|
||||
|
||||
inline fun<reified T> createArray(n: Int, crossinline block: () -> T): Array<T> {
|
||||
@@ -18,6 +13,6 @@ inline fun<T1, T2, T3, T4, T5, T6, reified R> recursive(
|
||||
fun box(): String {
|
||||
val x = recursive<Int, Int, Int, Int, Int, Int, String>(){ "abc" }
|
||||
|
||||
assert(x.all { it == "abc" })
|
||||
require(x.all { it == "abc" })
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_STDLIB
|
||||
|
||||
inline fun<reified T1, reified T2> createArray(n: Int, crossinline block: () -> Pair<T1, T2>): Pair<Array<T1>, Array<T2>> {
|
||||
@@ -19,9 +14,9 @@ fun box(): String {
|
||||
val y = createArray(5) { Pair(1, "test") }
|
||||
val x = recursive<Int, Int, Int, Int, Int, Int, String>(){ "abc" }
|
||||
|
||||
assert(y.first.all { it == 1 } )
|
||||
assert(y.second.all { it == "test" })
|
||||
assert(x.first.all { it == "abc" })
|
||||
assert(x.second.all { it == "abc" })
|
||||
require(y.first.all { it == 1 } )
|
||||
require(y.second.all { it == "test" })
|
||||
require(x.first.all { it == "abc" })
|
||||
require(x.second.all { it == "abc" })
|
||||
return "OK"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user