Skip to content

Commit dd5e9a6

Browse files
committed
Use the displays_as matcher when asserting on the output of Matcher::describe in tests.
Many existing tests assert directly on the output of `Matcher::describe`, which is currently a `String`. This return type will change to a `Description` in the future. In order that the tests do not have to be modified when that is changed, this changes them to wrap the existing matcher in `displays_as`. That has no effect on the current assertion, but will cause the `Display::fmt` method to be invoked on the output in the future.
1 parent b27147c commit dd5e9a6

14 files changed

+54
-42
lines changed

googletest/src/matchers/all_matcher.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ mod tests {
163163

164164
verify_that!(
165165
matcher.describe(MatcherResult::Match),
166-
eq(indoc!(
166+
displays_as(eq(indoc!(
167167
"
168168
has all the following properties:
169169
* starts with prefix \"A\"
170170
* ends with suffix \"string\""
171-
))
171+
)))
172172
)
173173
}
174174

@@ -177,7 +177,10 @@ mod tests {
177177
let first_matcher = starts_with("A");
178178
let matcher: internal::AllMatcher<String, 1> = all!(first_matcher);
179179

180-
verify_that!(matcher.describe(MatcherResult::Match), eq("starts with prefix \"A\""))
180+
verify_that!(
181+
matcher.describe(MatcherResult::Match),
182+
displays_as(eq("starts with prefix \"A\""))
183+
)
181184
}
182185

183186
#[test]

googletest/src/matchers/any_matcher.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ mod tests {
157157

158158
verify_that!(
159159
matcher.describe(MatcherResult::Match),
160-
eq(indoc!(
160+
displays_as(eq(indoc!(
161161
"
162162
has at least one of the following properties:
163163
* starts with prefix \"A\"
164164
* ends with suffix \"string\""
165-
))
165+
)))
166166
)
167167
}
168168

@@ -171,7 +171,10 @@ mod tests {
171171
let first_matcher = starts_with("A");
172172
let matcher: internal::AnyMatcher<String, 1> = any!(first_matcher);
173173

174-
verify_that!(matcher.describe(MatcherResult::Match), eq("starts with prefix \"A\""))
174+
verify_that!(
175+
matcher.describe(MatcherResult::Match),
176+
displays_as(eq("starts with prefix \"A\""))
177+
)
175178
}
176179

177180
#[test]

googletest/src/matchers/contains_matcher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ mod tests {
233233

234234
verify_that!(
235235
Matcher::describe(&matcher, MatcherResult::Match),
236-
eq("contains at least one element which is equal to 1")
236+
displays_as(eq("contains at least one element which is equal to 1"))
237237
)
238238
}
239239

@@ -243,7 +243,7 @@ mod tests {
243243

244244
verify_that!(
245245
Matcher::describe(&matcher, MatcherResult::Match),
246-
eq("contains n elements which is equal to 1\n where n is equal to 2")
246+
displays_as(eq("contains n elements which is equal to 1\n where n is equal to 2"))
247247
)
248248
}
249249

googletest/src/matchers/contains_regex_matcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ mod tests {
142142

143143
verify_that!(
144144
Matcher::describe(&matcher, MatcherResult::Match),
145-
eq("contains the regular expression \"\\n\"")
145+
displays_as(eq("contains the regular expression \"\\n\""))
146146
)
147147
}
148148
}

googletest/src/matchers/err_matcher.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ mod tests {
139139
phantom_t: Default::default(),
140140
phantom_e: Default::default(),
141141
};
142-
verify_that!(matcher.describe(MatcherResult::Match), eq("is an error which is equal to 1"))
142+
verify_that!(
143+
matcher.describe(MatcherResult::Match),
144+
displays_as(eq("is an error which is equal to 1"))
145+
)
143146
}
144147
}

