diff --git a/src/bin/capsule.rs b/src/bin/capsule.rs index 0ca2bb4..6c40217 100644 --- a/src/bin/capsule.rs +++ b/src/bin/capsule.rs @@ -95,9 +95,22 @@ fn run_cli() -> Result<()> { .args(&[Arg::with_name("name").short("n").long("name").required(true).takes_value(true).help("contract name"), Arg::with_name("cmd").required(true).multiple(true).help("command to run")]) .display_order(4)) - .subcommand(SubCommand::with_name("test").about("Run tests").arg( - Arg::with_name("release").long("release").help("Test release mode contracts.") - ).display_order(5)) + .subcommand( + SubCommand::with_name("test") + .about("Run tests") + .arg( + Arg::with_name("release") + .long("release") + .help("Test release mode contracts.") + ) + .arg( + Arg::with_name("testname") + .takes_value(true) + .value_name("TESTNAME") + .help("If specified, only run tests containing this string in their names.") + ) + .display_order(5) + ) .subcommand( SubCommand::with_name("deploy") .about("Deploy contracts, edit deployment.toml to custodian deployment recipe.") @@ -312,7 +325,7 @@ fn run_cli() -> Result<()> { } else { BuildEnv::Debug }; - Tester::run(&context, build_env, &signal)?; + Tester::run(&context, build_env, &signal, args.value_of("testname"))?; } ("deploy", Some(args)) => { Checker::build()?.check_ckb_cli()?; diff --git a/src/tester.rs b/src/tester.rs index bfc107b..69acc26 100644 --- a/src/tester.rs +++ b/src/tester.rs @@ -8,7 +8,12 @@ const TEST_ENV_VAR: &str = "CAPSULE_TEST_ENV"; pub struct Tester; impl Tester { - pub fn run(project_context: &Context, env: BuildEnv, signal: &Signal) -> Result<()> { + pub fn run( + project_context: &Context, + env: BuildEnv, + signal: &Signal, + testname: Option<&str>, + ) -> Result<()> { let env_arg = match env { BuildEnv::Debug => "debug", BuildEnv::Release => "release", @@ -31,8 +36,10 @@ impl Tester { .fix_dir_permission("Cargo.lock".to_string()); cmd.run( format!( - "{}={} cargo test -p tests -- --nocapture", - TEST_ENV_VAR, env_arg + "{}={} cargo test {} -p tests -- --nocapture", + TEST_ENV_VAR, + env_arg, + testname.unwrap_or(""), ), signal, )?;