diff options
author | Aleksey Kladov <[email protected]> | 2018-01-07 12:34:11 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-01-07 12:34:11 +0000 |
commit | 7c6f0f9128665c1a605caaa552347b936578f952 (patch) | |
tree | e46900ddc24786364a767b35c78c0df588ab0541 /tests/testutils/src/lib.rs | |
parent | 9e4052cc2ee12751ba94909ff479bd03df141ac4 (diff) |
G: shebang
Diffstat (limited to 'tests/testutils/src/lib.rs')
-rw-r--r-- | tests/testutils/src/lib.rs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/tests/testutils/src/lib.rs b/tests/testutils/src/lib.rs index 9fc85cc24..b34517c5f 100644 --- a/tests/testutils/src/lib.rs +++ b/tests/testutils/src/lib.rs | |||
@@ -6,7 +6,33 @@ use std::fs::read_dir; | |||
6 | 6 | ||
7 | use difference::Changeset; | 7 | use difference::Changeset; |
8 | 8 | ||
9 | pub fn assert_equal_text( | 9 | pub fn dir_tests<F>( |
10 | paths: &[&str], | ||
11 | f: F | ||
12 | ) | ||
13 | where | ||
14 | F: Fn(&str) -> String | ||
15 | { | ||
16 | for path in collect_tests(paths) { | ||
17 | let actual = { | ||
18 | let text = file::get_text(&path).unwrap(); | ||
19 | f(&text) | ||
20 | }; | ||
21 | let path = path.with_extension("txt"); | ||
22 | if !path.exists() { | ||
23 | println!("\nfile: {}", path.display()); | ||
24 | println!("No .txt file with expected result, creating..."); | ||
25 | file::put_text(&path, actual).unwrap(); | ||
26 | panic!("No expected result") | ||
27 | } | ||
28 | let expected = file::get_text(&path).unwrap(); | ||
29 | let expected = expected.as_str(); | ||
30 | let actual = actual.as_str(); | ||
31 | assert_equal_text(expected, actual, &path); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | fn assert_equal_text( | ||
10 | expected: &str, | 36 | expected: &str, |
11 | actual: &str, | 37 | actual: &str, |
12 | path: &Path | 38 | path: &Path |
@@ -16,7 +42,7 @@ pub fn assert_equal_text( | |||
16 | } | 42 | } |
17 | } | 43 | } |
18 | 44 | ||
19 | pub fn collect_tests(paths: &[&str]) -> Vec<PathBuf> { | 45 | fn collect_tests(paths: &[&str]) -> Vec<PathBuf> { |
20 | paths.iter().flat_map(|path| { | 46 | paths.iter().flat_map(|path| { |
21 | let path = test_data_dir().join(path); | 47 | let path = test_data_dir().join(path); |
22 | test_from_dir(&path).into_iter() | 48 | test_from_dir(&path).into_iter() |