Print diffs when tests fail
This commit is contained in:
parent
20fcffb393
commit
6c4d00aad5
4 changed files with 35 additions and 10 deletions
|
|
@ -74,9 +74,7 @@ fn run() -> error::Result<()> {
|
|||
generate::generate_parser_for_grammar(&grammar_path, minimize, state_ids_to_log)?;
|
||||
println!("{}", code);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(_matches) = matches.subcommand_matches("test") {
|
||||
} else if let Some(_matches) = matches.subcommand_matches("test") {
|
||||
let corpus_path = current_dir.join("corpus");
|
||||
let home_dir = dirs::home_dir().unwrap();
|
||||
let mut loader = Loader::new(home_dir.join(".tree-sitter"));
|
||||
|
|
@ -85,9 +83,7 @@ fn run() -> error::Result<()> {
|
|||
} else {
|
||||
eprintln!("No language found");
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("parse") {
|
||||
} else if let Some(matches) = matches.subcommand_matches("parse") {
|
||||
loader.find_parsers(&vec![home_dir.join("github")])?;
|
||||
let source_path = Path::new(matches.value_of("path").unwrap());
|
||||
if let Some((language, _)) = loader.language_for_file_name(source_path)? {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use super::error::Result;
|
||||
use ansi_term::Colour;
|
||||
use difference::{Changeset, Difference};
|
||||
use regex::bytes::{Regex as ByteRegex, RegexBuilder as ByteRegexBuilder};
|
||||
use regex::Regex;
|
||||
use std::char;
|
||||
|
|
@ -55,10 +56,30 @@ pub fn run_tests_at_path(language: Language, path: &Path) -> Result<()> {
|
|||
println!("{} failures:", failures.len())
|
||||
}
|
||||
|
||||
for (name, actual, expected) in failures {
|
||||
println!("\n {}:", name);
|
||||
println!(" Expected: {}", expected);
|
||||
println!(" Actual: {}", actual);
|
||||
println!(
|
||||
"\n{} / {}",
|
||||
Colour::Green.paint("expected"),
|
||||
Colour::Red.paint("actual")
|
||||
);
|
||||
|
||||
for (i, (name, actual, expected)) in failures.iter().enumerate() {
|
||||
println!("\n {}. {}:", i + 1, name);
|
||||
let changeset = Changeset::new(actual, expected, " ");
|
||||
print!(" ");
|
||||
for diff in &changeset.diffs {
|
||||
match diff {
|
||||
Difference::Same(part) => {
|
||||
print!("{}{}", part, changeset.split);
|
||||
}
|
||||
Difference::Add(part) => {
|
||||
print!("{}{}", Colour::Green.paint(part), changeset.split);
|
||||
}
|
||||
Difference::Rem(part) => {
|
||||
print!("{}{}", Colour::Red.paint(part), changeset.split);
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue