From df0d817bd5ce50e7d703fda6388d1f542737b0fd Mon Sep 17 00:00:00 2001 From: mrkldshv Date: Tue, 21 Jun 2022 18:11:53 +0000 Subject: [PATCH 1/5] feat: add `DENO_JOBS` env variable and deprecate numeric value for `--jobs` --- cli/args/flags.rs | 15 ++++++++++- cli/tests/integration/test_tests.rs | 26 +++++++++++++++++++ cli/tests/testdata/test/pass-jobs-flag.out | 24 +++++++++++++++++ ...hort-pass-jobs-flag-with-numeric-value.out | 7 +++++ cli/tests/testdata/test/short-pass.out | 6 +++++ cli/tests/testdata/test/short-pass.ts | 1 + 6 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 cli/tests/testdata/test/pass-jobs-flag.out create mode 100644 cli/tests/testdata/test/short-pass-jobs-flag-with-numeric-value.out create mode 100644 cli/tests/testdata/test/short-pass.out create mode 100644 cli/tests/testdata/test/short-pass.ts diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 8b8cf8d86de99c..dfff279644f03c 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -480,6 +480,10 @@ 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. HTTP_PROXY Proxy address for HTTP requests (module downloads, fetch) HTTPS_PROXY Proxy address for HTTPS requests @@ -1548,9 +1552,10 @@ fn test_subcommand<'a>() -> Command<'a> { Arg::new("jobs") .short('j') .long("jobs") - .help("Number of parallel workers, defaults to # of CPUs when no value is provided. Defaults to 1 when the option is not present.") + .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.") .min_values(0) .max_values(1) + .require_equals(true) .takes_value(true) .validator(|val: &str| match val.parse::() { Ok(_) => Ok(()), @@ -2665,7 +2670,15 @@ 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") { + println!( + "{}", + crate::colors::yellow("Warning: --jobs flag with numeric value is deprecated. Use 'DENO_JOBS' environment variable with --jobs flag instead."), + ); value.parse().unwrap() + } else if let Ok(value) = env::var("DENO_JOBS") { + value + .parse::() + .unwrap_or(NonZeroUsize::new(1).unwrap()) } else { std::thread::available_parallelism() .unwrap_or(NonZeroUsize::new(1).unwrap()) diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs index 98192335909b16..e1c7700db77f88 100644 --- a/cli/tests/integration/test_tests.rs +++ b/cli/tests/integration/test_tests.rs @@ -62,6 +62,32 @@ itest!(collect { output: "test/collect.out", }); +itest!(jobs_flag { + args: "test test/short-pass.ts --jobs", + exit_code: 0, + output: "test/short-pass.out", +}); + +itest!(jobs_flag_with_numeric_value { + args: "test test/short-pass.ts --jobs=2", + exit_code: 0, + output: "test/short-pass-jobs-flag-with-numeric-value.out", +}); + +itest!(jobs_flag_with_env_variable { + args: "test test/short-pass.ts --jobs", + envs: vec![("DENO_JOBS".to_owned(), "2".to_owned())], + exit_code: 0, + output: "test/short-pass.out", +}); + +itest!(jobs_flag_with_numeric_value_and_env_var { + 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", +}); + itest!(load_unload { args: "test test/load_unload.ts", exit_code: 0, diff --git a/cli/tests/testdata/test/pass-jobs-flag.out b/cli/tests/testdata/test/pass-jobs-flag.out new file mode 100644 index 00000000000000..11e1fbbc393640 --- /dev/null +++ b/cli/tests/testdata/test/pass-jobs-flag.out @@ -0,0 +1,24 @@ +Warning: --jobs flag is deprecated. Use 'DENO_JOBS' environment variable instead. +Check [WILDCARD]/test/pass.ts +running 10 tests from ./test/pass.ts +test 0 ... ok ([WILDCARD]) +test 1 ... ok ([WILDCARD]) +test 2 ... ok ([WILDCARD]) +test 3 ... ok ([WILDCARD]) +test 4 ... ok ([WILDCARD]) +test 5 ... ok ([WILDCARD]) +test 6 ... ok ([WILDCARD]) +test 7 ... ok ([WILDCARD]) +test 8 ... +------- output ------- +console.log +----- output end ----- +test 8 ... ok ([WILDCARD]) +test 9 ... +------- output ------- +console.error +----- output end ----- +test 9 ... ok ([WILDCARD]) + +ok | 10 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 new file mode 100644 index 00000000000000..4ee49166ad583c --- /dev/null +++ b/cli/tests/testdata/test/short-pass-jobs-flag-with-numeric-value.out @@ -0,0 +1,7 @@ +Warning: --jobs flag with numeric value is deprecated. Use 'DENO_JOBS' environment variable with --jobs flag instead. +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.out b/cli/tests/testdata/test/short-pass.out new file mode 100644 index 00000000000000..09b72d5fd90170 --- /dev/null +++ b/cli/tests/testdata/test/short-pass.out @@ -0,0 +1,6 @@ +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.ts b/cli/tests/testdata/test/short-pass.ts new file mode 100644 index 00000000000000..03818ae8d43fb6 --- /dev/null +++ b/cli/tests/testdata/test/short-pass.ts @@ -0,0 +1 @@ +Deno.test("test", () => {}); From 05c885b15fff9b48917b200b1bb9d4ce49da5dfc Mon Sep 17 00:00:00 2001 From: mrkldshv Date: Thu, 30 Jun 2022 14:39:49 +0000 Subject: [PATCH 2/5] fix: remove unnecessary out file --- cli/tests/testdata/test/pass-jobs-flag.out | 24 ---------------------- 1 file changed, 24 deletions(-) delete mode 100644 cli/tests/testdata/test/pass-jobs-flag.out diff --git a/cli/tests/testdata/test/pass-jobs-flag.out b/cli/tests/testdata/test/pass-jobs-flag.out deleted file mode 100644 index 11e1fbbc393640..00000000000000 --- a/cli/tests/testdata/test/pass-jobs-flag.out +++ /dev/null @@ -1,24 +0,0 @@ -Warning: --jobs flag is deprecated. Use 'DENO_JOBS' environment variable instead. -Check [WILDCARD]/test/pass.ts -running 10 tests from ./test/pass.ts -test 0 ... ok ([WILDCARD]) -test 1 ... ok ([WILDCARD]) -test 2 ... ok ([WILDCARD]) -test 3 ... ok ([WILDCARD]) -test 4 ... ok ([WILDCARD]) -test 5 ... ok ([WILDCARD]) -test 6 ... ok ([WILDCARD]) -test 7 ... ok ([WILDCARD]) -test 8 ... -------- output ------- -console.log ------ output end ----- -test 8 ... ok ([WILDCARD]) -test 9 ... -------- output ------- -console.error ------ output end ----- -test 9 ... ok ([WILDCARD]) - -ok | 10 passed | 0 failed ([WILDCARD]) - From 152d5f5916ef8199f2669b2abefa0b55f944ce69 Mon Sep 17 00:00:00 2001 From: mrkldshv Date: Thu, 14 Jul 2022 09:03:43 +0000 Subject: [PATCH 3/5] fix: remove deprecation notice --- cli/args/flags.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index dfff279644f03c..00952556486254 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -2670,10 +2670,6 @@ 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") { - println!( - "{}", - crate::colors::yellow("Warning: --jobs flag with numeric value is deprecated. Use 'DENO_JOBS' environment variable with --jobs flag instead."), - ); value.parse().unwrap() } else if let Ok(value) = env::var("DENO_JOBS") { value From dbe16e3d5ab78dfd6a0fbd0b7da6e90f3838aaaf Mon Sep 17 00:00:00 2001 From: mrkldshv Date: Thu, 14 Jul 2022 09:17:06 +0000 Subject: [PATCH 4/5] fix: update out file --- .../testdata/test/short-pass-jobs-flag-with-numeric-value.out | 1 - 1 file changed, 1 deletion(-) 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 index 4ee49166ad583c..09b72d5fd90170 100644 --- 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 @@ -1,4 +1,3 @@ -Warning: --jobs flag with numeric value is deprecated. Use 'DENO_JOBS' environment variable with --jobs flag instead. Check [WILDCARD]/test/short-pass.ts running 1 test from ./test/short-pass.ts test ... ok ([WILDCARD]) From 146e60e0ed0b8ec0e5e80253b60377df37b37c09 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 15 Jul 2022 09:55:08 -0400 Subject: [PATCH 5/5] Remove require equals. --- cli/args/flags.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 00952556486254..c6fbb320b25870 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -480,9 +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. + 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. + --jobs flag and no value is provided. Defaults to 1 when --jobs flag is not used. HTTP_PROXY Proxy address for HTTP requests (module downloads, fetch) @@ -1555,7 +1555,6 @@ fn test_subcommand<'a>() -> Command<'a> { .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.") .min_values(0) .max_values(1) - .require_equals(true) .takes_value(true) .validator(|val: &str| match val.parse::() { Ok(_) => Ok(()),