Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support passing custom environment variable to docker when run capsule test #33

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: passing testname argument from capsule test to cargo test
fix #26
  • Loading branch information
TheWaWaR committed Jun 10, 2021
commit 11a30a830634f59fdbe5c8272641a24073754886
21 changes: 17 additions & 4 deletions src/bin/capsule.rs
Original file line number Diff line number Diff line change
@@ -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()?;
13 changes: 10 additions & 3 deletions src/tester.rs
Original file line number Diff line number Diff line change
@@ -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,
)?;