Skip to content
Open
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
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobserver = "0.1"
mutants = "0.0.3"
nextest-metadata = "0.12.1"
num_cpus = "1.16"
patch = "0.7"
gitpatch = "0.7"
path-slash = "0.2"
quote = "1.0.35"
regex = "1.10"
Expand Down
16 changes: 3 additions & 13 deletions src/in_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
//! for example from uncommitted or unmerged changes.

use std::collections::HashMap;
use std::iter::once;

use anyhow::{anyhow, bail};
use camino::Utf8Path;
use gitpatch::{Line, Patch};
use indoc::formatdoc;
use itertools::Itertools;
use patch::{Line, Patch};
use tracing::{info, trace, warn};

use crate::mutant::Mutant;
Expand All @@ -19,22 +18,13 @@ use crate::Result;

/// Return only mutants to functions whose source was touched by this diff.
pub fn diff_filter(mutants: Vec<Mutant>, diff_text: &str) -> Result<Vec<Mutant>> {
// Strip any "Binary files .. differ" lines because `patch` doesn't understand them at
// the moment; this could be removed if it's fixed in that crate.
let fixed_diff = diff_text
.lines()
.filter(|line| !(line.starts_with("Binary files ")))
.chain(once(""))
.join("\n");

// Flatten the error to a string because otherwise it references the diff, and can't be returned.
if fixed_diff.trim().is_empty() {
if diff_text.trim().is_empty() {
info!("diff file is empty; no mutants will match");
return Ok(Vec::new());
}

let patches =
Patch::from_multiple(&fixed_diff).map_err(|err| anyhow!("Failed to parse diff: {err}"))?;
Patch::from_multiple(diff_text).map_err(|err| anyhow!("Failed to parse diff: {err}"))?;
check_diff_new_text_matches(&patches, &mutants)?;
let mut lines_changed_by_path: HashMap<&Utf8Path, Vec<usize>> = HashMap::new();
for patch in &patches {
Expand Down
2 changes: 1 addition & 1 deletion tests/in_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn binary_diff_is_not_an_error_and_matches_nothing() {
.assert()
.success()
.stdout("")
.stderr(predicate::str::contains("diff file is empty"));
.stderr("");
}

#[test]
Expand Down
Loading