Files
kotlin-fork/compiler/testData/codegen/box/assert/alwaysEnable.kt
T
Svyatoslav Kuzmich abf70a586c [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>
2023-02-02 07:06:12 +00:00

52 lines
995 B
Kotlin
Vendored

// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS_IR
// IGNORE_BACKEND: JS_IR_ES6
// IGNORE_BACKEND: JS
// ASSERTIONS_MODE: always-enable
// WITH_STDLIB
fun checkTrue(): Boolean {
var hit = false
val l = { hit = true; true }
assert(l())
return hit
}
fun checkTrueWithMessage(): Boolean {
var hit = false
val l = { hit = true; true }
assert(l()) { "BOOYA!" }
return hit
}
fun checkFalse(): Boolean {
var hit = false
val l = { hit = true; false }
assert(l())
return hit
}
fun checkFalseWithMessage(): Boolean {
var hit = false
val l = { hit = true; false }
assert(l()) { "BOOYA!" }
return hit
}
fun box(): String {
if (!checkTrue()) return "FAIL 0"
if (!checkTrueWithMessage()) return "FAIL 1"
try {
checkFalse()
return "FAIL 3"
} catch (ignore: AssertionError) {
}
try {
checkFalseWithMessage()
return "FAIL 4"
} catch (ignore: AssertionError) {
}
return "OK"
}