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:
parent
d071d127ef
commit
9b5e5e7c0f
1 changed files with 3 additions and 5 deletions
|
|
@ -152,7 +152,7 @@ impl BookTest {
|
||||||
self
|
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.
|
/// The path can use glob-style wildcards, but it must match only a single file.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
|
@ -162,10 +162,8 @@ impl BookTest {
|
||||||
}
|
}
|
||||||
let path = glob_one(&self.dir, path_pattern);
|
let path = glob_one(&self.dir, path_pattern);
|
||||||
let actual = read_to_string(&path);
|
let actual = read_to_string(&path);
|
||||||
assert!(
|
let expected = format!("...\n[..]{expected}[..]\n...\n");
|
||||||
actual.contains(expected),
|
self.assert.eq(actual, expected);
|
||||||
"Did not find {expected:?} in {path:?}\n\n{actual}",
|
|
||||||
);
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue