diff options
author | Casper Beyer <caspervonb@pm.me> | 2021-07-06 09:20:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-05 21:20:33 -0400 |
commit | e8258e0210c4690a1fbbcefe0e6a859da8efc19b (patch) | |
tree | 75c56efb39d917d3d697eea4879d3e48acdc657e /cli/flags.rs | |
parent | bdeb4f430b387ebdacce7c68bb1f316830856c39 (diff) |
feat(test): add --shuffle flag to randomize test ordering (#11163)
Diffstat (limited to 'cli/flags.rs')
-rw-r--r-- | cli/flags.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index 6a51236c5..400798cbd 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -103,6 +103,7 @@ pub enum DenoSubcommand { allow_none: bool, include: Option<Vec<String>>, filter: Option<String>, + shuffle: Option<u64>, concurrent_jobs: usize, }, Types, @@ -1017,6 +1018,20 @@ fn test_subcommand<'a, 'b>() -> App<'a, 'b> { .help("Run tests with this string or pattern in the test name"), ) .arg( + Arg::with_name("shuffle") + .long("shuffle") + .value_name("NUMBER") + .help("(UNSTABLE): Shuffle the order in which the tests are run") + .min_values(0) + .max_values(1) + .require_equals(true) + .takes_value(true) + .validator(|val: String| match val.parse::<u64>() { + Ok(_) => Ok(()), + Err(_) => Err("Shuffle seed should be a number".to_string()), + }), + ) + .arg( Arg::with_name("coverage") .long("coverage") .require_equals(true) @@ -1686,7 +1701,17 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) { let quiet = matches.is_present("quiet"); let filter = matches.value_of("filter").map(String::from); - flags.watch = matches.is_present("watch"); + let shuffle = if matches.is_present("shuffle") { + let value = if let Some(value) = matches.value_of("shuffle") { + value.parse::<u64>().unwrap() + } else { + rand::random::<u64>() + }; + + Some(value) + } else { + None + }; if matches.is_present("script_arg") { let script_arg: Vec<String> = matches @@ -1730,6 +1755,7 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) { quiet, include, filter, + shuffle, allow_none, concurrent_jobs, }; @@ -3366,6 +3392,7 @@ mod tests { allow_none: true, quiet: false, include: Some(svec!["dir1/", "dir2/"]), + shuffle: None, concurrent_jobs: 1, }, unstable: true, |