Skip to content

Commit 9b5e5e7

Browse files
committed
Add snapbox pattern matching on check_file_contains
This is helpful for matching patterns within a larger file. The error message isn't quite as good, since it doesn't explicitly say "pattern not found", but I think you can figure it out from the context.
1 parent d071d12 commit 9b5e5e7

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

tests/testsuite/book_test.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl BookTest {
152152
self
153153
}
154154

155-
/// Checks that the given file contains the given string somewhere.
155+
/// Checks that the given file contains the given [`snapbox::Assert`] pattern somewhere.
156156
///
157157
/// The path can use glob-style wildcards, but it must match only a single file.
158158
#[track_caller]
@@ -162,10 +162,8 @@ impl BookTest {
162162
}
163163
let path = glob_one(&self.dir, path_pattern);
164164
let actual = read_to_string(&path);
165-
assert!(
166-
actual.contains(expected),
167-
"Did not find {expected:?} in {path:?}\n\n{actual}",
168-
);
165+
let expected = format!("...\n[..]{expected}[..]\n...\n");
166+
self.assert.eq(actual, expected);
169167
self
170168
}
171169

0 commit comments

Comments
 (0)