Minor. Use more granular assertion levels in assertion tests

This commit is contained in:
Ilmir Usmanov
2018-08-06 17:11:32 +03:00
parent 1a1bb53381
commit b4189d9e85
18 changed files with 74 additions and 46 deletions
@@ -1,6 +1,8 @@
// FILE: inline.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
// WITH_RUNTIME
// FULL_JDK
// IGNORE_BACKEND: JVM_IR
inline fun inlineMe() {
assert(false) { "FROM INLINED" }
@@ -9,7 +11,7 @@ inline fun inlineMe() {
// FILE: inlineSite.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
class Checker {
class CheckerJvmAssertInlineFunctionAssertionsDisabled {
fun check() {
inlineMe()
assert(false) { "FROM INLINESITE" }
@@ -18,16 +20,16 @@ class Checker {
class Dummy
fun disableAssertions(): Checker {
fun disableAssertions(): CheckerJvmAssertInlineFunctionAssertionsDisabled {
val loader = Dummy::class.java.classLoader
loader.setDefaultAssertionStatus(false)
val c = loader.loadClass("Checker")
return c.newInstance() as Checker
loader.setClassAssertionStatus("CheckerJvmAssertInlineFunctionAssertionsDisabled", false)
loader.setClassAssertionStatus("InlineKt", false)
val c = loader.loadClass("CheckerJvmAssertInlineFunctionAssertionsDisabled")
return c.newInstance() as CheckerJvmAssertInlineFunctionAssertionsDisabled
}
fun box(): String {
var c = disableAssertions()
c.check()
return "OK"
}
@@ -1,7 +1,7 @@
// IGNORE_BACKEND: JVM_IR
// FILE: inline.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
// WITH_RUNTIME
// FULL_JDK
inline fun inlineMe() {
assert(false) { "FROM INLINED" }
@@ -10,7 +10,7 @@ inline fun inlineMe() {
// FILE: inlineSite.kt
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
class Checker {
class CheckerJvmAssertInlineFunctionAssertionsEnabled {
fun check() {
inlineMe()
throw RuntimeException("FAIL 0")
@@ -19,11 +19,11 @@ class Checker {
class Dummy
fun enableAssertions(): Checker {
fun enableAssertions(): CheckerJvmAssertInlineFunctionAssertionsEnabled {
val loader = Dummy::class.java.classLoader
loader.setDefaultAssertionStatus(true)
val c = loader.loadClass("Checker")
return c.newInstance() as Checker
loader.setClassAssertionStatus("CheckerJvmAssertInlineFunctionAssertionsEnabled", true)
val c = loader.loadClass("CheckerJvmAssertInlineFunctionAssertionsEnabled")
return c.newInstance() as CheckerJvmAssertInlineFunctionAssertionsEnabled
}
fun box(): String {
@@ -32,6 +32,5 @@ fun box(): String {
c.check()
return "FAIL 2"
} catch (ignore: AssertionError) {}
return "OK"
}
@@ -96,7 +96,8 @@ class ShouldBeEnabled : Checker {
fun setDesiredAssertionStatus(v: Boolean): Checker {
val loader = Checker::class.java.classLoader
loader.setDefaultAssertionStatus(v)
loader.setClassAssertionStatus("ShouldBeEnabled", true)
loader.setClassAssertionStatus("ShouldBeDisabled", false)
val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled")
return c.newInstance() as Checker
}
@@ -120,6 +121,5 @@ fun box(): String {
return "FAIL 7"
} catch (ignore: AssertionError) {
}
return "OK"
}
@@ -97,7 +97,8 @@ class ShouldBeEnabled : Checker {
fun setDesiredAssertionStatus(v: Boolean): Checker {
val loader = Checker::class.java.classLoader
loader.setDefaultAssertionStatus(v)
loader.setClassAssertionStatus("ShouldBeEnabled", true)
loader.setClassAssertionStatus("ShouldBeDisabled", false)
val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled")
return c.newInstance() as Checker
}