summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoss Weir <29697678+ross-weir@users.noreply.github.com>2020-10-26 11:25:43 +1100
committerGitHub <noreply@github.com>2020-10-26 11:25:43 +1100
commitece1e1d5f184165f21b17d3fe293d8d31dd9e413 (patch)
tree8967b7d1014668b3bdf3ed3eb41095a6efb81f6e
parent3d19fb493b82a8ab9b3fd0fa923fc81fd68acb4e (diff)
feat(cli): pass script args for test command (#8121)
Closes #8096
-rw-r--r--cli/flags.rs41
1 files changed, 39 insertions, 2 deletions
diff --git a/cli/flags.rs b/cli/flags.rs
index 59bcb5cd0..f3c777d11 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -579,6 +579,18 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
flags.coverage = true;
}
+ if matches.is_present("script_arg") {
+ let script_arg: Vec<String> = matches
+ .values_of("script_arg")
+ .unwrap()
+ .map(String::from)
+ .collect();
+
+ for v in script_arg {
+ flags.argv.push(v);
+ }
+ }
+
let include = if matches.is_present("files") {
let files: Vec<String> = matches
.values_of("files")
@@ -1106,7 +1118,10 @@ fn run_subcommand<'a, 'b>() -> App<'a, 'b> {
runtime_args(SubCommand::with_name("run"), true)
.arg(watch_arg())
.setting(AppSettings::TrailingVarArg)
- .arg(script_arg())
+ .arg(
+ script_arg()
+ .required(true)
+ )
.about("Run a program given a filename or url to the module. Use '-' as a filename to read from stdin.")
.long_about(
"Run a program given a filename or url to the module.
@@ -1131,6 +1146,7 @@ Deno allows specifying the filename '-' to read the file from stdin.
fn test_subcommand<'a, 'b>() -> App<'a, 'b> {
runtime_args(SubCommand::with_name("test"), true)
+ .setting(AppSettings::TrailingVarArg)
.arg(
Arg::with_name("failfast")
.long("failfast")
@@ -1165,6 +1181,7 @@ fn test_subcommand<'a, 'b>() -> App<'a, 'b> {
.takes_value(true)
.multiple(true),
)
+ .arg(script_arg().last(true))
.about("Run tests")
.long_about(
"Run tests using Deno's built-in test runner.
@@ -1182,7 +1199,6 @@ Directory arguments are expanded to all contained files matching the glob
fn script_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("script_arg")
.multiple(true)
- .required(true)
.help("Script arg")
.value_name("SCRIPT_ARG")
}
@@ -2902,6 +2918,27 @@ mod tests {
}
#[test]
+ fn test_double_hyphen() {
+ let r = flags_from_vec_safe(svec![
+ "deno", "test", "test.ts", "--", "arg1", "arg2"
+ ]);
+ assert_eq!(
+ r.unwrap(),
+ Flags {
+ subcommand: DenoSubcommand::Test {
+ fail_fast: false,
+ allow_none: false,
+ quiet: false,
+ filter: None,
+ include: Some(svec!["test.ts"]),
+ },
+ argv: svec!["arg1", "arg2"],
+ ..Flags::default()
+ }
+ );
+ }
+
+ #[test]
fn run_with_cafile() {
let r = flags_from_vec_safe(svec![
"deno",