Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Dec 4, 2023
2 parents 80dd6a7 + 5ddf9d3 commit d7e9149
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ A big internal refactor to allow mutations smaller than a whole function. Only o

- New: Mutate `&&` to `||` and vice versa, and mutate both of them to `==` and `!=`.

- 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.

- Changed: Include column numbers in text listings of mutants and output to disambiguate smaller-than-function mutants, for example if there are several operators that can be changed on one line. This also applies to the names used for regex matching, so may break some regexps that match the entire line (sorry). The new option `--line-col=false` turns them both off in `--list` output.

- Changed: Replaced the `function`, `line`, and `return_type` fields in the mutants json message with a `function` submessage (including the name and return type) and a `span` indicating the entire replaced region.
- Changed: In the mutants.json format, replaced the `function`, `line`, and `return_type` fields with a `function` submessage (including the name and return type) and a `span` indicating the entire replaced region, to better handle smaller-than-function mutants. Also, the `function` includes the line-column span of the entire function.

## 23.11.2

Expand All @@ -24,8 +26,6 @@ A big internal refactor to allow mutations smaller than a whole function. Only o

- Added: Accept `--manifest-path` as an alternative to `-d`, for consistency with other cargo commands.

- Changed: The json mutants format now includes a `function` sub-message, which includes the function name and return type, rather than them being direct attributes of the mutant, to better accomodate smaller-than-function mutants. Also, the `function` includes the line-column span of the entire function.

## 23.11.1

- New `--in-diff FILE` option tests only mutants that are in the diff from the
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 d7e9149

Please sign in to comment.