diff --git a/Cargo.toml b/Cargo.toml index 925d0f5..e6e9df6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,5 +11,5 @@ keywords = ["test", "fixture"] categories = ["development-tools::testing"] [dependencies] -difference = "2.0.0" +similar = "2.1.0" newline-converter = "0.2.0" diff --git a/src/lib.rs b/src/lib.rs index 44988ba..51449e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,8 +33,8 @@ //! -Ten points for Gaston //! ``` -use difference::Changeset; use newline_converter::dos2unix; +use similar::{udiff::unified_diff, Algorithm}; use std::{env, fs, path::Path}; /// Compare the contents of the file to the string provided @@ -69,9 +69,14 @@ pub fn assert_contents>(path: P, actual: &str) { let expected = dos2unix(&expected_s); if expected != actual { - let changeset = - Changeset::new(expected.as_ref(), actual.as_ref(), "\n"); - println!("{}", changeset); + let diff = unified_diff( + Algorithm::Myers, // default algorithm used by git + &expected, + &actual, + 5, // lines before and after + None, + ); + println!("{}", diff); panic!( r#"assertion failed: string doesn't match the contents of file: "{}" see diffset above set EXPECTORATE=overwrite if these changes are intentional"#, diff --git a/tests/data_a.txt b/tests/data_a.txt index fee1414..8da136d 100644 --- a/tests/data_a.txt +++ b/tests/data_a.txt @@ -2,3 +2,23 @@ A eh? a a A a aye eh. + +A eh? +a a A +a aye +eh. + +A eh? +a a A +a aye +eh. + +A eh? +a a A +a aye +eh. + +A eh? +a a A +a aye +eh. \ No newline at end of file diff --git a/tests/data_a2.txt b/tests/data_a2.txt new file mode 100644 index 0000000..a89c772 --- /dev/null +++ b/tests/data_a2.txt @@ -0,0 +1,24 @@ +A eh? +a a A +a aye +eh. + +A eh? +a a A +a aye +eh. + +A eh? +a a A +a aye +eh. + +A eh? +this line changed +a aye +eh. + +A eh? +a a A +a aye +eh. \ No newline at end of file diff --git a/tests/test_basic.rs b/tests/test_basic.rs index 62b1c93..23b6c56 100644 --- a/tests/test_basic.rs +++ b/tests/test_basic.rs @@ -14,3 +14,10 @@ fn bad() { let actual = include_str!("data_a.txt"); assert_contents("tests/data_b.txt", actual); } + +#[test] +#[should_panic] +fn one_line_change() { + let actual = include_str!("data_a.txt"); + assert_contents("tests/data_a2.txt", actual); +}