From ece1e1d5f184165f21b17d3fe293d8d31dd9e413 Mon Sep 17 00:00:00 2001 From: Ross Weir <29697678+ross-weir@users.noreply.github.com> Date: Mon, 26 Oct 2020 11:25:43 +1100 Subject: [PATCH] feat(cli): pass script args for test command (#8121) Closes #8096 --- cli/flags.rs | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/cli/flags.rs b/cli/flags.rs index 59bcb5cd0a..f3c777d116 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 = 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 = 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") } @@ -2901,6 +2917,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![