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

sc-meta test CLI #1249

Merged
merged 6 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
18 changes: 18 additions & 0 deletions framework/meta/src/cli_args/cli_args_standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use clap::{ArgAction, Args, Parser, Subcommand};

use super::{CliArgsToRaw, ContractCliAction};


/// Parsed arguments of the meta crate CLI.
#[derive(Default, PartialEq, Eq, Debug, Parser)]
#[command(
Expand Down Expand Up @@ -61,6 +62,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 +79,21 @@ 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 can differentiate between types of tests to be ran (go, scenario, all).
/// Default value will be "rust" if not specified.
#[arg(short, long, default_value = "rust", verbatim_doc_comment)]
pub test_type: String,
andrei-marinica marked this conversation as resolved.
Show resolved Hide resolved
}

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

use crate::{
cli_args::{StandaloneCliAction, StandaloneCliArgs},
Expand All @@ -14,6 +15,7 @@ use info::call_info;
use local_deps::local_deps;
use scen_test_gen::test_gen_tool;
use upgrade::upgrade_sc;
use test::test;

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

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();

match test_args.test_type.as_str() {
"scenario" => {
program = "run-scenarios";
args.extend(["./"]);
},
"go" => {
args.extend(["test", "--features", "multiversx-sc-scenario/run-go-tests"]);
},
"rust" => {
args.extend(["test"]);
},
_ => {
panic!("Unrecognised test argument");
},
}

let status = Command::new(program)
.args(args.clone())
.current_dir(path)
.status()
.expect(&format!("Failed to run program: {program} {:?}", args));

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