aboutsummaryrefslogtreecommitdiff
path: root/tests/testutils/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testutils/src/lib.rs')
-rw-r--r--tests/testutils/src/lib.rs34
1 files changed, 16 insertions, 18 deletions
diff --git a/tests/testutils/src/lib.rs b/tests/testutils/src/lib.rs
index 80a94fb66..f829b243b 100644
--- a/tests/testutils/src/lib.rs
+++ b/tests/testutils/src/lib.rs
@@ -1,7 +1,7 @@
1extern crate difference; 1extern crate difference;
2extern crate file; 2extern crate file;
3 3
4use std::path::{PathBuf, Path}; 4use std::path::{Path, PathBuf};
5use std::fs::read_dir; 5use std::fs::read_dir;
6 6
7use difference::Changeset; 7use difference::Changeset;
@@ -21,12 +21,9 @@ fn read_text(path: &Path) -> String {
21 file::get_text(path).unwrap().replace("\r\n", "\n") 21 file::get_text(path).unwrap().replace("\r\n", "\n")
22} 22}
23 23
24pub fn dir_tests<F>( 24pub fn dir_tests<F>(paths: &[&str], f: F)
25 paths: &[&str],
26 f: F
27)
28where 25where
29 F: Fn(&str) -> String 26 F: Fn(&str) -> String,
30{ 27{
31 for path in collect_tests(paths) { 28 for path in collect_tests(paths) {
32 let actual = { 29 let actual = {
@@ -47,21 +44,20 @@ where
47 } 44 }
48} 45}
49 46
50fn assert_equal_text( 47fn assert_equal_text(expected: &str, actual: &str, path: &Path) {
51 expected: &str,
52 actual: &str,
53 path: &Path
54) {
55 if expected != actual { 48 if expected != actual {
56 print_difference(expected, actual, path) 49 print_difference(expected, actual, path)
57 } 50 }
58} 51}
59 52
60fn collect_tests(paths: &[&str]) -> Vec<PathBuf> { 53fn collect_tests(paths: &[&str]) -> Vec<PathBuf> {
61 paths.iter().flat_map(|path| { 54 paths
62 let path = test_data_dir().join(path); 55 .iter()
63 test_from_dir(&path).into_iter() 56 .flat_map(|path| {
64 }).collect() 57 let path = test_data_dir().join(path);
58 test_from_dir(&path).into_iter()
59 })
60 .collect()
65} 61}
66 62
67fn test_from_dir(dir: &Path) -> Vec<PathBuf> { 63fn test_from_dir(dir: &Path) -> Vec<PathBuf> {
@@ -95,11 +91,13 @@ fn print_difference(expected: &str, actual: &str, path: &Path) {
95fn project_dir() -> PathBuf { 91fn project_dir() -> PathBuf {
96 let dir = env!("CARGO_MANIFEST_DIR"); 92 let dir = env!("CARGO_MANIFEST_DIR");
97 PathBuf::from(dir) 93 PathBuf::from(dir)
98 .parent().unwrap() 94 .parent()
99 .parent().unwrap() 95 .unwrap()
96 .parent()
97 .unwrap()
100 .to_owned() 98 .to_owned()
101} 99}
102 100
103fn test_data_dir() -> PathBuf { 101fn test_data_dir() -> PathBuf {
104 project_dir().join("tests/data") 102 project_dir().join("tests/data")
105} \ No newline at end of file 103}