From 34ce564627cac9ca677b73f7c1291b0dec9e094a Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 4 Dec 2023 08:16:27 -0800 Subject: [PATCH 1/2] Warning not error if no mutants are found Fixes #175 --- NEWS.md | 4 ++++ src/lab.rs | 10 ++++++++-- src/visit.rs | 1 - tests/cli/main.rs | 8 +++++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index d230938d..c1133201 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # cargo-mutants changelog +## Unreleased + +- Changed: If no mutants are generated then `cargo mutants` now exits successfully, showing a warning. (Previously it would exit with an error.) This works better with `--in-diff` in CI, where it's normal that some changes may not have any mutants. + ## 23.11.2 - Changed: If `--file` or `--exclude` are set on the command line, then they replace the corresponding config file options. Similarly, if `--re` is given then the `examine_re` config key is ignored, and if `--exclude-re` is given then `exclude_regex` is ignored. (Previously the values were combined.) This makes it easier to use the command line to test files or mutants that are normally not tested. diff --git a/src/lab.rs b/src/lab.rs index e1eada8c..949023a3 100644 --- a/src/lab.rs +++ b/src/lab.rs @@ -7,7 +7,7 @@ use std::sync::Mutex; use std::thread; use std::time::{Duration, Instant}; -use anyhow::{ensure, Result}; +use anyhow::Result; use itertools::Itertools; use tracing::warn; #[allow(unused)] @@ -22,6 +22,9 @@ use crate::*; /// Run all possible mutation experiments. /// +/// This is called after all filtering is complete, so all the mutants here will be tested +/// or checked. +/// /// Before testing the mutants, the lab checks that the source tree passes its tests with no /// mutations applied. pub fn test_mutants( @@ -43,7 +46,10 @@ pub fn test_mutants( } output_dir.write_mutants_list(&mutants)?; console.discovered_mutants(&mutants); - ensure!(!mutants.is_empty(), "No mutants found"); + if mutants.is_empty() { + warn!("No mutants found under the active filters"); + return Ok(LabOutcome::default()); + } let all_packages = mutants.iter().map(|m| m.package()).unique().collect_vec(); debug!(?all_packages); diff --git a/src/visit.rs b/src/visit.rs index 680cf31e..005128f3 100644 --- a/src/visit.rs +++ b/src/visit.rs @@ -41,7 +41,6 @@ pub fn walk_tree( options: &Options, console: &Console, ) -> Result { - // TODO: Lift up parsing the error expressions... let error_exprs = options .error_values .iter() diff --git a/tests/cli/main.rs b/tests/cli/main.rs index a33f2ef5..3b4b5f5f 100644 --- a/tests/cli/main.rs +++ b/tests/cli/main.rs @@ -657,15 +657,17 @@ fn integration_test_source_is_not_mutated() { check_text_list_output(tmp_src_dir.path(), "integration_test_source_is_not_mutated"); } #[test] -fn error_when_no_mutants_found() { +fn warning_when_no_mutants_found() { let tmp_src_dir = copy_of_testdata("everything_skipped"); run() .args(["mutants", "--check", "--no-times", "--no-shuffle"]) .current_dir(tmp_src_dir.path()) .assert() - .stderr(predicate::str::contains("Error: No mutants found")) + .stderr(predicate::str::contains( + "No mutants found under the active filters", + )) .stdout(predicate::str::contains("Found 0 mutants to test")) - .failure(); + .success(); // It's arguable, but better if CI doesn't fail in this case. } #[test] From 235be7ee1586adbac9608aa26ccd09feabe8fd19 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 4 Dec 2023 08:18:22 -0800 Subject: [PATCH 2/2] Rename job to "pr-mutants" We might use the name "incremental" for iterating on failing mutants --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 955e0440..d4e64991 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -47,7 +47,7 @@ jobs: - name: Test run: cargo test --workspace - incremental-mutants: + pr-mutants: runs-on: ubuntu-latest if: github.event_name == 'pull_request' steps: