multiversx_sc_meta/cmd/
test.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::process::Command;

use colored::Colorize;

use crate::cli::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;
    let no_capture = test_args.nocapture;
    let chain_simulator = test_args.chain_simulator;

    if scen {
        program = "mx-scenario-go";
        args.extend(["run", "./"]);

        if go {
            println!("{}", "If scen parameter is true, it will override the go parameter. Executing scenarios...".yellow());
        }
    } else {
        args.push("test");

        if go {
            args.extend(["--features", "multiversx-sc-scenario/run-go-tests"]);
        }

        if chain_simulator && cfg!(feature = "chain-simulator-tests") {
            args.extend(["--features", "chain-simulator-tests"]);
        }

        if no_capture {
            args.extend(["--", "--nocapture"]);
        }
    }

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