File tree 2 files changed +20
-2
lines changed
src/tools/run-make-support/src
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ use std::path::Path;
6
6
use std:: process:: { Command as StdCommand , ExitStatus , Output , Stdio } ;
7
7
8
8
use crate :: drop_bomb:: DropBomb ;
9
- use crate :: { assert_not_contains, handle_failed_output} ;
9
+ use crate :: { assert_contans , assert_not_contains, handle_failed_output} ;
10
10
11
11
/// This is a custom command wrapper that simplifies working with commands and makes it easier to
12
12
/// ensure that we check the exit status of executed processes.
@@ -167,6 +167,12 @@ impl CompletedProcess {
167
167
self
168
168
}
169
169
170
+ #[ track_caller]
171
+ pub fn assert_stdout_contains < S : AsRef < str > > ( self , needle : S ) -> Self {
172
+ assert_contains ( self . stdout_utf8 ( ) , needle. as_ref ( ) ) ;
173
+ self
174
+ }
175
+
170
176
#[ track_caller]
171
177
pub fn assert_stdout_not_contains < S : AsRef < str > > ( & self , needle : S ) -> & Self {
172
178
assert_not_contains ( & self . stdout_utf8 ( ) , needle. as_ref ( ) ) ;
@@ -182,7 +188,7 @@ impl CompletedProcess {
182
188
183
189
#[ track_caller]
184
190
pub fn assert_stderr_contains < S : AsRef < str > > ( & self , needle : S ) -> & Self {
185
- assert ! ( self . stderr_utf8( ) . contains ( needle. as_ref( ) ) ) ;
191
+ assert_contains ( self . stderr_utf8 ( ) , needle. as_ref ( ) ) ;
186
192
self
187
193
}
188
194
Original file line number Diff line number Diff line change @@ -315,6 +315,18 @@ pub fn read_dir<F: Fn(&Path)>(dir: impl AsRef<Path>, callback: F) {
315
315
}
316
316
}
317
317
318
+ /// Check that `haystack` contains `needle`. Panic otherwise.
319
+ #[ track_caller]
320
+ pub fn assert_contains ( haystack : & str , needle : & str ) {
321
+ if !haystack. contains ( needle) {
322
+ eprintln ! ( "=== HAYSTACK ===" ) ;
323
+ eprintln ! ( "{}" , haystack) ;
324
+ eprintln ! ( "=== NEEDLE ===" ) ;
325
+ eprintln ! ( "{}" , needle) ;
326
+ panic ! ( "needle was not found in haystack" ) ;
327
+ }
328
+ }
329
+
318
330
/// Check that `haystack` does not contain `needle`. Panic otherwise.
319
331
#[ track_caller]
320
332
pub fn assert_not_contains ( haystack : & str , needle : & str ) {
You can’t perform that action at this time.
0 commit comments