Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Remove dependency assert_cmd #5480

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
55 changes: 0 additions & 55 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ sc-consensus-epochs = { version = "0.8.0-alpha.5", path = "../../../client/conse
sc-service-test = { version = "2.0.0-dev", path = "../../../client/service/test" }
futures = "0.3.4"
tempfile = "3.1.0"
assert_cmd = "1.0"
nix = "0.17"
serde_json = "1.0"

Expand Down
5 changes: 3 additions & 2 deletions bin/node/cli/tests/build_spec_works.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

use assert_cmd::cargo::cargo_bin;
use std::process::Command;
use tempfile::tempdir;

mod common;

#[test]
fn build_spec_works() {
let base_path = tempdir().expect("could not create a temp dir");

let output = Command::new(cargo_bin("substrate"))
let output = Command::new(common::cargo_bin("substrate"))
.args(&["build-spec", "--dev", "-d"])
.arg(base_path.path())
.output()
Expand Down
3 changes: 1 addition & 2 deletions bin/node/cli/tests/check_block_works.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#![cfg(unix)]

use assert_cmd::cargo::cargo_bin;
use std::process::Command;
use tempfile::tempdir;

Expand All @@ -28,7 +27,7 @@ fn check_block_works() {

common::run_dev_node_for_a_while(base_path.path());

let status = Command::new(cargo_bin("substrate"))
let status = Command::new(common::cargo_bin("substrate"))
.args(&["check-block", "--dev", "--pruning", "archive", "-d"])
.arg(base_path.path())
.arg("1")
Expand Down
28 changes: 26 additions & 2 deletions bin/node/cli/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
#![cfg(unix)]
#![allow(dead_code)]

use std::{process::{Child, ExitStatus}, thread, time::Duration, path::Path};
use assert_cmd::cargo::cargo_bin;
use std::{env, process::{Child, ExitStatus}, thread, time::Duration, path::{Path, PathBuf}};
use std::{convert::TryInto, process::Command};
use nix::sys::signal::{kill, Signal::SIGINT};
use nix::unistd::Pid;
Expand Down Expand Up @@ -64,3 +63,28 @@ pub fn run_dev_node_for_a_while(base_path: &Path) {
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
assert!(wait_for(&mut cmd, 40).map(|x| x.success()).unwrap_or_default());
}

// Code taken directly from https://github.com/assert-rs/assert_cmd/blob/d9fcca1ac40496afbcdaea719082e5d7f105f4d9/src/cargo.rs
// Adapted from
// https://github.com/rust-lang/cargo/blob/485670b3983b52289a2f353d589c57fae2f60f82/tests/testsuite/support/mod.rs#L507
fn target_dir() -> PathBuf {
env::current_exe()
.ok()
.map(|mut path| {
path.pop();
if path.ends_with("deps") {
path.pop();
}
path
})
.unwrap()
}

/// Look up the path to a cargo-built binary within an integration test.
pub fn cargo_bin<S: AsRef<str>>(name: S) -> PathBuf {
cargo_bin_str(name.as_ref())
}

fn cargo_bin_str(name: &str) -> PathBuf {
target_dir().join(format!("{}{}", name, env::consts::EXE_SUFFIX))
}
3 changes: 1 addition & 2 deletions bin/node/cli/tests/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#![cfg(unix)]

use assert_cmd::cargo::cargo_bin;
use std::process::{Command, Stdio};
use tempfile::tempdir;

Expand All @@ -26,7 +25,7 @@ mod common;
fn factory_works() {
let base_path = tempdir().expect("could not create a temp dir");

let status = Command::new(cargo_bin("substrate"))
let status = Command::new(common::cargo_bin("substrate"))
.stdout(Stdio::null())
.args(&["factory", "--dev", "-d"])
.arg(base_path.path())
Expand Down
7 changes: 3 additions & 4 deletions bin/node/cli/tests/import_export_and_revert_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#![cfg(unix)]

use assert_cmd::cargo::cargo_bin;
use std::{process::Command, fs};
use tempfile::tempdir;

Expand All @@ -29,7 +28,7 @@ fn import_export_and_revert_work() {

common::run_dev_node_for_a_while(base_path.path());

let status = Command::new(cargo_bin("substrate"))
let status = Command::new(common::cargo_bin("substrate"))
.args(&["export-blocks", "--dev", "--pruning", "archive", "-d"])
.arg(base_path.path())
.arg(&exported_blocks)
Expand All @@ -42,15 +41,15 @@ fn import_export_and_revert_work() {

let _ = fs::remove_dir_all(base_path.path().join("db"));

let status = Command::new(cargo_bin("substrate"))
let status = Command::new(common::cargo_bin("substrate"))
.args(&["import-blocks", "--dev", "--pruning", "archive", "-d"])
.arg(base_path.path())
.arg(&exported_blocks)
.status()
.unwrap();
assert!(status.success());

let status = Command::new(cargo_bin("substrate"))
let status = Command::new(common::cargo_bin("substrate"))
.args(&["revert", "--dev", "--pruning", "archive", "-d"])
.arg(base_path.path())
.status()
Expand Down
3 changes: 1 addition & 2 deletions bin/node/cli/tests/inspect_works.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#![cfg(unix)]

use assert_cmd::cargo::cargo_bin;
use std::process::Command;
use tempfile::tempdir;

Expand All @@ -28,7 +27,7 @@ fn inspect_works() {

common::run_dev_node_for_a_while(base_path.path());

let status = Command::new(cargo_bin("substrate"))
let status = Command::new(common::cargo_bin("substrate"))
.args(&["inspect", "--dev", "--pruning", "archive", "-d"])
.arg(base_path.path())
.args(&["block", "1"])
Expand Down
3 changes: 1 addition & 2 deletions bin/node/cli/tests/purge_chain_works.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

use assert_cmd::cargo::cargo_bin;
use std::process::Command;
use tempfile::tempdir;

Expand All @@ -27,7 +26,7 @@ fn purge_chain_works() {

common::run_dev_node_for_a_while(base_path.path());

let status = Command::new(cargo_bin("substrate"))
let status = Command::new(common::cargo_bin("substrate"))
.args(&["purge-chain", "--dev", "-d"])
.arg(base_path.path())
.arg("-y")
Expand Down
3 changes: 1 addition & 2 deletions bin/node/cli/tests/running_the_node_and_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

use assert_cmd::cargo::cargo_bin;
use std::{convert::TryInto, process::Command, thread, time::Duration};
use tempfile::tempdir;

Expand All @@ -28,7 +27,7 @@ fn running_the_node_works_and_can_be_interrupted() {

fn run_command_and_kill(signal: Signal) {
let base_path = tempdir().expect("could not create a temp dir");
let mut cmd = Command::new(cargo_bin("substrate"))
let mut cmd = Command::new(common::cargo_bin("substrate"))
.args(&["--dev", "-d"])
.arg(base_path.path())
.spawn()
Expand Down