Refactor cargo-build-sbf integration tests using assert_cmd crate
This commit is contained in:
parent
ebe25fdb56
commit
84eb6bab4a
|
@ -4767,6 +4767,7 @@ dependencies = [
|
|||
name = "solana-cargo-build-sbf"
|
||||
version = "1.12.0"
|
||||
dependencies = [
|
||||
"assert_cmd",
|
||||
"bzip2",
|
||||
"cargo_metadata",
|
||||
"clap 3.1.8",
|
||||
|
|
|
@ -21,6 +21,7 @@ solana-sdk = { path = "..", version = "=1.12.0" }
|
|||
tar = "0.4.38"
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "*"
|
||||
serial_test = "*"
|
||||
|
||||
[features]
|
||||
|
|
|
@ -1,19 +1,10 @@
|
|||
use std::{
|
||||
env, fs,
|
||||
io::{self, Write},
|
||||
process::{Command, Output},
|
||||
};
|
||||
use std::{env, fs, process};
|
||||
|
||||
#[macro_use]
|
||||
extern crate serial_test;
|
||||
|
||||
fn run_cargo_build(crate_name: &str, extra_args: &[&str], test_name: &str) -> Output {
|
||||
fn run_cargo_build(crate_name: &str, extra_args: &[&str], fail: bool) {
|
||||
let cwd = env::current_dir().expect("Unable to get current working directory");
|
||||
let root = cwd
|
||||
.parent()
|
||||
.expect("Unable to get parent directory of current working dir")
|
||||
.parent()
|
||||
.expect("Unable to get ../.. of current working dir");
|
||||
let toml = cwd
|
||||
.join("tests")
|
||||
.join("crates")
|
||||
|
@ -26,20 +17,13 @@ fn run_cargo_build(crate_name: &str, extra_args: &[&str], test_name: &str) -> Ou
|
|||
}
|
||||
args.push("--");
|
||||
args.push("-vv");
|
||||
let cargo_build_sbf = root.join("target").join("debug").join("cargo-build-sbf");
|
||||
env::set_var("RUST_LOG", "debug");
|
||||
let output = Command::new(cargo_build_sbf)
|
||||
.args(&args)
|
||||
.output()
|
||||
.expect("Error running cargo-build-sbf");
|
||||
if !output.status.success() {
|
||||
eprintln!("--- stdout of {} ---", test_name);
|
||||
io::stderr().write_all(&output.stdout).unwrap();
|
||||
eprintln!("--- stderr of {} ---", test_name);
|
||||
io::stderr().write_all(&output.stderr).unwrap();
|
||||
eprintln!("--------------");
|
||||
let mut cmd = assert_cmd::Command::cargo_bin("cargo-build-sbf").unwrap();
|
||||
let assert = cmd.env("RUST_LOG", "debug").args(&args).assert();
|
||||
if fail {
|
||||
assert.failure();
|
||||
} else {
|
||||
assert.success();
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
fn clean_target(crate_name: &str) {
|
||||
|
@ -55,8 +39,7 @@ fn clean_target(crate_name: &str) {
|
|||
#[test]
|
||||
#[serial]
|
||||
fn test_build() {
|
||||
let output = run_cargo_build("noop", &[], "test_build");
|
||||
assert!(output.status.success());
|
||||
run_cargo_build("noop", &[], false);
|
||||
clean_target("noop");
|
||||
}
|
||||
|
||||
|
@ -64,13 +47,12 @@ fn test_build() {
|
|||
#[serial]
|
||||
fn test_dump() {
|
||||
// This test requires rustfilt.
|
||||
assert!(Command::new("cargo")
|
||||
assert!(process::Command::new("cargo")
|
||||
.args(&["install", "-f", "rustfilt"])
|
||||
.status()
|
||||
.expect("Unable to install rustfilt required for --dump option")
|
||||
.success());
|
||||
let output = run_cargo_build("noop", &["--dump"], "test_dump");
|
||||
assert!(output.status.success());
|
||||
run_cargo_build("noop", &["--dump"], false);
|
||||
let cwd = env::current_dir().expect("Unable to get current working directory");
|
||||
let dump = cwd
|
||||
.join("tests")
|
||||
|
@ -86,8 +68,7 @@ fn test_dump() {
|
|||
#[test]
|
||||
#[serial]
|
||||
fn test_out_dir() {
|
||||
let output = run_cargo_build("noop", &["--sbf-out-dir", "tmp_out"], "test_out_dir");
|
||||
assert!(output.status.success());
|
||||
run_cargo_build("noop", &["--sbf-out-dir", "tmp_out"], false);
|
||||
let cwd = env::current_dir().expect("Unable to get current working directory");
|
||||
let dir = cwd.join("tmp_out");
|
||||
assert!(dir.exists());
|
||||
|
@ -98,12 +79,7 @@ fn test_out_dir() {
|
|||
#[test]
|
||||
#[serial]
|
||||
fn test_generate_child_script_on_failre() {
|
||||
let output = run_cargo_build(
|
||||
"fail",
|
||||
&["--generate-child-script-on-failure"],
|
||||
"test_generate_child_script_on_failre",
|
||||
);
|
||||
assert!(!output.status.success());
|
||||
run_cargo_build("fail", &["--generate-child-script-on-failure"], true);
|
||||
let cwd = env::current_dir().expect("Unable to get current working directory");
|
||||
let scr = cwd
|
||||
.join("tests")
|
||||
|
|
Loading…
Reference in New Issue