Skip to content

Commit da63492

Browse files
authored
More example testdata (#401)
2 parents 1586307 + ac881b2 commit da63492

File tree

8 files changed

+244
-15
lines changed

8 files changed

+244
-15
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ exclude = [
116116
"testdata/integration_tests",
117117
"testdata/many_patterns",
118118
"testdata/missing_test",
119+
"testdata/missing_test_fixed",
119120
"testdata/mut_ref",
120121
"testdata/nested_mod",
121122
"testdata/never_type",

testdata/missing_test/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
[package]
22
name = "cargo-mutants-testdata-missing-test"
33
version = "0.0.0"
4-
edition = "2018"
4+
edition = "2021"
55
authors = ["Martin Pool"]
66
publish = false
7+
resolver = "2"
78

9+
[dependencies]
10+
tempfile = "3.4"

testdata/missing_test/src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
fn is_symlink(unix_mode: u32) -> bool {
2-
unix_mode & 0o140000 != 0
1+
pub fn is_symlink(unix_permissions: u32) -> bool {
2+
unix_permissions & 0o140000 != 0
33
}
44

55
#[test]
6-
fn test_symlink() {
6+
fn test_symlink_from_known_unix_permissions() {
77
assert!(is_symlink(0o147777));
88
}
9+
10+
#[cfg(unix)]
11+
#[test]
12+
fn test_symlink_on_real_symlink_permissions() {
13+
use std::os::unix::fs::PermissionsExt;
14+
let td = tempfile::TempDir::new().unwrap();
15+
let p = td.path().join("link");
16+
std::os::unix::fs::symlink("target", &p).unwrap();
17+
let meta = std::fs::symlink_metadata(&p).unwrap();
18+
assert!(is_symlink(meta.permissions().mode()));
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "cargo-mutants-testdata-missing-test-fixed"
3+
version = "0.0.0"
4+
edition = "2021"
5+
authors = ["Martin Pool"]
6+
publish = false
7+
resolver = "2"
8+
9+
[dependencies]
10+
tempfile = "3.4"

testdata/missing_test_fixed/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A fixed and better-tested version of the code from `missing_test`.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
pub fn is_symlink(unix_permissions: u32) -> bool {
2+
unix_permissions & 0o170_000 == 0o120_000
3+
}
4+
5+
#[test]
6+
fn test_symlink_from_known_unix_permissions() {
7+
assert!(is_symlink(0o120777));
8+
}
9+
10+
#[cfg(unix)]
11+
#[test]
12+
fn test_symlink_on_real_symlink_permissions() {
13+
use std::fs::symlink_metadata;
14+
use std::os::unix::fs::PermissionsExt;
15+
16+
let td = tempfile::TempDir::new().unwrap();
17+
18+
let p = td.path().join("link");
19+
std::os::unix::fs::symlink("target", &p).unwrap();
20+
let meta = symlink_metadata(&p).unwrap();
21+
assert!(is_symlink(meta.permissions().mode()));
22+
23+
assert!(!is_symlink(
24+
symlink_metadata(td.path()).unwrap().permissions().mode()
25+
));
26+
27+
let file_path = td.path().join("file");
28+
std::fs::File::create(&file_path).unwrap();
29+
assert!(!is_symlink(
30+
symlink_metadata(&file_path).unwrap().permissions().mode()
31+
));
32+
}

tests/snapshots/list__list_mutants_in_all_trees_as_json.snap

Lines changed: 167 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,7 +3171,7 @@ expression: buf
31713171
"replacement": "true",
31723172
"span": {
31733173
"end": {
3174-
"column": 30,
3174+
"column": 37,
31753175
"line": 2
31763176
},
31773177
"start": {
@@ -3201,7 +3201,7 @@ expression: buf
32013201
"replacement": "false",
32023202
"span": {
32033203
"end": {
3204-
"column": 30,
3204+
"column": 37,
32053205
"line": 2
32063206
},
32073207
"start": {
@@ -3231,11 +3231,11 @@ expression: buf
32313231
"replacement": "==",
32323232
"span": {
32333233
"end": {
3234-
"column": 28,
3234+
"column": 35,
32353235
"line": 2
32363236
},
32373237
"start": {
3238-
"column": 26,
3238+
"column": 33,
32393239
"line": 2
32403240
}
32413241
}
@@ -3261,11 +3261,11 @@ expression: buf
32613261
"replacement": "|",
32623262
"span": {
32633263
"end": {
3264-
"column": 16,
3264+
"column": 23,
32653265
"line": 2
32663266
},
32673267
"start": {
3268-
"column": 15,
3268+
"column": 22,
32693269
"line": 2
32703270
}
32713271
}
@@ -3291,11 +3291,168 @@ expression: buf
32913291
"replacement": "^",
32923292
"span": {
32933293
"end": {
3294-
"column": 16,
3294+
"column": 23,
32953295
"line": 2
32963296
},
32973297
"start": {
3298-
"column": 15,
3298+
"column": 22,
3299+
"line": 2
3300+
}
3301+
}
3302+
}
3303+
]
3304+
```
3305+
3306+
## testdata/missing_test_fixed
3307+
3308+
```json
3309+
[
3310+
{
3311+
"file": "src/lib.rs",
3312+
"function": {
3313+
"function_name": "is_symlink",
3314+
"return_type": "-> bool",
3315+
"span": {
3316+
"end": {
3317+
"column": 2,
3318+
"line": 3
3319+
},
3320+
"start": {
3321+
"column": 1,
3322+
"line": 1
3323+
}
3324+
}
3325+
},
3326+
"genre": "FnValue",
3327+
"package": "cargo-mutants-testdata-missing-test-fixed",
3328+
"replacement": "true",
3329+
"span": {
3330+
"end": {
3331+
"column": 46,
3332+
"line": 2
3333+
},
3334+
"start": {
3335+
"column": 5,
3336+
"line": 2
3337+
}
3338+
}
3339+
},
3340+
{
3341+
"file": "src/lib.rs",
3342+
"function": {
3343+
"function_name": "is_symlink",
3344+
"return_type": "-> bool",
3345+
"span": {
3346+
"end": {
3347+
"column": 2,
3348+
"line": 3
3349+
},
3350+
"start": {
3351+
"column": 1,
3352+
"line": 1
3353+
}
3354+
}
3355+
},
3356+
"genre": "FnValue",
3357+
"package": "cargo-mutants-testdata-missing-test-fixed",
3358+
"replacement": "false",
3359+
"span": {
3360+
"end": {
3361+
"column": 46,
3362+
"line": 2
3363+
},
3364+
"start": {
3365+
"column": 5,
3366+
"line": 2
3367+
}
3368+
}
3369+
},
3370+
{
3371+
"file": "src/lib.rs",
3372+
"function": {
3373+
"function_name": "is_symlink",
3374+
"return_type": "-> bool",
3375+
"span": {
3376+
"end": {
3377+
"column": 2,
3378+
"line": 3
3379+
},
3380+
"start": {
3381+
"column": 1,
3382+
"line": 1
3383+
}
3384+
}
3385+
},
3386+
"genre": "BinaryOperator",
3387+
"package": "cargo-mutants-testdata-missing-test-fixed",
3388+
"replacement": "!=",
3389+
"span": {
3390+
"end": {
3391+
"column": 36,
3392+
"line": 2
3393+
},
3394+
"start": {
3395+
"column": 34,
3396+
"line": 2
3397+
}
3398+
}
3399+
},
3400+
{
3401+
"file": "src/lib.rs",
3402+
"function": {
3403+
"function_name": "is_symlink",
3404+
"return_type": "-> bool",
3405+
"span": {
3406+
"end": {
3407+
"column": 2,
3408+
"line": 3
3409+
},
3410+
"start": {
3411+
"column": 1,
3412+
"line": 1
3413+
}
3414+
}
3415+
},
3416+
"genre": "BinaryOperator",
3417+
"package": "cargo-mutants-testdata-missing-test-fixed",
3418+
"replacement": "|",
3419+
"span": {
3420+
"end": {
3421+
"column": 23,
3422+
"line": 2
3423+
},
3424+
"start": {
3425+
"column": 22,
3426+
"line": 2
3427+
}
3428+
}
3429+
},
3430+
{
3431+
"file": "src/lib.rs",
3432+
"function": {
3433+
"function_name": "is_symlink",
3434+
"return_type": "-> bool",
3435+
"span": {
3436+
"end": {
3437+
"column": 2,
3438+
"line": 3
3439+
},
3440+
"start": {
3441+
"column": 1,
3442+
"line": 1
3443+
}
3444+
}
3445+
},
3446+
"genre": "BinaryOperator",
3447+
"package": "cargo-mutants-testdata-missing-test-fixed",
3448+
"replacement": "^",
3449+
"span": {
3450+
"end": {
3451+
"column": 23,
3452+
"line": 2
3453+
},
3454+
"start": {
3455+
"column": 22,
32993456
"line": 2
33003457
}
33013458
}
@@ -9454,3 +9611,5 @@ expression: buf
94549611
}
94559612
]
94569613
```
9614+
9615+

tests/snapshots/list__list_mutants_in_all_trees_as_text.snap

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,19 @@ src/binops.rs:17:7: replace <<= with >>= in bin_assign
212212
```
213213
src/lib.rs:2:5: replace is_symlink -> bool with true
214214
src/lib.rs:2:5: replace is_symlink -> bool with false
215-
src/lib.rs:2:26: replace != with == in is_symlink
216-
src/lib.rs:2:15: replace & with | in is_symlink
217-
src/lib.rs:2:15: replace & with ^ in is_symlink
215+
src/lib.rs:2:33: replace != with == in is_symlink
216+
src/lib.rs:2:22: replace & with | in is_symlink
217+
src/lib.rs:2:22: replace & with ^ in is_symlink
218+
```
219+
220+
## testdata/missing_test_fixed
221+
222+
```
223+
src/lib.rs:2:5: replace is_symlink -> bool with true
224+
src/lib.rs:2:5: replace is_symlink -> bool with false
225+
src/lib.rs:2:34: replace == with != in is_symlink
226+
src/lib.rs:2:22: replace & with | in is_symlink
227+
src/lib.rs:2:22: replace & with ^ in is_symlink
218228
```
219229
220230
## testdata/mut_ref
@@ -513,3 +523,5 @@ main2/src/main.rs:10:5: replace triple_3 -> i32 with 0
513523
main2/src/main.rs:10:5: replace triple_3 -> i32 with 1
514524
main2/src/main.rs:10:5: replace triple_3 -> i32 with -1
515525
```
526+
527+

0 commit comments

Comments
 (0)