Skip to content

Commit

Permalink
More example testdata (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog authored Aug 21, 2024
2 parents 1586307 + ac881b2 commit da63492
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ exclude = [
"testdata/integration_tests",
"testdata/many_patterns",
"testdata/missing_test",
"testdata/missing_test_fixed",
"testdata/mut_ref",
"testdata/nested_mod",
"testdata/never_type",
Expand Down
5 changes: 4 additions & 1 deletion testdata/missing_test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[package]
name = "cargo-mutants-testdata-missing-test"
version = "0.0.0"
edition = "2018"
edition = "2021"
authors = ["Martin Pool"]
publish = false
resolver = "2"

[dependencies]
tempfile = "3.4"
17 changes: 14 additions & 3 deletions testdata/missing_test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
fn is_symlink(unix_mode: u32) -> bool {
unix_mode & 0o140000 != 0
pub fn is_symlink(unix_permissions: u32) -> bool {
unix_permissions & 0o140000 != 0
}

#[test]
fn test_symlink() {
fn test_symlink_from_known_unix_permissions() {
assert!(is_symlink(0o147777));
}

#[cfg(unix)]
#[test]
fn test_symlink_on_real_symlink_permissions() {
use std::os::unix::fs::PermissionsExt;
let td = tempfile::TempDir::new().unwrap();
let p = td.path().join("link");
std::os::unix::fs::symlink("target", &p).unwrap();
let meta = std::fs::symlink_metadata(&p).unwrap();
assert!(is_symlink(meta.permissions().mode()));
}
10 changes: 10 additions & 0 deletions testdata/missing_test_fixed/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "cargo-mutants-testdata-missing-test-fixed"
version = "0.0.0"
edition = "2021"
authors = ["Martin Pool"]
publish = false
resolver = "2"

[dependencies]
tempfile = "3.4"
1 change: 1 addition & 0 deletions testdata/missing_test_fixed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A fixed and better-tested version of the code from `missing_test`.
32 changes: 32 additions & 0 deletions testdata/missing_test_fixed/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
pub fn is_symlink(unix_permissions: u32) -> bool {
unix_permissions & 0o170_000 == 0o120_000
}

#[test]
fn test_symlink_from_known_unix_permissions() {
assert!(is_symlink(0o120777));
}

#[cfg(unix)]
#[test]
fn test_symlink_on_real_symlink_permissions() {
use std::fs::symlink_metadata;
use std::os::unix::fs::PermissionsExt;

let td = tempfile::TempDir::new().unwrap();

let p = td.path().join("link");
std::os::unix::fs::symlink("target", &p).unwrap();
let meta = symlink_metadata(&p).unwrap();
assert!(is_symlink(meta.permissions().mode()));

assert!(!is_symlink(
symlink_metadata(td.path()).unwrap().permissions().mode()
));

let file_path = td.path().join("file");
std::fs::File::create(&file_path).unwrap();
assert!(!is_symlink(
symlink_metadata(&file_path).unwrap().permissions().mode()
));
}
175 changes: 167 additions & 8 deletions tests/snapshots/list__list_mutants_in_all_trees_as_json.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3171,7 +3171,7 @@ expression: buf
"replacement": "true",
"span": {
"end": {
"column": 30,
"column": 37,
"line": 2
},
"start": {
Expand Down Expand Up @@ -3201,7 +3201,7 @@ expression: buf
"replacement": "false",
"span": {
"end": {
"column": 30,
"column": 37,
"line": 2
},
"start": {
Expand Down Expand Up @@ -3231,11 +3231,11 @@ expression: buf
"replacement": "==",
"span": {
"end": {
"column": 28,
"column": 35,
"line": 2
},
"start": {
"column": 26,
"column": 33,
"line": 2
}
}
Expand All @@ -3261,11 +3261,11 @@ expression: buf
"replacement": "|",
"span": {
"end": {
"column": 16,
"column": 23,
"line": 2
},
"start": {
"column": 15,
"column": 22,
"line": 2
}
}
Expand All @@ -3291,11 +3291,168 @@ expression: buf
"replacement": "^",
"span": {
"end": {
"column": 16,
"column": 23,
"line": 2
},
"start": {
"column": 15,
"column": 22,
"line": 2
}
}
}
]
```

## testdata/missing_test_fixed

```json
[
{
"file": "src/lib.rs",
"function": {
"function_name": "is_symlink",
"return_type": "-> bool",
"span": {
"end": {
"column": 2,
"line": 3
},
"start": {
"column": 1,
"line": 1
}
}
},
"genre": "FnValue",
"package": "cargo-mutants-testdata-missing-test-fixed",
"replacement": "true",
"span": {
"end": {
"column": 46,
"line": 2
},
"start": {
"column": 5,
"line": 2
}
}
},
{
"file": "src/lib.rs",
"function": {
"function_name": "is_symlink",
"return_type": "-> bool",
"span": {
"end": {
"column": 2,
"line": 3
},
"start": {
"column": 1,
"line": 1
}
}
},
"genre": "FnValue",
"package": "cargo-mutants-testdata-missing-test-fixed",
"replacement": "false",
"span": {
"end": {
"column": 46,
"line": 2
},
"start": {
"column": 5,
"line": 2
}
}
},
{
"file": "src/lib.rs",
"function": {
"function_name": "is_symlink",
"return_type": "-> bool",
"span": {
"end": {
"column": 2,
"line": 3
},
"start": {
"column": 1,
"line": 1
}
}
},
"genre": "BinaryOperator",
"package": "cargo-mutants-testdata-missing-test-fixed",
"replacement": "!=",
"span": {
"end": {
"column": 36,
"line": 2
},
"start": {
"column": 34,
"line": 2
}
}
},
{
"file": "src/lib.rs",
"function": {
"function_name": "is_symlink",
"return_type": "-> bool",
"span": {
"end": {
"column": 2,
"line": 3
},
"start": {
"column": 1,
"line": 1
}
}
},
"genre": "BinaryOperator",
"package": "cargo-mutants-testdata-missing-test-fixed",
"replacement": "|",
"span": {
"end": {
"column": 23,
"line": 2
},
"start": {
"column": 22,
"line": 2
}
}
},
{
"file": "src/lib.rs",
"function": {
"function_name": "is_symlink",
"return_type": "-> bool",
"span": {
"end": {
"column": 2,
"line": 3
},
"start": {
"column": 1,
"line": 1
}
}
},
"genre": "BinaryOperator",
"package": "cargo-mutants-testdata-missing-test-fixed",
"replacement": "^",
"span": {
"end": {
"column": 23,
"line": 2
},
"start": {
"column": 22,
"line": 2
}
}
Expand Down Expand Up @@ -9454,3 +9611,5 @@ expression: buf
}
]
```


18 changes: 15 additions & 3 deletions tests/snapshots/list__list_mutants_in_all_trees_as_text.snap
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,19 @@ src/binops.rs:17:7: replace <<= with >>= in bin_assign
```
src/lib.rs:2:5: replace is_symlink -> bool with true
src/lib.rs:2:5: replace is_symlink -> bool with false
src/lib.rs:2:26: replace != with == in is_symlink
src/lib.rs:2:15: replace & with | in is_symlink
src/lib.rs:2:15: replace & with ^ in is_symlink
src/lib.rs:2:33: replace != with == in is_symlink
src/lib.rs:2:22: replace & with | in is_symlink
src/lib.rs:2:22: replace & with ^ in is_symlink
```
## testdata/missing_test_fixed
```
src/lib.rs:2:5: replace is_symlink -> bool with true
src/lib.rs:2:5: replace is_symlink -> bool with false
src/lib.rs:2:34: replace == with != in is_symlink
src/lib.rs:2:22: replace & with | in is_symlink
src/lib.rs:2:22: replace & with ^ in is_symlink
```
## testdata/mut_ref
Expand Down Expand Up @@ -513,3 +523,5 @@ 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
```

0 comments on commit da63492

Please sign in to comment.