[K/N] Support stacktrace using libbacktrace
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
import kotlin.text.Regex
|
||||
import kotlin.test.*
|
||||
|
||||
var inlinesCount = 0
|
||||
|
||||
fun main() {
|
||||
try {
|
||||
foo()
|
||||
} catch (tw:Throwable) {
|
||||
val stackTrace = tw.getStackTrace()
|
||||
val stackTrace = tw.getStackTrace();
|
||||
inlinesCount = stackTrace.count { it.contains("[inlined]")}
|
||||
stackTrace.take(6).forEach(::checkFrame)
|
||||
}
|
||||
println(inlinesCount)
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
@@ -25,17 +29,22 @@ fun throwException() {
|
||||
throw Error()
|
||||
}
|
||||
internal val regex = Regex("^(\\d+)\\ +.*/(.*):(\\d+):.*$")
|
||||
internal val goldValues = arrayOf<Pair<String, Int>?>(
|
||||
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 goldValues = arrayOf<Pair<String, Int>?>(
|
||||
null,
|
||||
null,
|
||||
"kt-37572.kt" to 29,
|
||||
"kt-37572.kt" to 20,
|
||||
*(if (inlinesCount != 0) arrayOf(
|
||||
"kt-37572.kt" to 25,
|
||||
"kt-37572.kt" to 18,
|
||||
) else emptyArray()),
|
||||
"kt-37572.kt" to 8,
|
||||
"kt-37572.kt" to 6)
|
||||
|
||||
val (pos, file, line) = regex.find(value)!!.destructured
|
||||
goldValues[pos.toInt()]?.let{
|
||||
goldValues[pos.toInt()]?.let {
|
||||
assertEquals(it.first, file)
|
||||
assertEquals(it.second, line.toInt())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import kotlin.text.Regex
|
||||
import kotlin.test.*
|
||||
|
||||
var inlinesCount = 0
|
||||
|
||||
fun exception() {
|
||||
error("FAIL!")
|
||||
}
|
||||
@@ -11,20 +13,23 @@ fun main() {
|
||||
}
|
||||
catch (e:Exception) {
|
||||
val stackTrace = e.getStackTrace()
|
||||
inlinesCount = stackTrace.count { it.contains("[inlined]")}
|
||||
stackTrace.take(6).forEach(::checkFrame)
|
||||
}
|
||||
println(inlinesCount)
|
||||
}
|
||||
internal val regex = Regex("^(\\d+)\\ +.*/(.*):(\\d+):.*$")
|
||||
internal val goldValues = arrayOf<Pair<String, Int>?>(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
"stack_trace_inline.kt" to 5,
|
||||
"stack_trace_inline.kt" to 10)
|
||||
internal fun checkFrame(value:String) {
|
||||
val goldValues = arrayOf<Pair<String, Int>?>(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
*(if (inlinesCount != 0) arrayOf(null) else emptyArray()),
|
||||
"stack_trace_inline.kt" to 7,
|
||||
"stack_trace_inline.kt" to 12)
|
||||
val (pos, file, line) = regex.find(value)!!.destructured
|
||||
goldValues[pos.toInt()]?.let{
|
||||
goldValues[pos.toInt()]?.let {
|
||||
assertEquals(it.first, file)
|
||||
assertEquals(it.second, line.toInt())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user