From 66be735aa98c32fb062d1c756fa9303ff2d13002 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 12 Aug 2018 18:50:16 +0300 Subject: flip comma --- crates/libsyntax2/tests/test/main.rs | 48 +++++++++++++++--------------------- 1 file changed, 20 insertions(+), 28 deletions(-) (limited to 'crates/libsyntax2/tests') diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs index 18e5bc4d4..64d080dfd 100644 --- a/crates/libsyntax2/tests/test/main.rs +++ b/crates/libsyntax2/tests/test/main.rs @@ -1,5 +1,6 @@ extern crate libsyntax2; -extern crate difference; +#[macro_use] +extern crate assert_eq_text; use std::{ fs, @@ -7,8 +8,6 @@ use std::{ fmt::Write, }; -use difference::Changeset; - #[test] fn lexer_tests() { dir_tests(&["lexer"], |text| { @@ -63,10 +62,26 @@ pub fn dir_tests(paths: &[&str], f: F) } } +const REWRITE: bool = false; + fn assert_equal_text(expected: &str, actual: &str, path: &Path) { - if expected != actual { - print_difference(expected, actual, path) + if expected == actual { + return; + } + let dir = project_dir(); + let path = path.strip_prefix(&dir).unwrap_or_else(|_| path); + if expected.trim() == actual.trim() { + println!("whitespace difference, rewriting"); + println!("file: {}\n", path.display()); + fs::write(path, actual).unwrap(); + return; + } + if REWRITE { + println!("rewriting {}", path.display()); + fs::write(path, actual).unwrap(); + return; } + assert_eq_text!(expected, actual, "file: {}", path.display()); } fn collect_tests(paths: &[&str]) -> Vec { @@ -92,29 +107,6 @@ fn test_from_dir(dir: &Path) -> Vec { acc } -const REWRITE: bool = false; - -fn print_difference(expected: &str, actual: &str, path: &Path) { - let dir = project_dir(); - let path = path.strip_prefix(&dir).unwrap_or_else(|_| path); - if expected.trim() == actual.trim() { - println!("whitespace difference, rewriting"); - println!("file: {}\n", path.display()); - fs::write(path, actual).unwrap(); - return; - } - if REWRITE { - println!("rewriting {}", path.display()); - fs::write(path, actual).unwrap(); - return; - } - let changeset = Changeset::new(actual, expected, "\n"); - println!("Expected:\n{}\n\nActual:\n{}\n", expected, actual); - print!("{}", changeset); - println!("file: {}\n", path.display()); - panic!("Comparison failed") -} - fn project_dir() -> PathBuf { let dir = env!("CARGO_MANIFEST_DIR"); PathBuf::from(dir) -- cgit v1.2.3