-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f055b7c
commit 4bb2e88
Showing
3 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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,81 @@ | ||
// Copyright 2023 Martin Pool | ||
|
||
//! Test `--shard` | ||
use itertools::Itertools; | ||
|
||
use super::run; | ||
|
||
#[test] | ||
fn shard_divides_all_mutants() { | ||
// For speed, this only lists the mutants, trusting that the mutants | ||
// that are listed are the ones that are run. | ||
let common_args = [ | ||
"mutants", | ||
"--list", | ||
"-d", | ||
"testdata/well_tested", | ||
"--no-shuffle", | ||
]; | ||
let full_list = String::from_utf8( | ||
run() | ||
.args(common_args) | ||
.assert() | ||
.success() | ||
.get_output() | ||
.stdout | ||
.clone(), | ||
) | ||
.unwrap() | ||
.lines() | ||
.map(ToOwned::to_owned) | ||
.collect_vec(); | ||
|
||
let n_shards = 5; | ||
let shard_lists = (0..n_shards) | ||
.map(|k| { | ||
String::from_utf8( | ||
run() | ||
.args(common_args) | ||
.args(["--shard", &format!("{}/{}", k, n_shards)]) | ||
.assert() | ||
.success() | ||
.get_output() | ||
.stdout | ||
.clone(), | ||
) | ||
.unwrap() | ||
.lines() | ||
.map(ToOwned::to_owned) | ||
.collect_vec() | ||
}) | ||
.collect_vec(); | ||
|
||
// If you combine all the mutants selected for each shard, you get the | ||
// full list, with nothing lost or duplicated, disregarding order. | ||
assert_eq!( | ||
shard_lists.iter().flatten().sorted().collect_vec(), | ||
full_list.iter().sorted().collect_vec() | ||
); | ||
|
||
// The shards should also be approximately the same size. | ||
let shard_lens = shard_lists.iter().map(|l| l.len()).collect_vec(); | ||
assert!(shard_lens.iter().max().unwrap() - shard_lens.iter().min().unwrap() <= 1); | ||
|
||
// And the shards are disjoint | ||
for i in 0..n_shards { | ||
for j in 0..n_shards { | ||
if i != j { | ||
assert!( | ||
shard_lists[i].iter().all(|m| !shard_lists[j].contains(m)), | ||
"shard {} contains {}", | ||
j, | ||
shard_lists[j] | ||
.iter() | ||
.filter(|m| shard_lists[i].contains(m)) | ||
.join(", ") | ||
); | ||
} | ||
} | ||
} | ||
} |