Fix compilation for real

This commit is contained in:
Aleksey Kladov 2018-07-30 16:32:27 +03:00
parent 67424000a9
commit 69c385e810
3 changed files with 6 additions and 7 deletions

View File

@ -55,12 +55,12 @@ fn read_stdin() -> Result<String> {
fn render_test(file: &Path, line: usize) -> Result<(String, String)> {
let text = fs::read_to_string(file)?;
let tests = collect_tests(&text);
let test = tests.into_iter().find(|t| {
t.start_line <= line && line <= t.start_line + t.text.lines().count()
let test = tests.into_iter().find(|(start_line, t)| {
*start_line <= line && line <= *start_line + t.text.lines().count()
});
let test = match test {
None => bail!("No test found at line {} at {}", line, file.display()),
Some(test) => test,
Some((_start_line, test)) => test,
};
let file = libsyntax2::parse(test.text.clone());
let tree = libsyntax2::utils::dump_tree(&file);

View File

@ -5,7 +5,6 @@ use itertools::Itertools;
#[derive(Debug, Eq)]
pub struct Test {
pub start_line: usize,
pub name: String,
pub text: String,
}
@ -22,7 +21,7 @@ impl hash::Hash for Test {
}
}
pub fn collect_tests(s: &str) -> Vec<Test> {
pub fn collect_tests(s: &str) -> Vec<(usize, Test)> {
let mut res = vec![];
let prefix = "// ";
let comment_blocks = s
@ -52,7 +51,7 @@ pub fn collect_tests(s: &str) -> Vec<Test> {
"\n"
);
assert!(!text.trim().is_empty() && text.ends_with("\n"));
res.push(Test { start_line, name, text })
res.push((start_line, Test {name, text }))
}
res
}

View File

@ -108,7 +108,7 @@ fn tests_from_dir(dir: &Path) -> Result<HashSet<Test>> {
}
let text = fs::read_to_string(entry.path())?;
for test in collect_tests(&text) {
for (_, test) in collect_tests(&text) {
if let Some(old_test) = res.replace(test) {
bail!("Duplicate test: {}", old_test.name)
}