diff --git a/compiler/testData/codegen/box/assert/alwaysEnable.kt b/compiler/testData/codegen/box/assert/alwaysEnable.kt index 076ae6d12bf..c33cc157e43 100644 --- a/compiler/testData/codegen/box/assert/alwaysEnable.kt +++ b/compiler/testData/codegen/box/assert/alwaysEnable.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: STDLIB_ASSERT // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // IGNORE_BACKEND: JS diff --git a/compiler/testData/codegen/box/casts/functions/asFunKBig.kt b/compiler/testData/codegen/box/casts/functions/asFunKBig.kt index b9b74d8bc6a..857b6c39825 100644 --- a/compiler/testData/codegen/box/casts/functions/asFunKBig.kt +++ b/compiler/testData/codegen/box/casts/functions/asFunKBig.kt @@ -1,5 +1,5 @@ // IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: KOTLIN_TEST_LIB +// WASM_MUTE_REASON: CLASS_REFERENCES // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: muted automatically, investigate should it be ran for JS or not diff --git a/compiler/testData/codegen/box/casts/functions/isFunKBig.kt b/compiler/testData/codegen/box/casts/functions/isFunKBig.kt index 8e144added4..821e78fb38c 100644 --- a/compiler/testData/codegen/box/casts/functions/isFunKBig.kt +++ b/compiler/testData/codegen/box/casts/functions/isFunKBig.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: IGNORED_IN_JS // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: muted automatically, investigate should it be ran for JS or not diff --git a/compiler/testData/codegen/box/casts/functions/reifiedAsFunKBig.kt b/compiler/testData/codegen/box/casts/functions/reifiedAsFunKBig.kt index fe47ae62f7f..5820c0e753f 100644 --- a/compiler/testData/codegen/box/casts/functions/reifiedAsFunKBig.kt +++ b/compiler/testData/codegen/box/casts/functions/reifiedAsFunKBig.kt @@ -1,5 +1,5 @@ // IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: KOTLIN_TEST_LIB +// WASM_MUTE_REASON: CLASS_REFERENCES // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: muted automatically, investigate should it be ran for JS or not diff --git a/compiler/testData/codegen/box/casts/functions/reifiedIsFunKBig.kt b/compiler/testData/codegen/box/casts/functions/reifiedIsFunKBig.kt index e71fc2846b9..f91b9746982 100644 --- a/compiler/testData/codegen/box/casts/functions/reifiedIsFunKBig.kt +++ b/compiler/testData/codegen/box/casts/functions/reifiedIsFunKBig.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: IGNORED_IN_JS // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: muted automatically, investigate should it be ran for JS or not diff --git a/compiler/testData/codegen/box/casts/functions/reifiedIsFunKSmall.kt b/compiler/testData/codegen/box/casts/functions/reifiedIsFunKSmall.kt index a8c328c2fd2..9225f9021c2 100644 --- a/compiler/testData/codegen/box/casts/functions/reifiedIsFunKSmall.kt +++ b/compiler/testData/codegen/box/casts/functions/reifiedIsFunKSmall.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: IGNORED_IN_JS // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: muted automatically, investigate should it be ran for JS or not diff --git a/compiler/testData/codegen/box/constants/comparisonTrue.kt b/compiler/testData/codegen/box/constants/comparisonTrue.kt index daca2bae7c9..86603391ab9 100644 --- a/compiler/testData/codegen/box/constants/comparisonTrue.kt +++ b/compiler/testData/codegen/box/constants/comparisonTrue.kt @@ -1,3 +1,6 @@ +// IGNORE_BACKEND: WASM +// WASM_MUTE_REASON: FLAKY + // WITH_RUNTIME fun foo(): Array { return arrayOf( diff --git a/libraries/stdlib/wasm/src/kotlin/Assertions.kt b/libraries/stdlib/wasm/src/kotlin/Assertions.kt new file mode 100644 index 00000000000..fca88b71234 --- /dev/null +++ b/libraries/stdlib/wasm/src/kotlin/Assertions.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package kotlin + +// TODO: Make this dependant on the compiler flag (like -ea on JVM) + +/** + * Throws an [AssertionError] if the [value] is false. + */ +@kotlin.internal.InlineOnly +public inline fun assert(value: Boolean) { + assert(value) { "Assertion failed" } +} + +/** + * Throws an [AssertionError] calculated by [lazyMessage] if the [value] is false. + */ +@kotlin.internal.InlineOnly +public inline fun assert(value: Boolean, lazyMessage: () -> Any) { + if (!value) { + val message = lazyMessage() + throw AssertionError(message) + } +} diff --git a/libraries/stdlib/wasm/stubs/testHelpers.kt b/libraries/stdlib/wasm/stubs/testHelpers.kt index 70128e11706..0abb0b3909e 100644 --- a/libraries/stdlib/wasm/stubs/testHelpers.kt +++ b/libraries/stdlib/wasm/stubs/testHelpers.kt @@ -8,20 +8,7 @@ package kotlin.test import kotlin.internal.InlineOnly import kotlin.internal.OnlyInputTypes -public fun assert(x: Boolean) { - if (!x) throw AssertionError("Assertion failed") -} - -/** Asserts that the [expected] value is equal to the [actual] value, with an optional [message]. */ -public fun <@OnlyInputTypes T> assertEquals(expected: T, actual: T, message: String? = null) { - if (expected != actual) throw AssertionError("assertEquals failed: expected:$expected, actual:$actual, message=$message") -} - -/** Asserts that the [actual] value is not equal to the illegal value, with an optional [message]. */ -public fun <@OnlyInputTypes T> assertNotEquals(illegal: T, actual: T, message: String? = null) { - if (illegal == actual) throw AssertionError("assertNotEquals failed: illegal:$illegal, actual:$actual, message=$message") -} - +// TODO: Remove this once we support CLASS_REFERENCE IR node @InlineOnly public inline fun assertFailsWith(message: String? = null, block: () -> Unit): T { var throwable: Throwable? = null @@ -32,5 +19,3 @@ public inline fun assertFailsWith(message: String? = nul } return throwable as? T ?: throw AssertionError("assertFailsWith failed: $message") } - -public fun assertTrue(x: Boolean) = assert(x) diff --git a/libraries/stdlib/wasm/stubs/testHelpers2.kt b/libraries/stdlib/wasm/stubs/testHelpers2.kt deleted file mode 100644 index bae3a0dbeb9..00000000000 --- a/libraries/stdlib/wasm/stubs/testHelpers2.kt +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package kotlin - -import kotlin.internal.OnlyInputTypes - -public fun assert(x: Boolean) { - if (!x) throw AssertionError("Assertion failed") -} - -/** Asserts that the [expected] value is equal to the [actual] value, with an optional [message]. */ -public fun <@OnlyInputTypes T> assertEquals(expected: T, actual: T, message: String? = null) { - if (expected != actual) throw AssertionError("assertEquals failed: expected:$expected, actual:$actual, message=$message") -} \ No newline at end of file