From 627904d46954fa65560b5eec0c9b1052cd7f424b Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Thu, 16 Apr 2020 15:58:05 +0200 Subject: [PATCH] [test][stacktrace][mac] added two test for stack trace validation --- backend.native/tests/build.gradle | 12 ++++++ .../tests/runtime/exceptions/kt-37572.kt | 42 +++++++++++++++++++ .../runtime/exceptions/stack_trace_inline.kt | 31 ++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 backend.native/tests/runtime/exceptions/kt-37572.kt create mode 100644 backend.native/tests/runtime/exceptions/stack_trace_inline.kt diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 327bf3ae376..d4a65c8ed50 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -2325,6 +2325,18 @@ standaloneTest("check_stacktrace_format") { source = "runtime/exceptions/check_stacktrace_format.kt" } +standaloneTest("stack_trace_inline") { + disabled = !isAppleTarget(project) || project.globalTestArgs.contains('-opt') || (project.testTarget == 'ios_arm64') + flags = ['-g'] + source = "runtime/exceptions/stack_trace_inline.kt" +} + +standaloneTest("kt-37572") { + disabled = !isAppleTarget(project) || project.globalTestArgs.contains('-opt') || (project.testTarget == 'ios_arm64') + flags = ['-g'] + source = "runtime/exceptions/kt-37572.kt" +} + standaloneTest("custom_hook") { enabled = (project.testTarget != 'wasm32') // Uses exceptions. goldValue = "value 42: Error\n" diff --git a/backend.native/tests/runtime/exceptions/kt-37572.kt b/backend.native/tests/runtime/exceptions/kt-37572.kt new file mode 100644 index 00000000000..eee281de776 --- /dev/null +++ b/backend.native/tests/runtime/exceptions/kt-37572.kt @@ -0,0 +1,42 @@ +import kotlin.text.Regex +import kotlin.test.* + +fun main() { + try { + foo() + } catch (tw:Throwable) { + val stackTrace = tw.getStackTrace() + stackTrace.take(6).forEach(::checkFrame) + } +} + +fun foo() { + myRun { + //platform.darwin.NSObject() + throwException() + } +} + +inline fun myRun(block: () -> Unit) { + block() +} + +fun throwException() { + throw Error() +} +internal val regex = Regex("^(\\d+)\\ +.*/(.*):(\\d+):.*$") +internal val goldValues = arrayOf?>( + null, + null, + "kt-37572.kt" to 25, + "kt-37572.kt" to 16, + "kt-37572.kt" to 6, + "kt-37572.kt" to 4) + +internal fun checkFrame(value:String) { + val (pos, file, line) = regex.find(value)!!.destructured + goldValues[pos.toInt()]?.let{ + assertEquals(it.first, file) + assertEquals(it.second, line.toInt()) + } +} \ No newline at end of file diff --git a/backend.native/tests/runtime/exceptions/stack_trace_inline.kt b/backend.native/tests/runtime/exceptions/stack_trace_inline.kt new file mode 100644 index 00000000000..6b4514726cc --- /dev/null +++ b/backend.native/tests/runtime/exceptions/stack_trace_inline.kt @@ -0,0 +1,31 @@ +import kotlin.text.Regex +import kotlin.test.* + +fun exception() { + error("FAIL!") +} + +fun main() { + try { + exception() + } + catch (e:Exception) { + val stackTrace = e.getStackTrace() + stackTrace.take(6).forEach(::checkFrame) + } +} +internal val regex = Regex("^(\\d+)\\ +.*/(.*):(\\d+):.*$") +internal val goldValues = arrayOf?>( + null, + null, + null, + null, + "stack_trace_inline.kt" to 5, + "stack_trace_inline.kt" to 10) +internal fun checkFrame(value:String) { + val (pos, file, line) = regex.find(value)!!.destructured + goldValues[pos.toInt()]?.let{ + assertEquals(it.first, file) + assertEquals(it.second, line.toInt()) + } +} \ No newline at end of file