Commit 3d00bf9
Skip functions with
Fixes functions annotated with async testing framework attributes like
`#[tokio::test]`, `#[sqlx::test]`, and similar being incorrectly
mutated.
## Problem
Previously, cargo-mutants only skipped functions with the exact
`#[test]` attribute. This meant that test functions using async testing
frameworks were being mutated, leading to false positives. For example:
```rust
#[test]
fn test() {
println!("Hello") // ✅ Correctly skipped
}
#[tokio::test]
async fn tokio_test() {
println!("Hello") // ❌ Was being mutated (incorrect)
}
```
## Solution
Generalized the test attribute detection to match any attribute whose
path ends with `test`. This is consistent with the project's goal of
"doing something reasonable on most Rust trees without needing any
setup" since Tokio, sqlx, and similar testing frameworks are widely used
in the Rust ecosystem.
The implementation now uses the existing `path_ends_with()` helper
function to check if an attribute path ends with `test`, which matches:
- `#[test]` (standard test attribute)
- `#[tokio::test]` (Tokio async tests)
- `#[sqlx::test]` (sqlx database tests)
- `#[any_framework::test]` (any testing framework following this
convention)
## Changes
- Modified `attr_is_test()` in `src/visit.rs` to use `path_ends_with()`
instead of exact identifier matching
- Added 5 comprehensive tests verifying the new behavior
- Updated documentation in `NEWS.md` and `book/src/mutants.md`
- All existing tests continue to pass
This change is backward compatible and requires no configuration
changes.
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Co-authored-by: Martin Pool <mbp@sourcefrog.net>#[anything::test] (#559)1 parent 81357d8 commit 3d00bf9
3 files changed
+108
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
9 | 20 | | |
10 | 21 | | |
11 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
793 | 793 | | |
794 | 794 | | |
795 | 795 | | |
796 | | - | |
| 796 | + | |
797 | 797 | | |
798 | 798 | | |
799 | 799 | | |
| |||
828 | 828 | | |
829 | 829 | | |
830 | 830 | | |
831 | | - | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
832 | 834 | | |
833 | | - | |
| 835 | + | |
834 | 836 | | |
835 | 837 | | |
836 | 838 | | |
| |||
1081 | 1083 | | |
1082 | 1084 | | |
1083 | 1085 | | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
1084 | 1176 | | |
1085 | 1177 | | |
1086 | 1178 | | |
| |||
0 commit comments