Skip to content

Commit 45c7d58

Browse files
committed
T: Don't unescape test output
1 parent 953cd3d commit 45c7d58

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

src/main/kotlin/org/rust/cargo/runconfig/test/CargoTestEventsConverter.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import com.intellij.execution.testframework.sm.ServiceMessageBuilder
1515
import com.intellij.execution.testframework.sm.runner.OutputToGeneralTestEventsConverter
1616
import com.intellij.openapi.project.Project
1717
import com.intellij.openapi.util.Key
18-
import com.intellij.openapi.util.text.StringUtil.unescapeStringCharacters
1918
import com.intellij.openapi.util.text.StringUtil.unquoteString
2019
import com.intellij.util.execution.ParametersListUtil
2120
import jetbrains.buildServer.messages.serviceMessages.ServiceMessageVisitor
@@ -119,8 +118,7 @@ class CargoTestEventsConverter(
119118
// Parse `rustdoc` test name:
120119
// src/lib.rs - qualifiedName (line #i) -> qualifiedName (line #i)
121120
val qualifiedName = it.name.substringAfter(" - ")
122-
val stdout = it.stdout?.let(::unescape)
123-
it.copy(name = "$target::$qualifiedName", stdout = stdout)
121+
it.copy(name = "$target::$qualifiedName")
124122
} ?: return false
125123
val messages = createServiceMessagesFor(testMessage) ?: return false
126124
for (message in messages) {
@@ -358,8 +356,8 @@ class CargoTestEventsConverter(
358356
val message = groups["message"]?.value ?: error("Failed to find `message` capturing group")
359357

360358
val diff = if (groups["sign"]?.value == "==") {
361-
val left = groups["left"]?.value?.let(::unescape)
362-
val right = groups["right"]?.value?.let(::unescape)
359+
val left = groups["left"]?.value?.let(::unquoteString)
360+
val right = groups["right"]?.value?.let(::unquoteString)
363361
if (left != null && right != null) DiffResult(left, right) else null
364362
} else {
365363
null
@@ -393,8 +391,6 @@ class CargoTestEventsConverter(
393391
}
394392
}
395393

396-
private fun unescape(s: String): String = unquoteString(unescapeStringCharacters(s))
397-
398394
private data class FailedTestOutput(val stdout: String, val failedMessage: String)
399395
private data class ErrorMessage(val message: String, val diff: DiffResult?, val backtrace: String?)
400396
private data class DiffResult(val left: String, val right: String)

src/test/kotlin/org/rustSlowTests/cargo/runconfig/test/CargoTestNodeInfoTest.kt

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CargoTestNodeInfoTest : CargoTestRunnerTestBase() {
3030

3131
fun `test multiline string diff`() = checkErrors("""
3232
assert_eq!("a\naa", "bbb");
33-
""", "", Diff("a\naa", "bbb"))
33+
""", "", Diff("a\\naa", "bbb"))
3434

3535
fun `test assert_eq with message`() = checkErrors("""
3636
assert_eq!(1, 2, "`1` != `2`");
@@ -52,26 +52,14 @@ class CargoTestNodeInfoTest : CargoTestRunnerTestBase() {
5252
assert_ne!(123, 123, "123 == 123");
5353
""", "123 == 123")
5454

55+
fun `test don't unescape error messages`() = checkErrors("""
56+
assert_eq!("a\\\\b", "a\\b", "`a\\\\b` != `a\\b`");
57+
""", "`a\\\\b` != `a\\b`")
58+
5559
@MinRustcVersion("1.39.0")
56-
fun `test successful output`() = checkOutput("""
57-
println!("
58-
- ");
59-
""",
60-
output = """
61-
- """,
62-
shouldPass = true)
63-
64-
fun `test failed output`() = checkOutput("""
65-
println!("
66-
- ");
67-
panic!("
68-
- ");
69-
""",
70-
output = """
71-
-
72-
73-
74-
- """)
60+
fun `test don't unescape test output`() = checkOutput("""
61+
println!("a\\\\b");
62+
""", "a\\\\b")
7563

7664
fun `test root output`() {
7765
val testProject = buildProject {
@@ -121,7 +109,7 @@ class CargoTestNodeInfoTest : CargoTestRunnerTestBase() {
121109
}
122110
}
123111

124-
private fun checkOutput(@Language("Rust") testFnText: String, output: String, shouldPass: Boolean = false) {
112+
private fun checkOutput(@Language("Rust") testFnText: String, output: String, shouldPass: Boolean = true) {
125113
val testNode = getTestNode(testFnText, shouldPass)
126114
assertEquals(output, testNode.output.trimEnd('\n'))
127115
}

0 commit comments

Comments
 (0)