Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't error if in-diff contains multiple deletions #220

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}