[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
@@ -314,11 +314,6 @@ standaloneTest("runtime_basic_init") {
|
|||||||
expectedExitStatus = 0
|
expectedExitStatus = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
standaloneTest("runtime_basic_exit") {
|
|
||||||
source = "runtime/basic/exit.kt"
|
|
||||||
expectedExitStatus = 42
|
|
||||||
}
|
|
||||||
|
|
||||||
standaloneTest('enumEquals') {
|
standaloneTest('enumEquals') {
|
||||||
useGoldenData = true
|
useGoldenData = true
|
||||||
source = "runtime/basic/enum_equals.kt"
|
source = "runtime/basic/enum_equals.kt"
|
||||||
@@ -833,70 +828,6 @@ standaloneTest("throw_from_except_constr") {
|
|||||||
source = "runtime/exceptions/throw_from_except_constr.kt"
|
source = "runtime/exceptions/throw_from_except_constr.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
standaloneTest("custom_hook") {
|
|
||||||
outputChecker = {
|
|
||||||
it.contains("value 42: Error. Runnable state: true") && it.contains("Uncaught Kotlin exception: kotlin.Error: an error")
|
|
||||||
}
|
|
||||||
expectedExitStatusChecker = { it != 0 }
|
|
||||||
source = "runtime/exceptions/custom_hook.kt"
|
|
||||||
flags = ['-opt-in=kotlin.native.internal.InternalForKotlinNative']
|
|
||||||
}
|
|
||||||
|
|
||||||
standaloneTest("custom_hook_memory_leak") {
|
|
||||||
outputChecker = {
|
|
||||||
it.contains("Hook 42") && it.contains("Uncaught Kotlin exception: kotlin.Error: an error")
|
|
||||||
}
|
|
||||||
expectedExitStatusChecker = { it != 0 }
|
|
||||||
source = "runtime/exceptions/custom_hook_memory_leak.kt"
|
|
||||||
}
|
|
||||||
|
|
||||||
standaloneTest("custom_hook_get") {
|
|
||||||
source = "runtime/exceptions/custom_hook_get.kt"
|
|
||||||
}
|
|
||||||
|
|
||||||
standaloneTest("custom_hook_no_reset") {
|
|
||||||
outputChecker = {
|
|
||||||
it.contains("Hook called") && it.contains("Uncaught Kotlin exception: kotlin.Error: some error")
|
|
||||||
}
|
|
||||||
expectedExitStatusChecker = { it != 0 }
|
|
||||||
source = "runtime/exceptions/custom_hook_no_reset.kt"
|
|
||||||
}
|
|
||||||
|
|
||||||
standaloneTest("custom_hook_throws") {
|
|
||||||
outputChecker = {
|
|
||||||
it.contains("Hook called") && it.contains("Uncaught Kotlin exception: kotlin.Error: another error") && !it.contains("some error")
|
|
||||||
}
|
|
||||||
expectedExitStatusChecker = { it != 0 }
|
|
||||||
source = "runtime/exceptions/custom_hook_throws.kt"
|
|
||||||
}
|
|
||||||
|
|
||||||
standaloneTest("custom_hook_unhandled_exception") {
|
|
||||||
useGoldenData = true
|
|
||||||
source = "runtime/exceptions/custom_hook_unhandled_exception.kt"
|
|
||||||
}
|
|
||||||
|
|
||||||
standaloneTest("custom_hook_terminate") {
|
|
||||||
outputChecker = {
|
|
||||||
it.contains("Hook called")
|
|
||||||
}
|
|
||||||
expectedExitStatusChecker = { it != 0 }
|
|
||||||
source = "runtime/exceptions/custom_hook_terminate.kt"
|
|
||||||
}
|
|
||||||
|
|
||||||
standaloneTest("custom_hook_terminate_unhandled_exception") {
|
|
||||||
outputChecker = {
|
|
||||||
it.contains("Hook called") && it.contains("Uncaught Kotlin exception: kotlin.Error: some error") && !it.contains("Not going to happen")
|
|
||||||
}
|
|
||||||
expectedExitStatusChecker = { it != 0 }
|
|
||||||
source = "runtime/exceptions/custom_hook_terminate_unhandled_exception.kt"
|
|
||||||
}
|
|
||||||
|
|
||||||
standaloneTest("exception_in_global_init") {
|
|
||||||
source = "runtime/exceptions/exception_in_global_init.kt"
|
|
||||||
expectedExitStatusChecker = { it != 0 }
|
|
||||||
outputChecker = { s -> s.contains("Uncaught Kotlin exception:") && s.contains("FAIL") && !s.contains("in kotlin main") }
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.register("rethrow_exception", KonanLocalTest) {
|
tasks.register("rethrow_exception", KonanLocalTest) {
|
||||||
source = "runtime/exceptions/rethrow.kt"
|
source = "runtime/exceptions/rethrow.kt"
|
||||||
}
|
}
|
||||||
@@ -905,42 +836,6 @@ tasks.register("throw_from_catch", KonanLocalTest) {
|
|||||||
source = "runtime/exceptions/throw_from_catch.kt"
|
source = "runtime/exceptions/throw_from_catch.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
standaloneTest("terminate") {
|
|
||||||
expectedExitStatusChecker = { it != 0 }
|
|
||||||
source = "runtime/exceptions/terminate.kt"
|
|
||||||
}
|
|
||||||
|
|
||||||
standaloneTest("unhandled_exception") {
|
|
||||||
outputChecker = {
|
|
||||||
it.contains("Uncaught Kotlin exception: kotlin.Error: some error")
|
|
||||||
}
|
|
||||||
expectedExitStatusChecker = { it != 0 }
|
|
||||||
source = "runtime/exceptions/unhandled_exception.kt"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
tasks.register("main_exception", KonanLocalTest) {
|
|
||||||
outputChecker = { s -> s.contains("kotlin.Error: Hello!") }
|
|
||||||
expectedExitStatus = 1
|
|
||||||
source = "runtime/basic/main_exception.kt"
|
|
||||||
}
|
|
||||||
|
|
||||||
standaloneTest("runtime_basic_assert_failed") {
|
|
||||||
expectedExitStatusChecker = { it != 0 }
|
|
||||||
source = "runtime/basic/assert_failed.kt"
|
|
||||||
}
|
|
||||||
|
|
||||||
standaloneTest("runtime_basic_assert_passed") {
|
|
||||||
expectedExitStatus = 0
|
|
||||||
source = "runtime/basic/assert_passed.kt"
|
|
||||||
}
|
|
||||||
|
|
||||||
standaloneTest("runtime_basic_assert_disabled") {
|
|
||||||
expectedExitStatus = 0
|
|
||||||
enableKonanAssertions = false
|
|
||||||
source = "runtime/basic/assert_failed.kt"
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.register("initializers0", KonanLocalTest) {
|
tasks.register("initializers0", KonanLocalTest) {
|
||||||
useGoldenData = true
|
useGoldenData = true
|
||||||
source = "runtime/basic/initializers0.kt"
|
source = "runtime/basic/initializers0.kt"
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
|
||||||
assert(false)
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
|
||||||
assert(true)
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import kotlin.system.*
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
|
||||||
exitProcess(42)
|
|
||||||
@Suppress("UNREACHABLE_CODE")
|
|
||||||
throw RuntimeException("Exit function call returned normally")
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package runtime.basic.main_exception
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
@Test fun runTest() {
|
|
||||||
throw Error("Hello!")
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class, kotlin.native.runtime.NativeRuntimeApi::class)
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
import kotlin.native.concurrent.*
|
|
||||||
import kotlin.native.internal.*
|
|
||||||
import kotlin.native.runtime.Debugging
|
|
||||||
|
|
||||||
fun mainLegacyMM() {
|
|
||||||
val wrong = "wrong"
|
|
||||||
assertFailsWith<InvalidMutabilityException> {
|
|
||||||
setUnhandledExceptionHook { _ -> println(wrong) }
|
|
||||||
}
|
|
||||||
|
|
||||||
val x = 42
|
|
||||||
val old = setUnhandledExceptionHook({ throwable: Throwable ->
|
|
||||||
println("value $x: ${throwable::class.simpleName}. Runnable state: ${Debugging.isThreadStateRunnable}")
|
|
||||||
}.freeze())
|
|
||||||
|
|
||||||
assertNull(old)
|
|
||||||
|
|
||||||
throw Error("an error")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mainExperimentalMM() {
|
|
||||||
val unset = setUnhandledExceptionHook { _ -> println("ok") }
|
|
||||||
assertNull(unset)
|
|
||||||
|
|
||||||
val x = 42
|
|
||||||
val old = setUnhandledExceptionHook { throwable: Throwable ->
|
|
||||||
println("value $x: ${throwable::class.simpleName}. Runnable state: ${Debugging.isThreadStateRunnable}")
|
|
||||||
}
|
|
||||||
|
|
||||||
assertNotNull(old)
|
|
||||||
|
|
||||||
throw Error("an error")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
if (Platform.memoryModel == MemoryModel.EXPERIMENTAL) {
|
|
||||||
mainExperimentalMM()
|
|
||||||
} else {
|
|
||||||
mainLegacyMM()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class)
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
import kotlin.native.concurrent.*
|
|
||||||
|
|
||||||
data class C(val x: Int)
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
Platform.isMemoryLeakCheckerActive = true
|
|
||||||
|
|
||||||
val c = C(42)
|
|
||||||
setUnhandledExceptionHook({ _: Throwable ->
|
|
||||||
println("Hook ${c.x}")
|
|
||||||
}.freeze())
|
|
||||||
|
|
||||||
throw Error("an error")
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, FreezingIsDeprecated::class)
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
import kotlin.native.concurrent.*
|
|
||||||
|
|
||||||
fun customExceptionHook(throwable: Throwable) {
|
|
||||||
println("Hook called")
|
|
||||||
assertEquals(::customExceptionHook, getUnhandledExceptionHook())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
setUnhandledExceptionHook((::customExceptionHook).freeze())
|
|
||||||
|
|
||||||
throw Error("some error")
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, FreezingIsDeprecated::class)
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
import kotlin.native.concurrent.*
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
setUnhandledExceptionHook({ t: Throwable ->
|
|
||||||
println("Hook called")
|
|
||||||
terminateWithUnhandledException(t)
|
|
||||||
}.freeze())
|
|
||||||
|
|
||||||
throw Error("some error")
|
|
||||||
}
|
|
||||||
-20
@@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, FreezingIsDeprecated::class)
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
import kotlin.native.concurrent.*
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
setUnhandledExceptionHook({ t: Throwable ->
|
|
||||||
println("Hook called")
|
|
||||||
terminateWithUnhandledException(t)
|
|
||||||
}.freeze())
|
|
||||||
|
|
||||||
val exception = Error("some error")
|
|
||||||
processUnhandledException(exception)
|
|
||||||
println("Not going to happen")
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class)
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
import kotlin.native.concurrent.*
|
|
||||||
|
|
||||||
fun customExceptionHook(throwable: Throwable) {
|
|
||||||
println("Hook called")
|
|
||||||
throw Error("another error")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
setUnhandledExceptionHook((::customExceptionHook).freeze())
|
|
||||||
|
|
||||||
throw Error("some error")
|
|
||||||
}
|
|
||||||
-20
@@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, FreezingIsDeprecated::class)
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
import kotlin.concurrent.AtomicInt
|
|
||||||
import kotlin.native.concurrent.*
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val called = AtomicInt(0)
|
|
||||||
setUnhandledExceptionHook({ _: Throwable ->
|
|
||||||
called.value = 1
|
|
||||||
}.freeze())
|
|
||||||
|
|
||||||
val exception = Error("some error")
|
|
||||||
processUnhandledException(exception)
|
|
||||||
assertEquals(1, called.value)
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
val p: Nothing = error("FAIL")
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
println("in kotlin main")
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val exception = Error("some error")
|
|
||||||
terminateWithUnhandledException(exception)
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
val exception = Error("some error")
|
|
||||||
processUnhandledException(exception)
|
|
||||||
}
|
|
||||||
@@ -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")
|
||||||
|
}
|
||||||
+4
-11
@@ -1,17 +1,10 @@
|
|||||||
/*
|
// No termination is going on here. But that's the closest location to other unhandled exception hook tests.
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||||
* that can be found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class, FreezingIsDeprecated::class)
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
import kotlin.native.concurrent.*
|
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val exceptionHook = { _: Throwable ->
|
val exceptionHook = { _: Throwable -> Unit }
|
||||||
println("Hook")
|
|
||||||
}.freeze()
|
|
||||||
|
|
||||||
val oldHook = setUnhandledExceptionHook(exceptionHook)
|
val oldHook = setUnhandledExceptionHook(exceptionHook)
|
||||||
assertNull(oldHook)
|
assertNull(oldHook)
|
||||||
@@ -23,4 +16,4 @@ fun main() {
|
|||||||
assertEquals(exceptionHook, hook3)
|
assertEquals(exceptionHook, hook3)
|
||||||
val hook4 = getUnhandledExceptionHook()
|
val hook4 = getUnhandledExceptionHook()
|
||||||
assertNull(hook4)
|
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)
|
||||||
|
}
|
||||||
+99
@@ -141,4 +141,103 @@ public class FirNativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest
|
|||||||
runTest("native/native.tests/testData/standalone/entryPoint/mainOverloadingNoArgs.kt");
|
runTest("native/native.tests/testData/standalone/entryPoint/mainOverloadingNoArgs.kt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@TestMetadata("native/native.tests/testData/standalone/termination")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@Tag("standalone")
|
||||||
|
@EnforcedProperty(property = ClassLevelProperty.TEST_KIND, propertyValue = "STANDALONE_NO_TR")
|
||||||
|
@UseStandardTestCaseGroupProvider()
|
||||||
|
@Tag("frontend-fir")
|
||||||
|
@FirPipeline()
|
||||||
|
public class Termination {
|
||||||
|
@Test
|
||||||
|
public void testAllFilesPresentInTermination() throws Exception {
|
||||||
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone/termination"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("assertFailed.kt")
|
||||||
|
public void testAssertFailed() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/assertFailed.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("assertPassed.kt")
|
||||||
|
public void testAssertPassed() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/assertPassed.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("exitProcess.kt")
|
||||||
|
public void testExitProcess() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/exitProcess.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("globalThrow.kt")
|
||||||
|
public void testGlobalThrow() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/globalThrow.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("mainThrow.kt")
|
||||||
|
public void testMainThrow() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/mainThrow.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("processUnhandledException.kt")
|
||||||
|
public void testProcessUnhandledException() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/processUnhandledException.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("terminateWithUnhandledException.kt")
|
||||||
|
public void testTerminateWithUnhandledException() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/terminateWithUnhandledException.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookClosure.kt")
|
||||||
|
public void testUnhandledExceptionHookClosure() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookClosure.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookFun.kt")
|
||||||
|
public void testUnhandledExceptionHookFun() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookFun.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookGet.kt")
|
||||||
|
public void testUnhandledExceptionHookGet() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookGet.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookTerminate.kt")
|
||||||
|
public void testUnhandledExceptionHookTerminate() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookTerminate.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookTerminateWithProcess.kt")
|
||||||
|
public void testUnhandledExceptionHookTerminateWithProcess() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookTerminateWithProcess.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookThrow.kt")
|
||||||
|
public void testUnhandledExceptionHookThrow() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookThrow.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookWithProcess.kt")
|
||||||
|
public void testUnhandledExceptionHookWithProcess() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookWithProcess.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+97
@@ -134,4 +134,101 @@ public class NativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest {
|
|||||||
runTest("native/native.tests/testData/standalone/entryPoint/mainOverloadingNoArgs.kt");
|
runTest("native/native.tests/testData/standalone/entryPoint/mainOverloadingNoArgs.kt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@TestMetadata("native/native.tests/testData/standalone/termination")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@Tag("standalone")
|
||||||
|
@EnforcedProperty(property = ClassLevelProperty.TEST_KIND, propertyValue = "STANDALONE_NO_TR")
|
||||||
|
@UseStandardTestCaseGroupProvider()
|
||||||
|
public class Termination {
|
||||||
|
@Test
|
||||||
|
public void testAllFilesPresentInTermination() throws Exception {
|
||||||
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone/termination"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("assertFailed.kt")
|
||||||
|
public void testAssertFailed() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/assertFailed.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("assertPassed.kt")
|
||||||
|
public void testAssertPassed() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/assertPassed.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("exitProcess.kt")
|
||||||
|
public void testExitProcess() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/exitProcess.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("globalThrow.kt")
|
||||||
|
public void testGlobalThrow() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/globalThrow.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("mainThrow.kt")
|
||||||
|
public void testMainThrow() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/mainThrow.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("processUnhandledException.kt")
|
||||||
|
public void testProcessUnhandledException() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/processUnhandledException.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("terminateWithUnhandledException.kt")
|
||||||
|
public void testTerminateWithUnhandledException() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/terminateWithUnhandledException.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookClosure.kt")
|
||||||
|
public void testUnhandledExceptionHookClosure() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookClosure.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookFun.kt")
|
||||||
|
public void testUnhandledExceptionHookFun() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookFun.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookGet.kt")
|
||||||
|
public void testUnhandledExceptionHookGet() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookGet.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookTerminate.kt")
|
||||||
|
public void testUnhandledExceptionHookTerminate() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookTerminate.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookTerminateWithProcess.kt")
|
||||||
|
public void testUnhandledExceptionHookTerminateWithProcess() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookTerminateWithProcess.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookThrow.kt")
|
||||||
|
public void testUnhandledExceptionHookThrow() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookThrow.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unhandledExceptionHookWithProcess.kt")
|
||||||
|
public void testUnhandledExceptionHookWithProcess() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/standalone/termination/unhandledExceptionHookWithProcess.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user