From e8258e0210c4690a1fbbcefe0e6a859da8efc19b Mon Sep 17 00:00:00 2001 From: Casper Beyer Date: Tue, 6 Jul 2021 09:20:33 +0800 Subject: feat(test): add --shuffle flag to randomize test ordering (#11163) --- cli/flags.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'cli/flags.rs') 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>, filter: Option, + shuffle: Option, concurrent_jobs: usize, }, Types, @@ -1016,6 +1017,20 @@ fn test_subcommand<'a, 'b>() -> App<'a, 'b> { .takes_value(true) .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::() { + Ok(_) => Ok(()), + Err(_) => Err("Shuffle seed should be a number".to_string()), + }), + ) .arg( Arg::with_name("coverage") .long("coverage") @@ -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::().unwrap() + } else { + rand::random::() + }; + + Some(value) + } else { + None + }; if matches.is_present("script_arg") { let script_arg: Vec = 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, -- cgit v1.2.3