[K/N][tests] Migrate termination runtime tests to new testing infra ^KT-61259
This commit is contained in:
committed by
Space Team
parent
226ee3c367
commit
04a2a2d90d
@@ -0,0 +1,8 @@
|
||||
// EXIT_CODE: !0
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
// TODO: Test running this test with disabled assertions. This requires removing always-enabled
|
||||
// -enable-assertions from `BasicCompilation`.
|
||||
fun main() {
|
||||
assert(false)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
fun main() {
|
||||
assert(true)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// EXIT_CODE: 42
|
||||
// OUTPUT_DATA_FILE: exitProcess.out
|
||||
|
||||
import kotlin.system.*
|
||||
|
||||
fun main() {
|
||||
print("OK")
|
||||
exitProcess(42)
|
||||
println("FAIL")
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1,8 @@
|
||||
// EXIT_CODE: !0
|
||||
// OUTPUT_REGEX: Uncaught Kotlin exception: kotlin\.Error: an error\n(?!.*FAIL.*).*
|
||||
|
||||
val p: Nothing = throw Error("an error")
|
||||
|
||||
fun main() {
|
||||
println("FAIL")
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// EXIT_CODE: !0
|
||||
// OUTPUT_REGEX: Uncaught Kotlin exception: kotlin\.Error: an error\n.*
|
||||
|
||||
fun main() {
|
||||
throw Error("an error")
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// EXIT_CODE: !0
|
||||
// OUTPUT_REGEX: Uncaught Kotlin exception: kotlin\.Error: an error\n.*
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
fun main() {
|
||||
processUnhandledException(Error("an error"))
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// EXIT_CODE: !0
|
||||
// OUTPUT_REGEX: Uncaught Kotlin exception: kotlin\.Error: an error\n.*
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
fun main() {
|
||||
terminateWithUnhandledException(Error("an error"))
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// EXIT_CODE: !0
|
||||
// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative
|
||||
// OUTPUT_REGEX: value 42: Error\. Runnable state: true\nUncaught Kotlin exception: kotlin\.Error: an error\n.*
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
|
||||
|
||||
import kotlin.native.runtime.Debugging
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
val x = 42
|
||||
setUnhandledExceptionHook { throwable: Throwable ->
|
||||
println("value $x: ${throwable::class.simpleName}. Runnable state: ${Debugging.isThreadStateRunnable}")
|
||||
}
|
||||
|
||||
throw Error("an error")
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// EXIT_CODE: !0
|
||||
// FREE_COMPILER_ARGS: -opt-in=kotlin.native.internal.InternalForKotlinNative
|
||||
// OUTPUT_REGEX: value true: Error\. Runnable state: true\nUncaught Kotlin exception: kotlin\.Error: an error\n.*
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
|
||||
|
||||
import kotlin.native.runtime.Debugging
|
||||
import kotlin.test.*
|
||||
|
||||
fun customExceptionHook(throwable: Throwable) {
|
||||
println("value ${getUnhandledExceptionHook() == ::customExceptionHook}: ${throwable::class.simpleName}. Runnable state: ${Debugging.isThreadStateRunnable}")
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val x = 42
|
||||
setUnhandledExceptionHook(::customExceptionHook)
|
||||
|
||||
throw Error("an error")
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// No termination is going on here. But that's the closest location to other unhandled exception hook tests.
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
val exceptionHook = { _: Throwable -> Unit }
|
||||
|
||||
val oldHook = setUnhandledExceptionHook(exceptionHook)
|
||||
assertNull(oldHook)
|
||||
val hook1 = getUnhandledExceptionHook()
|
||||
assertEquals(exceptionHook, hook1)
|
||||
val hook2 = getUnhandledExceptionHook()
|
||||
assertEquals(exceptionHook, hook2)
|
||||
val hook3 = setUnhandledExceptionHook(null)
|
||||
assertEquals(exceptionHook, hook3)
|
||||
val hook4 = getUnhandledExceptionHook()
|
||||
assertNull(hook4)
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// EXIT_CODE: !0
|
||||
// OUTPUT_REGEX: Hook\nUncaught Kotlin exception: kotlin\.Error: an error\n.*
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
setUnhandledExceptionHook {
|
||||
println("Hook")
|
||||
terminateWithUnhandledException(it)
|
||||
}
|
||||
|
||||
throw Error("an error")
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// EXIT_CODE: !0
|
||||
// OUTPUT_REGEX: Hook\nUncaught Kotlin exception: kotlin\.Error: an error\n(?!.*FAIL.*).*
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
setUnhandledExceptionHook {
|
||||
println("Hook")
|
||||
terminateWithUnhandledException(it)
|
||||
}
|
||||
|
||||
processUnhandledException(Error("an error"))
|
||||
println("FAIL")
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// EXIT_CODE: !0
|
||||
// OUTPUT_REGEX: Hook\nUncaught Kotlin exception: kotlin\.Error: another error\n(?!.*an error.*).*
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
setUnhandledExceptionHook {
|
||||
println("Hook")
|
||||
throw Error("another error")
|
||||
}
|
||||
|
||||
throw Error("an error")
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// No termination is going on here. But that's the closest location to other unhandled exception hook tests.
|
||||
// OUTPUT_DATA_FILE: unhandledExceptionHookWithProcess.out
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.concurrent.AtomicInt
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
val exception = Error("an error")
|
||||
val called = AtomicInt(0)
|
||||
setUnhandledExceptionHook {
|
||||
assertSame(exception, it)
|
||||
called.value = 1
|
||||
}
|
||||
|
||||
processUnhandledException(exception)
|
||||
assertEquals(1, called.value)
|
||||
}
|
||||
Reference in New Issue
Block a user