Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 53-iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Aug 18, 2024
2 parents ad73960 + 41eab78 commit e225028
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 20 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/release-book.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Publish the book to https://mutants.rs/ when a new release is created.
name: Release book
on:
release:
types:
- published
- released
workflow_dispatch:
push:
branches:
- main

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,13 @@ jobs:
with:
name: mutants-${{matrix.test_tool}}-shard${{matrix.shard}}.out
path: mutants.out

typos:
name: Spell check with Typos
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check spelling
uses: crate-ci/typos@master
13 changes: 0 additions & 13 deletions .github/workflows/typos.yml

This file was deleted.

2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- New: cargo-mutants starts a GNU jobserver, shared across all children, so that running multiple `--jobs` does not spawn an excessive number of compiler processes. The jobserver is on by default and can be turned off with `--jobserver false`.

- Fixed: Don't error on diffs containing a "Binary files differ" message.

## 24.7.1

- Changed: No build timeouts by default. Previously, cargo-mutants set a default build timeout based on the baseline build, but experience showed that this would sometimes make builds flaky, because build times can be quite variable. If mutants cause builds to hang, then you can still set a timeout using `--build-timeout` or `--build-timeout-multiplier`.
Expand Down
14 changes: 12 additions & 2 deletions src/in_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! for example from uncommitted or unmerged changes.
use std::collections::HashMap;
use std::iter::once;

use anyhow::{anyhow, bail};
use camino::Utf8Path;
Expand All @@ -18,13 +19,22 @@ 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 diff_text.trim().is_empty() {
if fixed_diff.trim().is_empty() {
info!("diff file is empty; no mutants will match");
return Ok(Vec::new());
}

let patches =
Patch::from_multiple(diff_text).map_err(|err| anyhow!("Failed to parse diff: {err}"))?;
Patch::from_multiple(&fixed_diff).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
18 changes: 18 additions & 0 deletions tests/in_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ fn list_mutants_changed_in_diff1() {
);
}

#[test]
fn binary_diff_is_not_an_error_and_matches_nothing() {
// From https://github.com/sourcefrog/cargo-mutants/issues/391
let mut diff_file = NamedTempFile::new().unwrap();
diff_file.write_all(b"Binary files a/test-renderers/expected/renderers/fog-None-wgpu.png and b/test-renderers/expected/renderers/fog-None-wgpu.png differ\n").unwrap();
let tmp = copy_of_testdata("diff1");
run()
.args(["mutants", "--no-shuffle", "-d"])
.arg(tmp.path())
.arg("--in-diff")
.arg(diff_file.path())
.arg("--list")
.assert()
.success()
.stdout("")
.stderr(predicate::str::contains("diff file is empty"));
}

#[test]
fn empty_diff_is_not_an_error_and_matches_nothing() {
let diff_file = NamedTempFile::new().unwrap();
Expand Down

0 comments on commit e225028

Please sign in to comment.