Skip to content

Commit

Permalink
Don't error if in-diff contains multiple deletions (#220)
Browse files Browse the repository at this point in the history
Fixes `Error: Patch input contains repeated filename: "/dev/null"` #219
  • Loading branch information
sourcefrog authored Jan 2, 2024
2 parents 9ccf645 + 751e4a1 commit a8873f1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# cargo-mutants changelog

## Unreleased

- Fixed: Fixed spurious "Patch input contains repeated filenames" error when `--in-diff` is given a patch that deletes multiple files.

## 23.12.2

- New: A `--shard k/n` allows you to split the work across n independent parallel `cargo mutants` invocations running on separate machines to get a faster overall solution on large suites. You, or your CI system, are responsible for launching all the shards and checking whether any of them failed.
Expand Down
4 changes: 4 additions & 0 deletions src/in_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub fn diff_filter(mutants: Vec<Mutant>, diff_text: &str) -> Result<Vec<Mutant>>
let mut lines_changed_by_path: HashMap<&Utf8Path, Vec<usize>> = HashMap::new();
for patch in &patches {
let path = strip_patch_path(&patch.new.path);
if path == "/dev/null" {
// The file was deleted; we can't possibly match anything in it.
continue;
}
if lines_changed_by_path
.insert(path, affected_lines(patch))
.is_some()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ src/fnvalue.rs: replace == with != in match_first_type_arg
src/in_diff.rs: replace diff_filter -> Result<Vec<Mutant>> with Ok(vec![])
src/in_diff.rs: replace diff_filter -> Result<Vec<Mutant>> with Ok(vec![Default::default()])
src/in_diff.rs: replace diff_filter -> Result<Vec<Mutant>> with Err(::anyhow::anyhow!("mutated!"))
src/in_diff.rs: replace == with != in diff_filter
src/in_diff.rs: replace check_diff_new_text_matches -> Result<()> with Ok(())
src/in_diff.rs: replace check_diff_new_text_matches -> Result<()> with Err(::anyhow::anyhow!("mutated!"))
src/in_diff.rs: replace != with == in check_diff_new_text_matches
Expand Down
39 changes: 39 additions & 0 deletions tests/cli/in_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,42 @@ fn mismatched_diff_causes_error() {
"Diff content doesn't match source file: src/lib.rs",
));
}

/// If the diff contains multiple deletions (with a new filename of /dev/null),
/// don't fail.
///
/// <https://github.com/sourcefrog/cargo-mutants/issues/219>
#[test]
fn diff_with_multiple_deletions_is_ok() {
let diff = indoc! {r#"
diff --git a/src/monitor/collect.rs b/src/monitor/collect.rs
deleted file mode 100644
index d842cf9..0000000
--- a/src/monitor/collect.rs
+++ /dev/null
@@ -1,1 +0,0 @@
-// Some stuff
diff --git a/src/monitor/another.rs b/src/monitor/another.rs
deleted file mode 100644
index d842cf9..0000000
--- a/src/monitor/collect.rs
+++ /dev/null
@@ -1,1 +0,0 @@
-// More stuff
"#};
let mut diff_file = NamedTempFile::new().unwrap();
diff_file.write_all(diff.as_bytes()).unwrap();

let tmp = copy_of_testdata("diff1");

run()
.args(["mutants", "--no-shuffle", "-d"])
.arg(tmp.path())
.arg("--in-diff")
.arg(diff_file.path())
.assert()
.stderr(predicates::str::contains(
"No mutants found under the active filters",
))
.success();
}

0 comments on commit a8873f1

Please sign in to comment.