Print diffs when tests fail
This commit is contained in:
parent
20fcffb393
commit
6c4d00aad5
4 changed files with 35 additions and 10 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -156,6 +156,11 @@ dependencies = [
|
|||
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "difference"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "1.0.4"
|
||||
|
|
@ -643,6 +648,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hashbrown 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ignore 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
@ -764,6 +770,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum crossbeam-epoch 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2449aaa4ec7ef96e5fb24db16024b935df718e9ae1cec0a1e68feeca2efca7b8"
|
||||
"checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015"
|
||||
"checksum crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c55913cc2799171a550e307918c0a360e8c16004820291bf3b638969b4a01816"
|
||||
"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
|
||||
"checksum dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "88972de891f6118092b643d85a0b28e0678e0f948d7f879aa32f2d5aafe97d2a"
|
||||
"checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7"
|
||||
"checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596"
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ path = "src/main.rs"
|
|||
|
||||
[dependencies]
|
||||
ansi_term = "0.11"
|
||||
difference = "2.0"
|
||||
lazy_static = "1.2.0"
|
||||
smallbitvec = "2.3.0"
|
||||
clap = "2.32"
|
||||
|
|
|
|||
|
|
@ -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