Skip to content

Commit

Permalink
Merge pull request #1249 from multiversx/sc-meta-test
Browse files Browse the repository at this point in the history
sc-meta test CLI
  • Loading branch information
andrei-marinica authored Oct 27, 2023
2 parents a7287d5 + 8844261 commit 3bc4a7a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
21 changes: 21 additions & 0 deletions framework/meta/src/cli_args/cli_args_standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub enum StandaloneCliAction {
about = "Generates Rust integration tests based on scenarios provided in the scenarios folder of each contract."
)]
TestGen(TestGenArgs),
#[command(name = "test", about = "Runs cargo test")]
Test(TestArgs),
}

#[derive(Default, Clone, PartialEq, Eq, Debug, Args)]
Expand All @@ -76,6 +78,25 @@ pub struct InfoArgs {
pub ignore: Vec<String>,
}

#[derive(Default, Clone, PartialEq, Eq, Debug, Args)]
pub struct TestArgs {
/// Target directory where to generate contract integration tests.
/// Will be current directory if not specified.
#[arg(short, long, verbatim_doc_comment)]
pub path: Option<String>,

/// This arg runs rust and go tests.
/// Default value will be "false" if not specified.
#[arg(short, long, default_value = "false", verbatim_doc_comment)]
pub go: bool,

/// This arg runs scenarios.
/// Default value will be "false" if not specified.
/// If scen and go are both specified, scen overrides the go argument.
#[arg(short, long, default_value = "false", verbatim_doc_comment)]
pub scen: bool,
}

#[derive(Default, Clone, PartialEq, Eq, Debug, Args)]
pub struct AllArgs {
#[command(subcommand)]
Expand Down
3 changes: 3 additions & 0 deletions framework/meta/src/cmd/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod all;
mod info;
mod local_deps;
pub mod scen_test_gen;
pub mod test;
pub(crate) mod upgrade;

use crate::{
Expand All @@ -13,6 +14,7 @@ use clap::Parser;
use info::call_info;
use local_deps::local_deps;
use scen_test_gen::test_gen_tool;
use test::test;
use upgrade::upgrade_sc;

/// Entry point in the program when calling it as a standalone tool.
Expand All @@ -36,6 +38,7 @@ pub async fn cli_main_standalone() {
Some(StandaloneCliAction::TestGen(args)) => {
test_gen_tool(args);
},
Some(StandaloneCliAction::Test(args)) => test(args),
None => {},
}
}
49 changes: 49 additions & 0 deletions framework/meta/src/cmd/standalone/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use std::process::Command;

use colored::Colorize;

use crate::cli_args::TestArgs;

pub fn test(test_args: &TestArgs) {
let path = test_args.path.as_deref().unwrap_or("./");
let mut program = "cargo";
let mut args = Vec::new();

let go = test_args.go;
let scen = test_args.scen;

if scen {
program = "run-scenarios";
args.extend(["./"]);

if go {
println!("{}", "If scen parameter is true, it will override the go parameter. Executing scenarios...".yellow());
}
} else if go {
args.extend(["test", "--features", "multiversx-sc-scenario/run-go-tests"]);
} else {
args.extend(["test"]);
}

let args_str = args.join(" ");

println!(
"{}\n{}",
format!("Running tests in {path} ...").green(),
format!("Executing {program} {args_str} ...").green()
);

let status = Command::new(program)
.args(args.clone())
.current_dir(path)
.status()
.unwrap_or_else(|_| {
panic!(
"{}",
format!("Failed to run program: {program} {args_str}").bright_red()
)
});

println!("Process finished with: {status}");
assert!(status.success());
}

0 comments on commit 3bc4a7a

Please sign in to comment.