Skip to content

Commit 9d0f6e0

Browse files
hovinenbcopybara-github
authored andcommitted
Enumerate and indent the descriptions of the inner matchers in elements_are!, unordered_elements_are!, and friends.
This makes a test failure assertion a bit more readable, by visually separating the inner matchers from the rest of the message. The enumeration also helps the reader to connect the mismatch explanation below with the expected values indicated in the matcher descriptions. PiperOrigin-RevId: 505621887
1 parent 221ccca commit 9d0f6e0

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

googletest/src/matchers/elements_are_matcher.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ pub mod internal {
106106
matcher_result.pick("has", "doesn't have"),
107107
self.elements
108108
.iter()
109-
.map(|m| m.describe(MatcherResult::Matches))
109+
.enumerate()
110+
.map(|(index, matcher)| format!(
111+
" {index}: {}",
112+
matcher.describe(MatcherResult::Matches)
113+
))
110114
.collect::<Vec<_>>()
111115
.join("\n")
112116
)
@@ -151,9 +155,9 @@ mod tests {
151155
"\
152156
Value of: vec![1, 4, 3]
153157
Expected: has elements:
154-
is equal to 1
155-
is equal to 2
156-
is equal to 3
158+
0: is equal to 1
159+
1: is equal to 2
160+
2: is equal to 3
157161
Actual: [
158162
1,
159163
4,

googletest/src/matchers/unordered_elements_are_matcher.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,11 @@ pub mod internal {
327327
matcher_result.pick("contains", "doesn't contain"),
328328
self.elements
329329
.iter()
330-
.map(|&m| m.describe(MatcherResult::Matches))
330+
.enumerate()
331+
.map(|(index, matcher)| format!(
332+
" {index}: {}",
333+
matcher.describe(MatcherResult::Matches)
334+
))
331335
.collect::<Vec<_>>()
332336
.join("\n")
333337
)
@@ -755,9 +759,9 @@ mod tests {
755759
"\
756760
Value of: vec![1, 4, 3]
757761
Expected: contains elements matching in any order:
758-
is equal to 1
759-
is equal to 2
760-
is equal to 3
762+
0: is equal to 1
763+
1: is equal to 2
764+
2: is equal to 3
761765
Actual: [
762766
1,
763767
4,

0 commit comments

Comments
 (0)