-
-
Notifications
You must be signed in to change notification settings - Fork 46
Honour #[mutants::skip] on block expressions #618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sandersaares
wants to merge
12
commits into
sourcefrog:main
Choose a base branch
from
sandersaares:skip-attr-block
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
be28543
Honour #[mutants::skip] on block expressions
sandersaares 08e6f28
Add testdata integration test for #[mutants::skip] on block expressions
sandersaares 8756788
Recognise function-style cfg predicates inside cfg_attr(mutants::skip)
sandersaares aa7c70c
Document the cfg_attr(any(), ...) trick more thoroughly
sandersaares ba4ecd3
Make skip-on-expressions testdata nightly-only via mutants_nightly cfg
sandersaares fdf71d6
Merge remote-tracking branch 'upstream/main' into skip-attr-block
sandersaares e6777b6
NEWS: refer to the mutants::skip attribute directly
sandersaares 862804c
Add testdata integration test for #[mutants::skip] on non-block expre…
sandersaares 4a1394d
Potential fix for pull request finding
sandersaares 817e748
Drop duplicative skip-attr integration tests
sandersaares adaa151
Merge remote-tracking branch 'origin/main' into skip-attr-block
sandersaares 4a90405
Honour mutants::exclude_re in cfg_attr with non-trivial predicates
sandersaares File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| //! Tests that `#[mutants::skip]` on a block expression `{ ... }` suppresses | ||
| //! mutants generated inside that block, while sibling code in the same | ||
| //! function remains mutated. | ||
|
|
||
| use indoc::indoc; | ||
| use test_log::test; | ||
|
|
||
| use crate::Options; | ||
| use crate::visit::mutate_source_str; | ||
|
|
||
| #[test] | ||
| fn skip_attr_on_statement_position_block_suppresses_nested_mutants() { | ||
| let mutants = mutate_source_str( | ||
| indoc! {r#" | ||
| fn driver(a: i32, b: i32, c: i32, d: i32) { | ||
| #[mutants::skip] | ||
| { | ||
| let _ = a + b; | ||
| } | ||
| let _ = c - d; | ||
| } | ||
| "#}, | ||
| &Options::default(), | ||
| ) | ||
| .unwrap(); | ||
| let names: Vec<String> = mutants.iter().map(|m| m.name(false)).collect(); | ||
|
|
||
| assert!( | ||
| !names.iter().any(|n| n.contains("replace + with")), | ||
| "`+` inside skipped block should not produce mutants: {names:?}" | ||
| ); | ||
| assert!( | ||
| names.iter().any(|n| n.contains("replace - with")), | ||
| "`-` in the unannotated sibling code should still produce mutants: {names:?}" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn skip_attr_on_expression_position_block_suppresses_nested_mutants() { | ||
| let mutants = mutate_source_str( | ||
| indoc! {r#" | ||
| fn driver(a: i32, b: i32, c: i32, d: i32) -> i32 { | ||
| let x = #[mutants::skip] { | ||
| a + b | ||
| }; | ||
| let y = { | ||
| c - d | ||
| }; | ||
| x | y | ||
| } | ||
| "#}, | ||
| &Options::default(), | ||
| ) | ||
| .unwrap(); | ||
| let names: Vec<String> = mutants.iter().map(|m| m.name(false)).collect(); | ||
|
|
||
| assert!( | ||
| !names.iter().any(|n| n.contains("replace + with")), | ||
| "`+` inside skipped block should not produce mutants: {names:?}" | ||
| ); | ||
| assert!( | ||
| names.iter().any(|n| n.contains("replace - with")), | ||
| "`-` in the unannotated sibling block should still produce mutants: {names:?}" | ||
| ); | ||
| assert!( | ||
| names.iter().any(|n| n.contains("replace | with")), | ||
| "`|` in the unannotated tail expression should still produce mutants: {names:?}" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn skip_attr_on_block_suppresses_all_genres_within() { | ||
| let mutants = mutate_source_str( | ||
| indoc! {r#" | ||
| fn pick(x: i32, y: i32) -> &'static str { | ||
| #[mutants::skip] | ||
| { | ||
| let _ = !true; | ||
| match x { | ||
| 0 => "zero", | ||
| n if n > y => "gt", | ||
| _ => "other", | ||
| } | ||
| } | ||
| } | ||
| "#}, | ||
| &Options::default(), | ||
| ) | ||
| .unwrap(); | ||
| let names: Vec<String> = mutants.iter().map(|m| m.name(false)).collect(); | ||
|
|
||
| assert!( | ||
| !names.iter().any(|n| n.contains("delete !")), | ||
| "unary mutants inside skipped block should be suppressed: {names:?}" | ||
| ); | ||
| assert!( | ||
| !names.iter().any(|n| n.contains("delete match arm")), | ||
| "match arm deletion mutants inside skipped block should be suppressed: {names:?}" | ||
| ); | ||
| assert!( | ||
| !names.iter().any(|n| n.contains("replace match guard")), | ||
| "match guard mutants inside skipped block should be suppressed: {names:?}" | ||
| ); | ||
| assert!( | ||
| !names.iter().any(|n| n.contains("replace > with")), | ||
| "binary mutants inside skipped block should be suppressed: {names:?}" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn skip_attr_on_labeled_block_suppresses_nested_mutants() { | ||
| let mutants = mutate_source_str( | ||
| indoc! {r#" | ||
| fn driver(a: i32, b: i32) -> i32 { | ||
| #[mutants::skip] | ||
| 'block: { | ||
| if a > b { | ||
| break 'block a + b; | ||
| } | ||
| a - b | ||
| } | ||
| } | ||
| "#}, | ||
| &Options::default(), | ||
| ) | ||
| .unwrap(); | ||
| let names: Vec<String> = mutants.iter().map(|m| m.name(false)).collect(); | ||
|
|
||
| assert!( | ||
| !names.iter().any(|n| n.contains("replace + with")), | ||
| "`+` inside skipped labeled block should not produce mutants: {names:?}" | ||
| ); | ||
| assert!( | ||
| !names.iter().any(|n| n.contains("replace - with")), | ||
| "`-` inside skipped labeled block should not produce mutants: {names:?}" | ||
| ); | ||
| assert!( | ||
| !names.iter().any(|n| n.contains("replace > with")), | ||
| "`>` inside skipped labeled block should not produce mutants: {names:?}" | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.