dir-diff icon indicating copy to clipboard operation
dir-diff copied to clipboard

Expose a diffing iterator

Open epage opened this issue 7 years ago • 1 comments

Some example use cases

  • Report more detailed information than is_different
    • first diff
    • all diffs
    • all regular and diffs
  • Custom content comparisons
    • line-ending agnostic
    • Using the difference crate

You can look at the implementation of is_different to see how simple it is. I have a test branch of cobalt that replaces the custom directory diffing with this, augmented to use difference:

fn assert_dirs_eq(expected: &Path, actual: &Path) {
     for entry in dir_diff::DirDiff::new(expected, actual) {
        let entry = entry
            .unwrap()
            .assert_exists()
            .and_then(dir_diff::DiffEntry::assert_file_type)
            .and_then(assert_content);
        if let Err(error) = entry {
            panic!("{}", error);
        }
      }
  }

Controversial API choices

  • Prefixing the test functions with assert despite them erroring rather than panicing. I wasn't sure of a better name

Potential areas for the API to expand

  • Make it even easier to get the first or all differences
  • Make it easier to have a nice panic

Potential areas for chrome improvement

  • AssertionError's Display
  • Have a fancy feature that uses difference
    • Limit on file size?
    • Assume anything convertable to String / UTF-8 is text?
    • Use a extension crate to detect text?
    • Use a content sniffer to detect text?

epage avatar Feb 02 '18 02:02 epage

@steveklabnik This is a big change. Is it something you're wanting to look at before I submit?

epage avatar Feb 02 '18 02:02 epage