Skip to content

Commit b27147c

Browse files
committed
Indent the output of the diff between actual and expected values by two spaces.
This is to reduce the need to adjust tests in a later change. Namely, a coming rework in the way failure messages are rendered will increase the aforementioned indentation, which will result in several tests having to be updated. Making this change now greatly reduces the number of tests which have to be updated later, allowing that change to be more focused.
1 parent 1fb0652 commit b27147c

File tree

6 files changed

+200
-199
lines changed

6 files changed

+200
-199
lines changed

googletest/src/matcher_support/summarize_diff.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,21 @@ pub(crate) fn create_diff(
4343
}
4444
match edit_distance::edit_list(actual_debug.lines(), expected_debug.lines(), diff_mode) {
4545
edit_distance::Difference::Equal => "No difference found between debug strings.".into(),
46-
edit_distance::Difference::Editable(edit_list) => format!(
46+
edit_distance::Difference::Editable(edit_list) => indent(format!(
4747
"\nDifference({} / {}):{}",
4848
LineStyle::extra_actual_style().style("actual"),
4949
LineStyle::extra_expected_style().style("expected"),
5050
edit_list.into_iter().collect::<BufferedSummary>(),
51-
)
51+
))
5252
.into(),
5353
edit_distance::Difference::Unrelated => "".into(),
5454
}
5555
}
5656

57+
fn indent(string: impl AsRef<str>) -> String {
58+
string.as_ref().lines().collect::<Vec<_>>().join("\n ")
59+
}
60+
5761
/// Returns a string describing how the expected and actual differ after
5862
/// reversing the lines in each.
5963
///
@@ -351,17 +355,14 @@ mod tests {
351355

352356
verify_that!(
353357
create_diff(&build_text(1..50), &build_text(1..51), Mode::Exact),
354-
eq(indoc! {
355-
"
356-
357-
Difference(-actual / +expected):
358-
1
359-
2
360-
<---- 45 common lines omitted ---->
361-
48
362-
49
363-
+50"
364-
})
358+
eq("
359+
Difference(-actual / +expected):
360+
1
361+
2
362+
<---- 45 common lines omitted ---->
363+
48
364+
49
365+
+50")
365366
)
366367
}
367368
}

