aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-02-03 19:41:52 +0000
committerAleksey Kladov <[email protected]>2018-02-03 19:41:52 +0000
commita5a6973df68a99a19176c717a337d5cdbf7c5629 (patch)
tree1e3a55035197907c6ae1f7815b1be8bf8bb33ae2 /tools
parent2fd3228525858f594361eba345ff31087f8a917a (diff)
fmt
Diffstat (limited to 'tools')
-rw-r--r--tools/src/bin/collect-tests.rs18
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 @@
1extern crate file; 1extern crate file;
2extern crate walkdir;
3extern crate itertools; 2extern crate itertools;
3extern crate walkdir;
4 4
5use walkdir::WalkDir; 5use walkdir::WalkDir;
6use itertools::Itertools; 6use itertools::Itertools;
7 7
8use std::path::{PathBuf, Path}; 8use std::path::{Path, PathBuf};
9use std::collections::HashSet; 9use std::collections::HashSet;
10use std::fs; 10use 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)]
38struct Test { 37struct 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