44 lines
1.3 KiB
Kotlin
44 lines
1.3 KiB
Kotlin
// Checks that on Apple targets first two lines of exception stacktrace of symbolized executable looks like
|
|
// "\tat 1 main.kexe\t\t 0x000000010d7cdb4c kfun:package.function(kotlin.Int) + 108 (/path/to/file/name.kt:10:27)\n"
|
|
// If test is broken, org.jetbrains.kotlin.idea.filters.KotlinExceptionFilter (in main Kotlin repo) should be updated.
|
|
|
|
import kotlin.test.*
|
|
import kotlin.text.Regex
|
|
|
|
val EXTENSION = ".kt:"
|
|
val LOCATION_PATTERN = Regex("\\d+:\\d+")
|
|
|
|
fun checkStringFormat(s: String) {
|
|
val trimmed = s.trim()
|
|
|
|
assertTrue(trimmed.endsWith(')'), "Line is not ended with ')'")
|
|
assertNotEquals(trimmed.indexOf('('), -1, "No '(' before filename")
|
|
|
|
val fileName = trimmed.substring(trimmed.lastIndexOf('(') + 1, trimmed.lastIndex)
|
|
assertNotEquals(fileName.indexOf(EXTENSION), -1, "Filename 'kt' extension is absent")
|
|
|
|
val location = fileName.substring(fileName.indexOf(EXTENSION) + EXTENSION.length)
|
|
assertTrue(LOCATION_PATTERN.matches(location), "Expected location of form 12:8")
|
|
}
|
|
|
|
fun functionA() {
|
|
throw Error("an error")
|
|
}
|
|
|
|
fun functionB() {
|
|
functionA()
|
|
}
|
|
|
|
fun main(args : Array<String>) {
|
|
try {
|
|
functionB()
|
|
} catch (e: Throwable) {
|
|
val stacktrace = e.getStackTrace()
|
|
if (stacktrace.size >= 3) {
|
|
repeat(3) {
|
|
checkStringFormat(stacktrace[it])
|
|
}
|
|
}
|
|
}
|
|
}
|