[K/N] Support stacktrace using libbacktrace

This commit is contained in:
Pavel Kunyavskiy
2021-09-14 11:09:36 +03:00
committed by Space
parent 4fa5be3e58
commit c704fd6ae7
21 changed files with 350 additions and 123 deletions
@@ -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())
}