Skip to content

Commit

Permalink
feat: passing testname argument from capsule test to cargo test
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWaWaR committed Jun 10, 2021
1 parent 1b88a41 commit 11a30a8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
21 changes: 17 additions & 4 deletions src/bin/capsule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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()?;
Expand Down
13 changes: 10 additions & 3 deletions src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
)?;
Expand Down

0 comments on commit 11a30a8

Please sign in to comment.