diff options
-rw-r--r-- | cli/src/main.rs | 6 | ||||
-rw-r--r-- | tools/src/lib.rs | 5 | ||||
-rw-r--r-- | tools/src/main.rs | 2 |
3 files changed, 6 insertions, 7 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs index 94183c552..f87878137 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs | |||
@@ -55,12 +55,12 @@ fn read_stdin() -> Result<String> { | |||
55 | fn render_test(file: &Path, line: usize) -> Result<(String, String)> { | 55 | fn render_test(file: &Path, line: usize) -> Result<(String, String)> { |
56 | let text = fs::read_to_string(file)?; | 56 | let text = fs::read_to_string(file)?; |
57 | let tests = collect_tests(&text); | 57 | let tests = collect_tests(&text); |
58 | let test = tests.into_iter().find(|t| { | 58 | let test = tests.into_iter().find(|(start_line, t)| { |
59 | t.start_line <= line && line <= t.start_line + t.text.lines().count() | 59 | *start_line <= line && line <= *start_line + t.text.lines().count() |
60 | }); | 60 | }); |
61 | let test = match test { | 61 | let test = match test { |
62 | None => bail!("No test found at line {} at {}", line, file.display()), | 62 | None => bail!("No test found at line {} at {}", line, file.display()), |
63 | Some(test) => test, | 63 | Some((_start_line, test)) => test, |
64 | }; | 64 | }; |
65 | let file = libsyntax2::parse(test.text.clone()); | 65 | let file = libsyntax2::parse(test.text.clone()); |
66 | let tree = libsyntax2::utils::dump_tree(&file); | 66 | let tree = libsyntax2::utils::dump_tree(&file); |
diff --git a/tools/src/lib.rs b/tools/src/lib.rs index 1b7ef3ca9..7a0de3e3c 100644 --- a/tools/src/lib.rs +++ b/tools/src/lib.rs | |||
@@ -5,7 +5,6 @@ use itertools::Itertools; | |||
5 | 5 | ||
6 | #[derive(Debug, Eq)] | 6 | #[derive(Debug, Eq)] |
7 | pub struct Test { | 7 | pub struct Test { |
8 | pub start_line: usize, | ||
9 | pub name: String, | 8 | pub name: String, |
10 | pub text: String, | 9 | pub text: String, |
11 | } | 10 | } |
@@ -22,7 +21,7 @@ impl hash::Hash for Test { | |||
22 | } | 21 | } |
23 | } | 22 | } |
24 | 23 | ||
25 | pub fn collect_tests(s: &str) -> Vec<Test> { | 24 | pub fn collect_tests(s: &str) -> Vec<(usize, Test)> { |
26 | let mut res = vec![]; | 25 | let mut res = vec![]; |
27 | let prefix = "// "; | 26 | let prefix = "// "; |
28 | let comment_blocks = s | 27 | let comment_blocks = s |
@@ -52,7 +51,7 @@ pub fn collect_tests(s: &str) -> Vec<Test> { | |||
52 | "\n" | 51 | "\n" |
53 | ); | 52 | ); |
54 | assert!(!text.trim().is_empty() && text.ends_with("\n")); | 53 | assert!(!text.trim().is_empty() && text.ends_with("\n")); |
55 | res.push(Test { start_line, name, text }) | 54 | res.push((start_line, Test {name, text })) |
56 | } | 55 | } |
57 | res | 56 | res |
58 | } | 57 | } |
diff --git a/tools/src/main.rs b/tools/src/main.rs index 783e3395b..6786b81ca 100644 --- a/tools/src/main.rs +++ b/tools/src/main.rs | |||
@@ -108,7 +108,7 @@ fn tests_from_dir(dir: &Path) -> Result<HashSet<Test>> { | |||
108 | } | 108 | } |
109 | let text = fs::read_to_string(entry.path())?; | 109 | let text = fs::read_to_string(entry.path())?; |
110 | 110 | ||
111 | for test in collect_tests(&text) { | 111 | for (_, test) in collect_tests(&text) { |
112 | if let Some(old_test) = res.replace(test) { | 112 | if let Some(old_test) = res.replace(test) { |
113 | bail!("Duplicate test: {}", old_test.name) | 113 | bail!("Duplicate test: {}", old_test.name) |
114 | } | 114 | } |