diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-03 09:54:52 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-03 09:54:52 +0000 |
commit | 3c70ae2e26f654ce536f00fde8c159e4ebe6901a (patch) | |
tree | 89fe4c9e08b76f69d39f4a565848c4ba054b6da7 /tests | |
parent | 6d9753bf548b22ab1a54462f72c9c0bf4ff69382 (diff) | |
parent | 9435ea4b8e990521ee7a6206b6106bb3ce392746 (diff) |
Merge #38
38: Move tools to a separate package r=matklad a=matklad
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lexer.rs | 1 | ||||
-rw-r--r-- | tests/parser.rs | 1 | ||||
-rw-r--r-- | tests/testutils/src/lib.rs | 34 |
3 files changed, 16 insertions, 20 deletions
diff --git a/tests/lexer.rs b/tests/lexer.rs index 397ebafdd..46ac9fedd 100644 --- a/tests/lexer.rs +++ b/tests/lexer.rs | |||
@@ -1,4 +1,3 @@ | |||
1 | extern crate file; | ||
2 | extern crate libsyntax2; | 1 | extern crate libsyntax2; |
3 | extern crate testutils; | 2 | extern crate testutils; |
4 | 3 | ||
diff --git a/tests/parser.rs b/tests/parser.rs index 37c9021ef..f681c066f 100644 --- a/tests/parser.rs +++ b/tests/parser.rs | |||
@@ -1,4 +1,3 @@ | |||
1 | extern crate file; | ||
2 | extern crate libsyntax2; | 1 | extern crate libsyntax2; |
3 | extern crate testutils; | 2 | extern crate testutils; |
4 | 3 | ||
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 @@ | |||
1 | extern crate difference; | 1 | extern crate difference; |
2 | extern crate file; | 2 | extern crate file; |
3 | 3 | ||
4 | use std::path::{PathBuf, Path}; | 4 | use std::path::{Path, PathBuf}; |
5 | use std::fs::read_dir; | 5 | use std::fs::read_dir; |
6 | 6 | ||
7 | use difference::Changeset; | 7 | use 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 | ||
24 | pub fn dir_tests<F>( | 24 | pub fn dir_tests<F>(paths: &[&str], f: F) |
25 | paths: &[&str], | ||
26 | f: F | ||
27 | ) | ||
28 | where | 25 | where |
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 | ||
50 | fn assert_equal_text( | 47 | fn 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 | ||
60 | fn collect_tests(paths: &[&str]) -> Vec<PathBuf> { | 53 | fn 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 | ||
67 | fn test_from_dir(dir: &Path) -> Vec<PathBuf> { | 63 | fn test_from_dir(dir: &Path) -> Vec<PathBuf> { |
@@ -95,11 +91,13 @@ fn print_difference(expected: &str, actual: &str, path: &Path) { | |||
95 | fn project_dir() -> PathBuf { | 91 | fn 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 | ||
103 | fn test_data_dir() -> PathBuf { | 101 | fn test_data_dir() -> PathBuf { |
104 | project_dir().join("tests/data") | 102 | project_dir().join("tests/data") |
105 | } \ No newline at end of file | 103 | } |