Add checker for stack trace format

KT-29817
Reviewed at KN-CR-1563
This commit is contained in:
Kirill Shmakov
2019-02-20 13:37:31 +03:00
parent e97ff3a1fc
commit 7254d44921
2 changed files with 47 additions and 0 deletions
+6
View File
@@ -2036,6 +2036,12 @@ task extend_exception(type: RunKonanTest) {
source = "runtime/exceptions/extend0.kt"
}
task check_stacktrace_format(type: RunStandaloneKonanTest) {
disabled = !isAppleTarget(project)
flags = ['-g']
source = "runtime/exceptions/check_stacktrace_format.kt"
}
task custom_hook(type: RunStandaloneKonanTest) {
disabled = (project.testTarget == 'wasm32') // Uses exceptions.
goldValue = "value 42: Error\n"
@@ -0,0 +1,41 @@
// 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 st = e.getStackTrace()
repeat(3) {
checkStringFormat(st[it])
}
}
}