Skip to content

Commit

Permalink
compiletest: A more verbose matching failure for mir tests
Browse files Browse the repository at this point in the history
This makes it easier to work with mir test failures during development.

- Show which expected line was not found
- Show full expected output
- Show full actual output
  • Loading branch information
bluss committed Dec 10, 2016
1 parent dedd985 commit 90c5b71
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/tools/compiletest/src/runtest.rs
Expand Up @@ -2294,7 +2294,18 @@ actual:\n\
};
}
if !found {
panic!("ran out of mir dump output to match against");
let normalize_all = dumped_string.lines()
.map(nocomment_mir_line)
.filter(|l| !l.is_empty())
.collect::<Vec<_>>()
.join("\n");
panic!("ran out of mir dump output to match against.\n\
Did not find expected line: {:?}\n\
Expected:\n{}\n\
Actual:\n{}",
expected_line,
expected_content.join("\n"),
normalize_all);
}
}
}
Expand Down Expand Up @@ -2439,11 +2450,14 @@ enum TargetLocation {
}

fn normalize_mir_line(line: &str) -> String {
let no_comments = if let Some(idx) = line.find("//") {
nocomment_mir_line(line).replace(char::is_whitespace, "")
}

fn nocomment_mir_line(line: &str) -> &str {
if let Some(idx) = line.find("//") {
let (l, _) = line.split_at(idx);
l
l.trim_right()
} else {
line
};
no_comments.replace(char::is_whitespace, "")
}
}

0 comments on commit 90c5b71

Please sign in to comment.