Skip to content

Commit d1d1e16

Browse files
committed
Use platform-specific line separator in test value
1 parent f49d7ed commit d1d1e16

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

zipline/src/jniTest/kotlin/app/cash/zipline/ThrowableSerializerTest.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package app.cash.zipline
1818
import app.cash.zipline.internal.bridge.ThrowableSerializer
1919
import assertk.assertThat
2020
import assertk.assertions.isEqualTo
21+
import java.util.Locale.US
2122
import kotlin.coroutines.cancellation.CancellationException
2223
import kotlin.test.assertEquals
2324
import kotlinx.serialization.json.Json
@@ -31,6 +32,17 @@ class ThrowableSerializerTest {
3132
contextual(Throwable::class, ThrowableSerializer)
3233
}
3334
}
35+
private val newline: String
36+
private val newlineEscape: String
37+
init {
38+
if ("windows" in System.getProperty("os.name").lowercase(US)) {
39+
newline = "\r\n"
40+
newlineEscape = "\\r\\n"
41+
} else {
42+
newline = "\n"
43+
newlineEscape = "\\n"
44+
}
45+
}
3446

3547
@Test fun happyPath() {
3648
val exception = Exception("boom")
@@ -41,7 +53,7 @@ class ThrowableSerializerTest {
4153
val exceptionJson = """
4254
|{
4355
| "types": [],
44-
| "stacktraceString": "java.lang.Exception: boom\n\tat ThrowableSerializerTest.goBoom(test.kt:5)"
56+
| "stacktraceString": "java.lang.Exception: boom$newlineEscape\tat ThrowableSerializerTest.goBoom(test.kt:5)"
4557
|}
4658
""".trimMargin()
4759

@@ -53,10 +65,7 @@ class ThrowableSerializerTest {
5365
val decoded = json.decodeFromString(ThrowableSerializer, exceptionJson)
5466
assertEquals(ZiplineException::class, decoded::class)
5567
assertEquals(
56-
"""
57-
|java.lang.Exception: boom
58-
|${'\t'}at ThrowableSerializerTest.goBoom(test.kt:5)
59-
""".trimMargin(),
68+
"java.lang.Exception: boom$newline\tat ThrowableSerializerTest.goBoom(test.kt:5)",
6069
decoded.message,
6170
)
6271
}

0 commit comments

Comments
 (0)