Skip to content

Commit

Permalink
changed: The mutant name for trait impls now includes the path of the…
Browse files Browse the repository at this point in the history
… trait as it occurs in the source file: for example `impl fmt::Display for Foo`.
  • Loading branch information
sourcefrog committed Nov 18, 2024
1 parent aca4ae3 commit a9866f9
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 22 deletions.
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: `--skip-calls=NAME,NAME` on the command line or `skip_calls = [NAMES..]` in `.cargo/mutants.toml` allows configuring other functions whose calls should never be mutated.

- Changed: The mutant name for trait impls now includes the path of the trait as it occurs in the source file: for example `impl fmt::Display for Foo`.

## 24.11.0

- New: `--test-workspace` and `--test-package` arguments and config options support projects whose tests live in a different package.
Expand Down
3 changes: 1 addition & 2 deletions src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,7 @@ impl<'ast> Visit<'ast> for DiscoveryVisitor<'_> {
// Can't think of how to generate a viable different default.
return;
}
format!("<impl {trait} for {type_name}>", trait = trait_path.segments.last().unwrap().ident)
// TODO: trait = trait_path.to_pretty_string()) and update tests to match
format!("<impl {trait} for {type_name}>", trait = trait_path.to_pretty_string())
} else {
type_name
};
Expand Down
6 changes: 2 additions & 4 deletions tests/snapshots/list__list_mutants_in_all_trees_as_json.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6628,7 +6628,7 @@ expression: buf
{
"file": "src/methods.rs",
"function": {
"function_name": "<impl Display for Foo>::fmt",
"function_name": "<impl fmt::Display for Foo>::fmt",
"return_type": "-> fmt::Result",
"span": {
"end": {
Expand Down Expand Up @@ -6658,7 +6658,7 @@ expression: buf
{
"file": "src/methods.rs",
"function": {
"function_name": "<impl Debug for &Foo>::fmt",
"function_name": "<impl fmt::Debug for &Foo>::fmt",
"return_type": "-> fmt::Result",
"span": {
"end": {
Expand Down Expand Up @@ -9842,5 +9842,3 @@ expression: buf
}
]
```


6 changes: 2 additions & 4 deletions tests/snapshots/list__list_mutants_in_all_trees_as_text.snap
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ src/inside_mod.rs:4:13: replace outer::inner::name -> &'static str with "xyzzy"
src/methods.rs:17:9: replace Foo::double with ()
src/methods.rs:17:16: replace *= with += in Foo::double
src/methods.rs:17:16: replace *= with /= in Foo::double
src/methods.rs:23:9: replace <impl Display for Foo>::fmt -> fmt::Result with Ok(Default::default())
src/methods.rs:29:9: replace <impl Debug for &Foo>::fmt -> fmt::Result with Ok(Default::default())
src/methods.rs:23:9: replace <impl fmt::Display for Foo>::fmt -> fmt::Result with Ok(Default::default())
src/methods.rs:29:9: replace <impl fmt::Debug for &Foo>::fmt -> fmt::Result with Ok(Default::default())
src/nested_function.rs:2:5: replace has_nested -> u32 with 0
src/nested_function.rs:2:5: replace has_nested -> u32 with 1
src/nested_function.rs:3:9: replace has_nested::inner -> u32 with 0
Expand Down Expand Up @@ -545,5 +545,3 @@ main2/src/main.rs:10:5: replace triple_3 -> i32 with 0
main2/src/main.rs:10:5: replace triple_3 -> i32 with 1
main2/src/main.rs:10:5: replace triple_3 -> i32 with -1
```
4 changes: 2 additions & 2 deletions tests/snapshots/main__well_tested_tree_check_only.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ ok src/inside_mod.rs:4:13: replace outer::inner::name -> &'static str with
ok src/methods.rs:17:9: replace Foo::double with ()
ok src/methods.rs:17:16: replace *= with += in Foo::double
ok src/methods.rs:17:16: replace *= with /= in Foo::double
ok src/methods.rs:23:9: replace <impl Display for Foo>::fmt -> fmt::Result with Ok(Default::default())
ok src/methods.rs:29:9: replace <impl Debug for &Foo>::fmt -> fmt::Result with Ok(Default::default())
ok src/methods.rs:23:9: replace <impl fmt::Display for Foo>::fmt -> fmt::Result with Ok(Default::default())
ok src/methods.rs:29:9: replace <impl fmt::Debug for &Foo>::fmt -> fmt::Result with Ok(Default::default())
ok src/nested_function.rs:2:5: replace has_nested -> u32 with 0
ok src/nested_function.rs:2:5: replace has_nested -> u32 with 1
ok src/nested_function.rs:3:9: replace has_nested::inner -> u32 with 0
Expand Down
4 changes: 2 additions & 2 deletions tests/snapshots/main__well_tested_tree_finds_no_problems.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ caught src/inside_mod.rs:4:13: replace outer::inner::name -> &'static str with
caught src/methods.rs:17:9: replace Foo::double with ()
caught src/methods.rs:17:16: replace *= with += in Foo::double
caught src/methods.rs:17:16: replace *= with /= in Foo::double
caught src/methods.rs:23:9: replace <impl Display for Foo>::fmt -> fmt::Result with Ok(Default::default())
caught src/methods.rs:29:9: replace <impl Debug for &Foo>::fmt -> fmt::Result with Ok(Default::default())
caught src/methods.rs:23:9: replace <impl fmt::Display for Foo>::fmt -> fmt::Result with Ok(Default::default())
caught src/methods.rs:29:9: replace <impl fmt::Debug for &Foo>::fmt -> fmt::Result with Ok(Default::default())
caught src/nested_function.rs:2:5: replace has_nested -> u32 with 0
caught src/nested_function.rs:2:5: replace has_nested -> u32 with 1
caught src/nested_function.rs:3:9: replace has_nested::inner -> u32 with 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ src/inside_mod.rs:4:13: replace outer::inner::name -> &'static str with "xyzzy"
src/methods.rs:17:9: replace Foo::double with ()
src/methods.rs:17:16: replace *= with += in Foo::double
src/methods.rs:17:16: replace *= with /= in Foo::double
src/methods.rs:23:9: replace <impl Display for Foo>::fmt -> fmt::Result with Ok(Default::default())
src/methods.rs:29:9: replace <impl Debug for &Foo>::fmt -> fmt::Result with Ok(Default::default())
src/methods.rs:23:9: replace <impl fmt::Display for Foo>::fmt -> fmt::Result with Ok(Default::default())
src/methods.rs:29:9: replace <impl fmt::Debug for &Foo>::fmt -> fmt::Result with Ok(Default::default())
src/nested_function.rs:2:5: replace has_nested -> u32 with 0
src/nested_function.rs:2:5: replace has_nested -> u32 with 1
src/nested_function.rs:3:9: replace has_nested::inner -> u32 with 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ expression: "String::from_utf8_lossy(&output.stdout)"
{
"file": "src/methods.rs",
"function": {
"function_name": "<impl Display for Foo>::fmt",
"function_name": "<impl fmt::Display for Foo>::fmt",
"return_type": "-> fmt::Result",
"span": {
"end": {
Expand Down Expand Up @@ -636,7 +636,7 @@ expression: "String::from_utf8_lossy(&output.stdout)"
{
"file": "src/methods.rs",
"function": {
"function_name": "<impl Debug for &Foo>::fmt",
"function_name": "<impl fmt::Debug for &Foo>::fmt",
"return_type": "-> fmt::Result",
"span": {
"end": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ src/inside_mod.rs:4:13: replace outer::inner::name -> &'static str with "xyzzy"
src/methods.rs:17:9: replace Foo::double with ()
src/methods.rs:17:16: replace *= with += in Foo::double
src/methods.rs:17:16: replace *= with /= in Foo::double
src/methods.rs:23:9: replace <impl Display for Foo>::fmt -> fmt::Result with Ok(Default::default())
src/methods.rs:29:9: replace <impl Debug for &Foo>::fmt -> fmt::Result with Ok(Default::default())
src/methods.rs:23:9: replace <impl fmt::Display for Foo>::fmt -> fmt::Result with Ok(Default::default())
src/methods.rs:29:9: replace <impl fmt::Debug for &Foo>::fmt -> fmt::Result with Ok(Default::default())
src/nested_function.rs:2:5: replace has_nested -> u32 with 0
src/nested_function.rs:2:5: replace has_nested -> u32 with 1
src/nested_function.rs:3:9: replace has_nested::inner -> u32 with 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ src/inside_mod.rs:4:13: replace outer::inner::name -> &'static str with "xyzzy"
src/methods.rs:17:9: replace Foo::double with ()
src/methods.rs:17:16: replace *= with += in Foo::double
src/methods.rs:17:16: replace *= with /= in Foo::double
src/methods.rs:23:9: replace <impl Display for Foo>::fmt -> fmt::Result with Ok(Default::default())
src/methods.rs:29:9: replace <impl Debug for &Foo>::fmt -> fmt::Result with Ok(Default::default())
src/methods.rs:23:9: replace <impl fmt::Display for Foo>::fmt -> fmt::Result with Ok(Default::default())
src/methods.rs:29:9: replace <impl fmt::Debug for &Foo>::fmt -> fmt::Result with Ok(Default::default())
src/nested_function.rs:2:5: replace has_nested -> u32 with 0
src/nested_function.rs:2:5: replace has_nested -> u32 with 1
src/nested_function.rs:3:9: replace has_nested::inner -> u32 with 0
Expand Down

0 comments on commit a9866f9

Please sign in to comment.