googletest/src/matchers/gt_matcher.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,17 @@ mod tests {
175175

176176
#[test]
177177
fn gt_describe_matches() -> Result<()> {
178-
verify_that!(gt::<i32, i32>(232).describe(MatcherResult::Match), eq("is greater than 232"))
178+
verify_that!(
179+
gt::<i32, i32>(232).describe(MatcherResult::Match),
180+
displays_as(eq("is greater than 232"))
181+
)
179182
}
180183

181184
#[test]
182185
fn gt_describe_does_not_match() -> Result<()> {
183186
verify_that!(
184187
gt::<i32, i32>(232).describe(MatcherResult::NoMatch),
185-
eq("is less than or equal to 232")
188+
displays_as(eq("is less than or equal to 232"))
186189
)
187190
}
188191

googletest/src/matchers/is_encoded_string_matcher.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ mod tests {
129129

130130
verify_that!(
131131
matcher.describe(MatcherResult::Match),
132-
eq("is a UTF-8 encoded string which is equal to \"A string\"")
132+
displays_as(eq("is a UTF-8 encoded string which is equal to \"A string\""))
133133
)
134134
}
135135

@@ -139,7 +139,7 @@ mod tests {
139139

140140
verify_that!(
141141
matcher.describe(MatcherResult::NoMatch),
142-
eq("is not a UTF-8 encoded string which is equal to \"A string\"")
142+
displays_as(eq("is not a UTF-8 encoded string which is equal to \"A string\""))
143143
)
144144
}
145145

@@ -149,15 +149,15 @@ mod tests {
149149

150150
verify_that!(
151151
explanation,
152-
eq("which is a UTF-8 encoded string which is equal to \"A string\"")
152+
displays_as(eq("which is a UTF-8 encoded string which is equal to \"A string\""))
153153
)
154154
}
155155

156156
#[test]
157157
fn has_correct_explanation_when_byte_array_is_not_utf8_encoded() -> Result<()> {
158158
let explanation = is_utf8_string(eq("A string")).explain_match(&&[192, 128, 0, 64]);
159159

160-
verify_that!(explanation, starts_with("which is not a UTF-8 encoded string: "))
160+
verify_that!(explanation, displays_as(starts_with("which is not a UTF-8 encoded string: ")))
161161
}
162162

163163
#[test]
@@ -167,7 +167,7 @@ mod tests {
167167

168168
verify_that!(
169169
explanation,
170-
eq("which is a UTF-8 encoded string which isn't equal to \"A string\"")
170+
displays_as(eq("which is a UTF-8 encoded string which isn't equal to \"A string\""))
171171
)
172172
}
173173
}

googletest/src/matchers/matches_regex_matcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ mod tests {
204204

205205
verify_that!(
206206
Matcher::describe(&matcher, MatcherResult::Match),
207-
eq("matches the regular expression \"\\n\"")
207+
displays_as(eq("matches the regular expression \"\\n\""))
208208
)
209209
}
210210
}

googletest/src/matchers/ok_matcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ mod tests {
144144
};
145145
verify_that!(
146146
matcher.describe(MatcherResult::Match),
147-
eq("is a success containing a value, which is equal to 1")
147+
displays_as(eq("is a success containing a value, which is equal to 1"))
148148
)
149149
}
150150
}

googletest/src/matchers/some_matcher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ mod tests {
127127
fn some_describe_matches() -> Result<()> {
128128
verify_that!(
129129
some(eq(1)).describe(MatcherResult::Match),
130-
eq("has a value which is equal to 1")
130+
displays_as(eq("has a value which is equal to 1"))
131131
)
132132
}
133133

134134
#[test]
135135
fn some_describe_does_not_match() -> Result<()> {
136136
verify_that!(
137137
some(eq(1)).describe(MatcherResult::NoMatch),
138-
eq("is None or has a value which isn't equal to 1")
138+
displays_as(eq("is None or has a value which isn't equal to 1"))
139139
)
140140
}
141141

0 commit comments

Comments
 (0)