Add more tests for -Xassertions=jvm corner cases

This commit is contained in:
Steven Schäfer
2019-07-05 15:24:54 +02:00
committed by max-kammerer
parent 3e25166832
commit d11344ce2e
15 changed files with 491 additions and 1 deletions
@@ -0,0 +1,54 @@
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm
// WITH_RUNTIME
// Assertions which run before the class initializer are always checked
package initializerAssertionsEnabled
class Checker {
fun test() = Baz.testAsserts()
}
open class Bar {
companion object {
val barAssertionThrown = try {
Baz().assertFalse()
false
} catch(error: java.lang.AssertionError) {
true
}
}
}
class Baz : Bar() {
fun assertFalse() = assert(false)
companion object {
val bazAssertionThrown = try {
Baz().assertFalse()
false
} catch(error: java.lang.AssertionError) {
true
}
fun testAsserts(): String {
if (!barAssertionThrown) return "Fail 1"
if (bazAssertionThrown) return "Fail 2"
return "OK"
}
}
}
class Dummy
fun disableAssertions(): Checker {
val loader = Dummy::class.java.classLoader
loader.setPackageAssertionStatus("initializerAssertionsEnabled", false)
return loader.loadClass("initializerAssertionsEnabled.Checker").newInstance() as Checker
}
fun box(): String {
return disableAssertions().test()
}