Skip to content

Commit 4f53203

Browse files
committed
Remove code that deals with backspaces
1 parent 711d1e7 commit 4f53203

File tree

2 files changed

+4
-35
lines changed

2 files changed

+4
-35
lines changed

kotlinx-coroutines-core/jvm/test/exceptions/Stacktraces.kt

+1-16
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,10 @@ public fun toStackTrace(t: Throwable): String {
3333
}
3434

3535
public fun String.normalizeStackTrace(): String =
36-
applyBackspace()
37-
.replace(Regex(":[0-9]+"), "") // remove line numbers
36+
replace(Regex(":[0-9]+"), "") // remove line numbers
3837
.replace("kotlinx_coroutines_core_main", "") // yay source sets
3938
.replace("kotlinx_coroutines_core", "")
4039
.replace(Regex("@[0-9a-f]+"), "") // remove hex addresses in debug toStrings
4140
.lines().joinToString("\n") // normalize line separators
4241

43-
public fun String.applyBackspace(): String {
44-
val array = toCharArray()
45-
val stack = CharArray(array.size)
46-
var stackSize = -1
47-
for (c in array) {
48-
if (c != '\b') {
49-
stack[++stackSize] = c
50-
} else {
51-
--stackSize
52-
}
53-
}
54-
return String(stack, 0, stackSize)
55-
}
56-
5742
public fun String.count(substring: String): Int = split(substring).size - 1

kotlinx-coroutines-debug/test/StacktraceUtils.kt

+3-19
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,6 @@ public fun String.trimStackTrace(): String =
1414
.replace(Regex("(?<=\tat )[^\n]*/"), "")
1515
.replace(Regex("\t"), "")
1616
.replace("sun.misc.Unsafe.", "jdk.internal.misc.Unsafe.") // JDK8->JDK11
17-
.applyBackspace()
18-
19-
public fun String.applyBackspace(): String {
20-
val array = toCharArray()
21-
val stack = CharArray(array.size)
22-
var stackSize = -1
23-
for (c in array) {
24-
if (c != '\b') {
25-
stack[++stackSize] = c
26-
} else {
27-
--stackSize
28-
}
29-
}
30-
31-
return String(stack, 0, stackSize + 1)
32-
}
3317

3418
public fun verifyStackTrace(e: Throwable, traces: List<String>) {
3519
val stacktrace = toStackTrace(e)
@@ -74,7 +58,7 @@ public fun verifyDump(vararg traces: String, ignoredCoroutine: String? = null, f
7458
* `$$BlockHound$$_` prepended at the last component.
7559
*/
7660
private fun cleanBlockHoundTraces(frames: List<String>): List<String> {
77-
var result = mutableListOf<String>()
61+
val result = mutableListOf<String>()
7862
val blockHoundSubstr = "\$\$BlockHound\$\$_"
7963
var i = 0
8064
while (i < frames.size) {
@@ -103,8 +87,8 @@ public fun verifyDump(vararg traces: String, ignoredCoroutine: String? = null) {
10387
return@forEach
10488
}
10589

106-
val expected = traces[index - 1].applyBackspace().split("\n\tat kotlinx.coroutines.debug.ArtificialStackFrames.coroutineCreation(ArtificialStackFrames.kt)\n", limit = 2)
107-
val actual = value.applyBackspace().split("\n\tat kotlinx.coroutines.debug.ArtificialStackFrames.coroutineCreation(ArtificialStackFrames.kt)\n", limit = 2)
90+
val expected = traces[index - 1].split("\n\tat kotlinx.coroutines.debug.ArtificialStackFrames.coroutineCreation(ArtificialStackFrames.kt)\n", limit = 2)
91+
val actual = value.split("\n\tat kotlinx.coroutines.debug.ArtificialStackFrames.coroutineCreation(ArtificialStackFrames.kt)\n", limit = 2)
10892
assertEquals(expected.size, actual.size, "Creation stacktrace should be part of the expected input")
10993

11094
expected.withIndex().forEach { (index, trace) ->

0 commit comments

Comments
 (0)