diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 91adac84ba0607..ca8a5b05b77729 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -2682,10 +2682,19 @@ Directory arguments are expanded to all contained files matching the glob .value_name("N") .value_parser(value_parser!(NonZeroUsize)), ) + // TODO(@lucacasonato): remove for Deno 2.0 .arg( Arg::new("allow-none") .long("allow-none") .help("Don't return error code if no test files are found") + .hide(true) + .action(ArgAction::SetTrue), + ) + .arg( + Arg::new("permit-no-files") + .long("permit-no-files") + .help("Don't return an error code if no test files were found") + .conflicts_with("allow-none") .action(ArgAction::SetTrue), ) .arg( @@ -4436,7 +4445,17 @@ fn test_parse(flags: &mut Flags, matches: &mut ArgMatches) { ); } let doc = matches.get_flag("doc"); - let allow_none = matches.get_flag("allow-none"); + #[allow(clippy::print_stderr)] + let allow_none = matches.get_flag("permit-no-files") + || if matches.get_flag("allow-none") { + eprintln!( + "⚠️ {}", + crate::colors::yellow("The `--allow-none` flag is deprecated and will be removed in Deno 2.0.\nUse the `--permit-no-files` flag instead."), + ); + true + } else { + false + }; let filter = matches.remove_one::("filter"); let clean = matches.get_flag("clean"); @@ -8397,7 +8416,7 @@ mod tests { #[test] fn test_with_flags() { #[rustfmt::skip] - let r = flags_from_vec(svec!["deno", "test", "--unstable", "--no-npm", "--no-remote", "--trace-leaks", "--no-run", "--filter", "- foo", "--coverage=cov", "--clean", "--location", "https:foo", "--allow-net", "--allow-none", "dir1/", "dir2/", "--", "arg1", "arg2"]); + let r = flags_from_vec(svec!["deno", "test", "--unstable", "--no-npm", "--no-remote", "--trace-leaks", "--no-run", "--filter", "- foo", "--coverage=cov", "--clean", "--location", "https:foo", "--allow-net", "--permit-no-files", "dir1/", "dir2/", "--", "arg1", "arg2"]); assert_eq!( r.unwrap(), Flags { diff --git a/tests/specs/test/no_files/__test__.jsonc b/tests/specs/test/no_files/__test__.jsonc new file mode 100644 index 00000000000000..0bb252ec779c4a --- /dev/null +++ b/tests/specs/test/no_files/__test__.jsonc @@ -0,0 +1,19 @@ +{ + "tests": { + "error": { + "args": "test", + "output": "error.out", + "exitCode": 1 + }, + "permit_no_files": { + "args": "test --permit-no-files", + "output": "permit_no_files.out", + "exitCode": 0 + }, + "allow_none": { + "args": "test --allow-none", + "output": "allow_none.out", + "exitCode": 0 + } + } +} diff --git a/tests/specs/test/no_files/allow_none.out b/tests/specs/test/no_files/allow_none.out new file mode 100644 index 00000000000000..1cc973bb52c3e7 --- /dev/null +++ b/tests/specs/test/no_files/allow_none.out @@ -0,0 +1,5 @@ +⚠️ The `--allow-none` flag is deprecated and will be removed in Deno 2.0. +Use the `--permit-no-files` flag instead. + +ok | 0 passed | 0 failed (0ms) + diff --git a/tests/specs/test/no_files/error.out b/tests/specs/test/no_files/error.out new file mode 100644 index 00000000000000..2878f641a2077b --- /dev/null +++ b/tests/specs/test/no_files/error.out @@ -0,0 +1 @@ +error: No test modules found diff --git a/tests/specs/test/no_files/permit_no_files.out b/tests/specs/test/no_files/permit_no_files.out new file mode 100644 index 00000000000000..228425d10eb7d6 --- /dev/null +++ b/tests/specs/test/no_files/permit_no_files.out @@ -0,0 +1,3 @@ + +ok | 0 passed | 0 failed (0ms) +