From 26cea0e2ca3aa036d1e0fe4869f23bd6c0b564fb Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 20 Jul 2022 17:36:54 -0400 Subject: feat(test): add `--parallel` flag, soft deprecate `--jobs` (#15259) Co-authored-by: mrkldshv --- cli/args/flags.rs | 34 ++++++++++++++++------ cli/tests/integration/test_tests.rs | 21 +++++++------ .../testdata/test/short-pass-jobs-flag-warning.out | 7 +++++ .../short-pass-jobs-flag-with-numeric-value.out | 6 ---- 4 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 cli/tests/testdata/test/short-pass-jobs-flag-warning.out delete mode 100644 cli/tests/testdata/test/short-pass-jobs-flag-with-numeric-value.out diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 9bab9db3b..f4a379cf7 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -480,10 +480,9 @@ static ENV_VARIABLES_HELP: &str = r#"ENVIRONMENT VARIABLES: DENO_NO_PROMPT Set to disable permission prompts on access (alternative to passing --no-prompt on invocation) DENO_WEBGPU_TRACE Directory to use for wgpu traces - DENO_JOBS Number of parallel workers used for test subcommand. - Defaults to number of available CPUs when used with - --jobs flag and no value is provided. - Defaults to 1 when --jobs flag is not used. + DENO_JOBS Number of parallel workers used for the --parallel + flag with the test subcommand. Defaults to number + of available CPUs. HTTP_PROXY Proxy address for HTTP requests (module downloads, fetch) HTTPS_PROXY Proxy address for HTTPS requests @@ -1548,11 +1547,19 @@ fn test_subcommand<'a>() -> Command<'a> { .conflicts_with("inspect-brk") .help("UNSTABLE: Collect coverage profile data into DIR"), ) + .arg( + Arg::new("parallel") + .long("parallel") + .help("Run test modules in parallel. Parallelism defaults to the number of available CPUs or the value in the DENO_JOBS environment variable.") + .conflicts_with("jobs") + .takes_value(false) + ) .arg( Arg::new("jobs") .short('j') .long("jobs") - .help("Number of parallel workers, defaults to number of available CPUs when no value is provided. Defaults to 1 when the option is not present.") + .help("deprecated: Number of parallel workers, defaults to number of available CPUs when no value is provided. Defaults to 1 when the option is not present.") + .hide(true) .min_values(0) .max_values(1) .takes_value(true) @@ -2667,10 +2674,8 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) { } } - let concurrent_jobs = if matches.is_present("jobs") { - if let Some(value) = matches.value_of("jobs") { - value.parse().unwrap() - } else if let Ok(value) = env::var("DENO_JOBS") { + let concurrent_jobs = if matches.is_present("parallel") { + if let Ok(value) = env::var("DENO_JOBS") { value .parse::() .unwrap_or(NonZeroUsize::new(1).unwrap()) @@ -2678,6 +2683,17 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) { std::thread::available_parallelism() .unwrap_or(NonZeroUsize::new(1).unwrap()) } + } else if matches.is_present("jobs") { + println!( + "{}", + crate::colors::yellow("Warning: --jobs flag is deprecated. Use the --parallel flag with possibly the 'DENO_JOBS' environment variable."), + ); + if let Some(value) = matches.value_of("jobs") { + value.parse().unwrap() + } else { + std::thread::available_parallelism() + .unwrap_or(NonZeroUsize::new(1).unwrap()) + } } else { NonZeroUsize::new(1).unwrap() }; diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs index 32be3c127..3dd626909 100644 --- a/cli/tests/integration/test_tests.rs +++ b/cli/tests/integration/test_tests.rs @@ -80,30 +80,29 @@ itest!(test_with_malformed_config { output: "test/collect_with_malformed_config.out", }); -itest!(jobs_flag { - args: "test test/short-pass.ts --jobs", +itest!(parallel_flag { + args: "test test/short-pass.ts --parallel", exit_code: 0, output: "test/short-pass.out", }); -itest!(jobs_flag_with_numeric_value { - args: "test test/short-pass.ts --jobs=2", +itest!(parallel_flag_with_env_variable { + args: "test test/short-pass.ts --parallel", + envs: vec![("DENO_JOBS".to_owned(), "2".to_owned())], exit_code: 0, - output: "test/short-pass-jobs-flag-with-numeric-value.out", + output: "test/short-pass.out", }); -itest!(jobs_flag_with_env_variable { +itest!(jobs_flag { args: "test test/short-pass.ts --jobs", - envs: vec![("DENO_JOBS".to_owned(), "2".to_owned())], exit_code: 0, - output: "test/short-pass.out", + output: "test/short-pass-jobs-flag-warning.out", }); -itest!(jobs_flag_with_numeric_value_and_env_var { +itest!(jobs_flag_with_numeric_value { args: "test test/short-pass.ts --jobs=2", - envs: vec![("DENO_JOBS".to_owned(), "3".to_owned())], exit_code: 0, - output: "test/short-pass-jobs-flag-with-numeric-value.out", + output: "test/short-pass-jobs-flag-warning.out", }); itest!(load_unload { diff --git a/cli/tests/testdata/test/short-pass-jobs-flag-warning.out b/cli/tests/testdata/test/short-pass-jobs-flag-warning.out new file mode 100644 index 000000000..b70ec5ee1 --- /dev/null +++ b/cli/tests/testdata/test/short-pass-jobs-flag-warning.out @@ -0,0 +1,7 @@ +Warning: --jobs flag is deprecated. Use the --parallel flag with possibly the 'DENO_JOBS' environment variable. +Check [WILDCARD]/test/short-pass.ts +running 1 test from ./test/short-pass.ts +test ... ok ([WILDCARD]) + +ok | 1 passed | 0 failed ([WILDCARD]) + diff --git a/cli/tests/testdata/test/short-pass-jobs-flag-with-numeric-value.out b/cli/tests/testdata/test/short-pass-jobs-flag-with-numeric-value.out deleted file mode 100644 index 09b72d5fd..000000000 --- a/cli/tests/testdata/test/short-pass-jobs-flag-with-numeric-value.out +++ /dev/null @@ -1,6 +0,0 @@ -Check [WILDCARD]/test/short-pass.ts -running 1 test from ./test/short-pass.ts -test ... ok ([WILDCARD]) - -ok | 1 passed | 0 failed ([WILDCARD]) - -- cgit v1.2.3