mirror of
https://github.com/rust-lang/mdBook.git
synced 2025-12-27 10:16:09 -05:00
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.
This commit is contained in:
@@ -152,7 +152,7 @@ impl BookTest {
|
||||
self
|
||||
}
|
||||
|
||||
/// Checks that the given file contains the given string somewhere.
|
||||
/// Checks that the given file contains the given [`snapbox::Assert`] pattern somewhere.
|
||||
///
|
||||
/// The path can use glob-style wildcards, but it must match only a single file.
|
||||
#[track_caller]
|
||||
@@ -162,10 +162,8 @@ impl BookTest {
|
||||
}
|
||||
let path = glob_one(&self.dir, path_pattern);
|
||||
let actual = read_to_string(&path);
|
||||
assert!(
|
||||
actual.contains(expected),
|
||||
"Did not find {expected:?} in {path:?}\n\n{actual}",
|
||||
);
|
||||
let expected = format!("...\n[..]{expected}[..]\n...\n");
|
||||
self.assert.eq(actual, expected);
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user