Skip to content

Commit

Permalink
Warning not error if no mutants are found (#176)
Browse files Browse the repository at this point in the history
Fixes #175
  • Loading branch information
sourcefrog authored Dec 4, 2023
2 parents ab06125 + 34ce564 commit 7ec81d4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 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

- 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

A big internal refactor to allow mutations smaller than a whole function. Only one pattern is added in this release, mutation of `==` operators, but many more are possible.
Expand Down
10 changes: 8 additions & 2 deletions src/lab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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(
Expand All @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub fn walk_tree(
options: &Options,
console: &Console,
) -> Result<Discovered> {
// TODO: Lift up parsing the error expressions...
let error_exprs = options
.error_values
.iter()
Expand Down
8 changes: 5 additions & 3 deletions tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,15 +666,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]
Expand Down

0 comments on commit 7ec81d4

Please sign in to comment.