aboutsummaryrefslogtreecommitdiff
path: root/crates/test_utils
diff options
context:
space:
mode:
Diffstat (limited to 'crates/test_utils')
-rw-r--r--crates/test_utils/src/lib.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index 69deddcb5..db03df1c4 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -202,6 +202,19 @@ pub fn parse_fixture(fixture: &str) -> Vec<FixtureEntry> {
202 res 202 res
203} 203}
204 204
205/// Same as `parse_fixture`, except it allow empty fixture
206pub fn parse_single_fixture(fixture: &str) -> Option<FixtureEntry> {
207 if !fixture.lines().any(|it| it.trim_start().starts_with("//-")) {
208 return None;
209 }
210
211 let fixtures = parse_fixture(fixture);
212 if fixtures.len() > 1 {
213 panic!("too many fixtures");
214 }
215 fixtures.into_iter().nth(0)
216}
217
205// Comparison functionality borrowed from cargo: 218// Comparison functionality borrowed from cargo:
206 219
207/// Compare a line with an expected pattern. 220/// Compare a line with an expected pattern.
@@ -384,6 +397,8 @@ pub fn skip_slow_tests() -> bool {
384 should_skip 397 should_skip
385} 398}
386 399
400const REWRITE: bool = false;
401
387/// Asserts that `expected` and `actual` strings are equal. If they differ only 402/// Asserts that `expected` and `actual` strings are equal. If they differ only
388/// in trailing or leading whitespace the test won't fail and 403/// in trailing or leading whitespace the test won't fail and
389/// the contents of `actual` will be written to the file located at `path`. 404/// the contents of `actual` will be written to the file located at `path`.
@@ -399,7 +414,6 @@ fn assert_equal_text(expected: &str, actual: &str, path: &Path) {
399 fs::write(path, actual).unwrap(); 414 fs::write(path, actual).unwrap();
400 return; 415 return;
401 } 416 }
402 const REWRITE: bool = false;
403 if REWRITE { 417 if REWRITE {
404 println!("rewriting {}", pretty_path.display()); 418 println!("rewriting {}", pretty_path.display());
405 fs::write(path, actual).unwrap(); 419 fs::write(path, actual).unwrap();