diff options
Diffstat (limited to 'tools/src/bin')
-rw-r--r-- | tools/src/bin/collect-tests.rs | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/tools/src/bin/collect-tests.rs b/tools/src/bin/collect-tests.rs index c54059e79..df9d2db81 100644 --- a/tools/src/bin/collect-tests.rs +++ b/tools/src/bin/collect-tests.rs | |||
@@ -1,11 +1,11 @@ | |||
1 | extern crate file; | 1 | extern crate file; |
2 | extern crate walkdir; | ||
3 | extern crate itertools; | 2 | extern crate itertools; |
3 | extern crate walkdir; | ||
4 | 4 | ||
5 | use walkdir::WalkDir; | 5 | use walkdir::WalkDir; |
6 | use itertools::Itertools; | 6 | use itertools::Itertools; |
7 | 7 | ||
8 | use std::path::{PathBuf, Path}; | 8 | use std::path::{Path, PathBuf}; |
9 | use std::collections::HashSet; | 9 | use std::collections::HashSet; |
10 | use std::fs; | 10 | use std::fs; |
11 | 11 | ||
@@ -33,7 +33,6 @@ fn main() { | |||
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | |||
37 | #[derive(Debug, Eq)] | 36 | #[derive(Debug, Eq)] |
38 | struct Test { | 37 | struct Test { |
39 | name: String, | 38 | name: String, |
@@ -57,13 +56,12 @@ fn tests_from_dir(dir: &Path) -> HashSet<Test> { | |||
57 | for entry in WalkDir::new(dir) { | 56 | for entry in WalkDir::new(dir) { |
58 | let entry = entry.unwrap(); | 57 | let entry = entry.unwrap(); |
59 | if !entry.file_type().is_file() { | 58 | if !entry.file_type().is_file() { |
60 | continue | 59 | continue; |
61 | } | 60 | } |
62 | if entry.path().extension().unwrap_or_default() != "rs" { | 61 | if entry.path().extension().unwrap_or_default() != "rs" { |
63 | continue | 62 | continue; |
64 | } | 63 | } |
65 | let text = file::get_text(entry.path()) | 64 | let text = file::get_text(entry.path()).unwrap(); |
66 | .unwrap(); | ||
67 | 65 | ||
68 | for test in collect_tests(&text) { | 66 | for test in collect_tests(&text) { |
69 | if let Some(old_test) = res.replace(test) { | 67 | if let Some(old_test) = res.replace(test) { |
@@ -88,7 +86,7 @@ fn collect_tests(s: &str) -> Vec<Test> { | |||
88 | let mut block = block.map(|line| &line[prefix.len()..]); | 86 | let mut block = block.map(|line| &line[prefix.len()..]); |
89 | let first = block.next().unwrap(); | 87 | let first = block.next().unwrap(); |
90 | if !first.starts_with("test ") { | 88 | if !first.starts_with("test ") { |
91 | continue | 89 | continue; |
92 | } | 90 | } |
93 | let name = first["test ".len()..].to_string(); | 91 | let name = first["test ".len()..].to_string(); |
94 | let text: String = itertools::join(block.chain(::std::iter::once("")), "\n"); | 92 | let text: String = itertools::join(block.chain(::std::iter::once("")), "\n"); |
@@ -104,7 +102,7 @@ fn existing_tests() -> HashSet<Test> { | |||
104 | let file = file.unwrap(); | 102 | let file = file.unwrap(); |
105 | let path = file.path(); | 103 | let path = file.path(); |
106 | if path.extension().unwrap_or_default() != "rs" { | 104 | if path.extension().unwrap_or_default() != "rs" { |
107 | continue | 105 | continue; |
108 | } | 106 | } |
109 | let name = path.file_name().unwrap().to_str().unwrap(); | 107 | let name = path.file_name().unwrap().to_str().unwrap(); |
110 | let name = name["0000_".len()..name.len() - 3].to_string(); | 108 | let name = name["0000_".len()..name.len() - 3].to_string(); |
@@ -130,5 +128,3 @@ fn base_dir() -> PathBuf { | |||
130 | let dir = env!("CARGO_MANIFEST_DIR"); | 128 | let dir = env!("CARGO_MANIFEST_DIR"); |
131 | PathBuf::from(dir).parent().unwrap().to_owned() | 129 | PathBuf::from(dir).parent().unwrap().to_owned() |
132 | } | 130 | } |
133 | |||
134 | |||