1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

add deno test subcommand (#2783)

This commit is contained in:
Bartek Iwańczuk 2019-08-15 16:11:52 +02:00 committed by Ryan Dahl
parent 498f6ad431
commit d2d3afaf2d

View file

@ -311,6 +311,40 @@ Automatically downloads Prettier dependencies on first run.
.multiple(true) .multiple(true)
.required(true), .required(true),
), ),
).subcommand(
add_run_args(SubCommand::with_name("test"))
.about("Run tests")
.long_about(
"Run tests using test runner
Automatically downloads test runner on first run.
deno test **/*_test.ts **/test.ts",
).arg(
Arg::with_name("failfast")
.short("f")
.long("failfast")
.help("Stop on first error")
.takes_value(false),
).arg(
Arg::with_name("quiet")
.short("q")
.long("quiet")
.help("Don't show output from test cases")
.takes_value(false)
).arg(
Arg::with_name("exclude")
.short("e")
.long("exclude")
.help("List of file names to exclude from run")
.takes_value(true)
.multiple(true)
).arg(
Arg::with_name("files")
.help("List of file names to run")
.takes_value(true)
.multiple(true)
),
).subcommand( ).subcommand(
add_run_args(SubCommand::with_name("run")) add_run_args(SubCommand::with_name("run"))
.settings(&[ .settings(&[
@ -521,6 +555,10 @@ pub fn parse_flags(
if let Some(run_matches) = matches.subcommand_matches("run") { if let Some(run_matches) = matches.subcommand_matches("run") {
flags = parse_run_args(flags.clone(), run_matches); flags = parse_run_args(flags.clone(), run_matches);
} }
// flags specific to "test" subcommand
if let Some(test_matches) = matches.subcommand_matches("test") {
flags = parse_run_args(flags.clone(), test_matches);
}
flags flags
} }
@ -643,6 +681,8 @@ fn parse_script_args(
const PRETTIER_URL: &str = "https://deno.land/std@v0.11/prettier/main.ts"; const PRETTIER_URL: &str = "https://deno.land/std@v0.11/prettier/main.ts";
/// Used for `deno install...` subcommand /// Used for `deno install...` subcommand
const INSTALLER_URL: &str = "https://deno.land/std@v0.11/installer/mod.ts"; const INSTALLER_URL: &str = "https://deno.land/std@v0.11/installer/mod.ts";
/// Used for `deno test...` subcommand
const TEST_RUNNER_URL: &str = "https://deno.land/std@c44e536/testing/runner.ts";
/// These are currently handled subcommands. /// These are currently handled subcommands.
/// There is no "Help" subcommand because it's handled by `clap::App` itself. /// There is no "Help" subcommand because it's handled by `clap::App` itself.
@ -795,6 +835,40 @@ pub fn flags_from_vec(
_ => unreachable!(), _ => unreachable!(),
} }
} }
("test", Some(test_match)) => {
flags.allow_read = true;
argv.push(TEST_RUNNER_URL.to_string());
if test_match.is_present("quiet") {
argv.push("--quiet".to_string());
}
if test_match.is_present("failfast") {
argv.push("--failfast".to_string());
}
if test_match.is_present("exclude") {
argv.push("--exclude".to_string());
let exclude: Vec<String> = test_match
.values_of("exclude")
.unwrap()
.map(String::from)
.collect();
argv.extend(exclude);
}
if test_match.is_present("files") {
argv.push("--".to_string());
let files: Vec<String> = test_match
.values_of("files")
.unwrap()
.map(String::from)
.collect();
argv.extend(files);
}
DenoSubcommand::Run
}
("types", Some(_)) => DenoSubcommand::Types, ("types", Some(_)) => DenoSubcommand::Types,
("run", Some(run_match)) => { ("run", Some(run_match)) => {
match run_match.subcommand() { match run_match.subcommand() {