googletest/src/matchers/display_matcher.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,10 @@ impl<T: Debug + Display, InnerMatcher: Matcher<ActualT = String>> Matcher
5151
MatcherResult::Match => {
5252
format!("displays as a string which {}", self.inner.describe(MatcherResult::Match))
5353
}
54-
MatcherResult::NoMatch => {
55-
format!(
56-
"doesn't display as a string which {}",
57-
self.inner.describe(MatcherResult::Match)
58-
)
59-
}
54+
MatcherResult::NoMatch => format!(
55+
"doesn't display as a string which {}",
56+
self.inner.describe(MatcherResult::Match)
57+
),
6058
}
6159
}
6260
}
@@ -107,6 +105,7 @@ mod tests {
107105
result,
108106
err(displays_as(contains_substring(indoc!(
109107
"
108+
Actual: \"123\\n234\",
110109
which displays as a string which isn't equal to \"123\\n345\"
111110
Difference(-actual / +expected):
112111
123

googletest/src/matchers/eq_deref_of_matcher.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ mod tests {
138138
"
139139
Actual: Strukt { int: 123, string: \"something\" },
140140
which isn't equal to Strukt { int: 321, string: \"someone\" }
141-
Difference(-actual / +expected):
142-
Strukt {
143-
- int: 123,
144-
+ int: 321,
145-
- string: \"something\",
146-
+ string: \"someone\",
147-
}
141+
Difference(-actual / +expected):
142+
Strukt {
143+
- int: 123,
144+
+ int: 321,
145+
- string: \"something\",
146+
+ string: \"someone\",
147+
}
148148
"})))
149149
)
150150
}

googletest/src/matchers/eq_matcher.rs

Lines changed: 79 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@ mod tests {
178178
"
179179
Actual: Strukt { int: 123, string: \"something\" },
180180
which isn't equal to Strukt { int: 321, string: \"someone\" }
181-
Difference(-actual / +expected):
182-
Strukt {
183-
- int: 123,
184-
+ int: 321,
185-
- string: \"something\",
186-
+ string: \"someone\",
187-
}
181+
Difference(-actual / +expected):
182+
Strukt {
183+
- int: 123,
184+
+ int: 321,
185+
- string: \"something\",
186+
+ string: \"someone\",
187+
}
188188
"})))
189189
)
190190
}
@@ -200,13 +200,13 @@ mod tests {
200200
Expected: is equal to [1, 3, 4]
201201
Actual: [1, 2, 3],
202202
which isn't equal to [1, 3, 4]
203-
Difference(-actual / +expected):
204-
[
205-
1,
206-
- 2,
207-
3,
208-
+ 4,
209-
]
203+
Difference(-actual / +expected):
204+
[
205+
1,
206+
- 2,
207+
3,
208+
+ 4,
209+
]
210210
"})))
211211
)
212212
}
@@ -222,14 +222,14 @@ mod tests {
222222
Expected: is equal to [1, 3, 5]
223223
Actual: [1, 2, 3, 4, 5],
224224
which isn't equal to [1, 3, 5]
225-
Difference(-actual / +expected):
226-
[
227-
1,
228-
- 2,
229-
3,
230-
- 4,
231-
5,
232-
]
225+
Difference(-actual / +expected):
226+
[
227+
1,
228+
- 2,
229+
3,
230+
- 4,
231+
5,
232+
]
233233
"})))
234234
)
235235
}
@@ -241,18 +241,20 @@ mod tests {
241241
result,
242242
err(displays_as(contains_substring(indoc! {
243243
"
244-
Difference(-actual / +expected):
245-
[
246-
- 1,
247-
- 2,
248-
3,
249-
4,
250-
<---- 43 common lines omitted ---->
251-
48,
252-
49,
253-
+ 50,
254-
+ 51,
255-
]"})))
244+
],
245+
which isn't equal to [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51]
246+
Difference(-actual / +expected):
247+
[
248+
- 1,
249+
- 2,
250+
3,
251+
4,
252+
<---- 43 common lines omitted ---->
253+
48,
254+
49,
255+
+ 50,
256+
+ 51,
257+
]"})))
256258
)
257259
}
258260

@@ -263,18 +265,20 @@ mod tests {
263265
result,
264266
err(displays_as(contains_substring(indoc! {
265267
"
266-
Difference(-actual / +expected):
267-
[
268-
- 1,
269-
- 2,
270-
3,
271-
4,
272-
5,
273-
6,
274-
7,
275-
+ 8,
276-
+ 9,
277-
]"})))
268+
Actual: [1, 2, 3, 4, 5, 6, 7],
269+
which isn't equal to [3, 4, 5, 6, 7, 8, 9]
270+
Difference(-actual / +expected):
271+
[
272+
- 1,
273+
- 2,
274+
3,
275+
4,
276+
5,
277+
6,
278+
7,
279+
+ 8,
280+
+ 9,
281+
]"})))
278282
)
279283
}
280284

@@ -285,15 +289,17 @@ mod tests {
285289
result,
286290
err(displays_as(contains_substring(indoc! {
287291
"
288-
Difference(-actual / +expected):
289-
[
290-
1,
291-
<---- 46 common lines omitted ---->
292-
48,
293-
49,
294-
+ 50,
295-
+ 51,
296-
]"})))
292+
],
293+
which isn't equal to [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51]
294+
Difference(-actual / +expected):
295+
[
296+
1,
297+
<---- 46 common lines omitted ---->
298+
48,
299+
49,
300+
+ 50,
301+
+ 51,
302+
]"})))
297303
)
298304
}
299305

@@ -304,15 +310,17 @@ mod tests {
304310
result,
305311
err(displays_as(contains_substring(indoc! {
306312
"
307-
Difference(-actual / +expected):
308-
[
309-
- 1,
310-
- 2,
311-
3,
312-
4,
313-
<---- 46 common lines omitted ---->
314-
51,
315-
]"})))
313+
],
314+
which isn't equal to [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51]
315+
Difference(-actual / +expected):
316+
[
317+
- 1,
318+
- 2,
319+
3,
320+
4,
321+
<---- 46 common lines omitted ---->
322+
51,
323+
]"})))
316324
)
317325
}
318326

@@ -354,14 +362,13 @@ mod tests {
354362

355363
verify_that!(
356364
result,
357-
err(displays_as(contains_substring(indoc!(
358-
"
359-
First line
360-
-Second line
361-
+Second lines
362-
Third line
363-
"
364-
))))
365+
err(displays_as(contains_substring(
366+
"\
367+
First line
368+
-Second line
369+
+Second lines
370+
Third line"
371+
)))
365372
)
366373
}
367374

0 commit comments

Comments
 (0)