mirror of
https://github.com/uutils/findutils.git
synced 2026-06-10 15:48:30 -07:00
tests: replace deprecated Command::cargo_bin
with cargo_bin_cmd!
This commit is contained in:
+88
-175
File diff suppressed because it is too large
Load Diff
+45
-89
@@ -8,7 +8,7 @@
|
||||
/// ! tests so that testing-commandline can be built first.
|
||||
use std::io::{Seek, SeekFrom, Write};
|
||||
|
||||
use assert_cmd::Command;
|
||||
use assert_cmd::cargo::cargo_bin_cmd;
|
||||
use predicates::prelude::*;
|
||||
|
||||
use common::test_helpers::path_to_testing_commandline;
|
||||
@@ -18,8 +18,7 @@ mod common;
|
||||
|
||||
#[test]
|
||||
fn xargs_basics() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.write_stdin("abc\ndef g\\hi 'i j \"k'")
|
||||
.assert()
|
||||
.success()
|
||||
@@ -29,8 +28,7 @@ fn xargs_basics() {
|
||||
|
||||
#[test]
|
||||
fn xargs_null() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-0n1"])
|
||||
.write_stdin("ab c\0d\tef\0")
|
||||
.assert()
|
||||
@@ -41,8 +39,7 @@ fn xargs_null() {
|
||||
|
||||
#[test]
|
||||
fn xargs_delim() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-d1"])
|
||||
.write_stdin("ab1cd1ef")
|
||||
.assert()
|
||||
@@ -50,8 +47,7 @@ fn xargs_delim() {
|
||||
.stderr(predicate::str::is_empty())
|
||||
.stdout(predicate::str::diff("ab cd ef\n"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-d\\t", "-n1"])
|
||||
.write_stdin("a\nb\td e\tfg")
|
||||
.assert()
|
||||
@@ -59,8 +55,7 @@ fn xargs_delim() {
|
||||
.stderr(predicate::str::is_empty())
|
||||
.stdout(predicate::str::diff("a\nb\nd e\nfg\n"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-dabc"])
|
||||
.assert()
|
||||
.failure()
|
||||
@@ -71,8 +66,7 @@ fn xargs_delim() {
|
||||
|
||||
#[test]
|
||||
fn xargs_null_conflict() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-d\t", "-0n1"])
|
||||
.write_stdin("ab c\0d\tef\0")
|
||||
.assert()
|
||||
@@ -83,16 +77,14 @@ fn xargs_null_conflict() {
|
||||
|
||||
#[test]
|
||||
fn xargs_if_empty() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.assert()
|
||||
.success()
|
||||
.stderr(predicate::str::is_empty())
|
||||
// Should echo at least once still.
|
||||
.stdout(predicate::eq("\n"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["--no-run-if-empty"])
|
||||
.assert()
|
||||
.success()
|
||||
@@ -103,8 +95,7 @@ fn xargs_if_empty() {
|
||||
|
||||
#[test]
|
||||
fn xargs_max_args() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-n2"])
|
||||
.write_stdin("ab cd ef\ngh i")
|
||||
.assert()
|
||||
@@ -116,8 +107,7 @@ fn xargs_max_args() {
|
||||
#[test]
|
||||
fn xargs_max_lines() {
|
||||
for arg in ["-L2", "--max-lines=2"] {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.arg(arg)
|
||||
.write_stdin("ab cd\nef\ngh i\n\njkl\n")
|
||||
.assert()
|
||||
@@ -129,8 +119,7 @@ fn xargs_max_lines() {
|
||||
|
||||
#[test]
|
||||
fn xargs_max_args_lines_conflict() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
// -n2 is last, so it should be given priority.
|
||||
.args(["-L2", "-n2"])
|
||||
.write_stdin("ab cd ef\ngh i")
|
||||
@@ -139,8 +128,7 @@ fn xargs_max_args_lines_conflict() {
|
||||
.stderr(predicate::str::contains("WARNING"))
|
||||
.stdout(predicate::str::diff("ab cd\nef gh\ni\n"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
// -n2 is last, so it should be given priority.
|
||||
.args(["-I=_", "-n2", "echo", "_"])
|
||||
.write_stdin("ab cd ef\ngh i\njkl")
|
||||
@@ -149,8 +137,7 @@ fn xargs_max_args_lines_conflict() {
|
||||
.stderr(predicate::str::contains("WARNING"))
|
||||
.stdout(predicate::str::diff("_ ab cd\n_ ef gh\n_ i jkl\n"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
// -L2 is last, so it should be given priority.
|
||||
.args(["-n2", "-L2"])
|
||||
.write_stdin("ab cd\nef\ngh i\n\njkl\n")
|
||||
@@ -159,8 +146,7 @@ fn xargs_max_args_lines_conflict() {
|
||||
.stderr(predicate::str::contains("WARNING"))
|
||||
.stdout(predicate::str::diff("ab cd ef\ngh i jkl\n"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
// -L2 is last, so it should be given priority.
|
||||
.args(["-I=_", "-L2", "echo", "_"])
|
||||
.write_stdin("ab cd\nef\ngh i\n\njkl\n")
|
||||
@@ -170,8 +156,7 @@ fn xargs_max_args_lines_conflict() {
|
||||
.stdout(predicate::str::diff("_ ab cd ef\n_ gh i jkl\n"));
|
||||
|
||||
for redundant_arg in ["-L2", "-n2"] {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
// -I={} is last, so it should be given priority.
|
||||
.args([redundant_arg, "-I={}", "echo", "{} bar"])
|
||||
.write_stdin("ab cd ef\ngh i\njkl")
|
||||
@@ -185,8 +170,7 @@ fn xargs_max_args_lines_conflict() {
|
||||
#[test]
|
||||
fn xargs_max_chars() {
|
||||
for arg in ["-s11", "--max-chars=11"] {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.arg(arg)
|
||||
.write_stdin("ab cd efg")
|
||||
.assert()
|
||||
@@ -197,8 +181,7 @@ fn xargs_max_chars() {
|
||||
|
||||
// Behavior should be the same with -x, which only takes effect with -L or
|
||||
// -n.
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-xs11"])
|
||||
.write_stdin("ab cd efg")
|
||||
.assert()
|
||||
@@ -206,8 +189,7 @@ fn xargs_max_chars() {
|
||||
.stderr(predicate::str::is_empty())
|
||||
.stdout(predicate::str::diff("ab cd\nefg\n"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-s10"])
|
||||
.write_stdin("abcdefghijkl ab")
|
||||
.assert()
|
||||
@@ -219,8 +201,7 @@ fn xargs_max_chars() {
|
||||
|
||||
#[test]
|
||||
fn xargs_exit_on_large() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-xs11", "-n2"])
|
||||
.write_stdin("ab cd efg h i")
|
||||
.assert()
|
||||
@@ -228,8 +209,7 @@ fn xargs_exit_on_large() {
|
||||
.stderr(predicate::str::is_empty())
|
||||
.stdout(predicate::str::diff("ab cd\nefg h\ni\n"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-xs11", "-n2"])
|
||||
.write_stdin("abcdefg hijklmn")
|
||||
.assert()
|
||||
@@ -241,8 +221,7 @@ fn xargs_exit_on_large() {
|
||||
|
||||
#[test]
|
||||
fn xargs_exec() {
|
||||
let result = Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
let result = cargo_bin_cmd!("xargs")
|
||||
.args([
|
||||
"-n2",
|
||||
&path_to_testing_commandline(),
|
||||
@@ -274,8 +253,7 @@ fn xargs_exec_stdin_open() {
|
||||
write!(temp_file, "a b c").unwrap();
|
||||
temp_file.seek(SeekFrom::Start(0)).unwrap();
|
||||
|
||||
let result = Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
let result = cargo_bin_cmd!("xargs")
|
||||
.args([
|
||||
"-a",
|
||||
&temp_file.path().to_string_lossy(),
|
||||
@@ -303,8 +281,7 @@ fn xargs_exec_stdin_open() {
|
||||
|
||||
#[test]
|
||||
fn xargs_exec_failure() {
|
||||
let result = Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
let result = cargo_bin_cmd!("xargs")
|
||||
.args([
|
||||
"-n1",
|
||||
&path_to_testing_commandline(),
|
||||
@@ -332,8 +309,7 @@ fn xargs_exec_failure() {
|
||||
|
||||
#[test]
|
||||
fn xargs_exec_urgent_failure() {
|
||||
let result = Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
let result = cargo_bin_cmd!("xargs")
|
||||
.args([
|
||||
"-n1",
|
||||
&path_to_testing_commandline(),
|
||||
@@ -361,8 +337,7 @@ fn xargs_exec_urgent_failure() {
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn xargs_exec_with_signal() {
|
||||
let result = Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
let result = cargo_bin_cmd!("xargs")
|
||||
.args([
|
||||
"-n1",
|
||||
&path_to_testing_commandline(),
|
||||
@@ -388,8 +363,7 @@ fn xargs_exec_with_signal() {
|
||||
|
||||
#[test]
|
||||
fn xargs_exec_not_found() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["this-file-does-not-exist"])
|
||||
.assert()
|
||||
.failure()
|
||||
@@ -400,8 +374,7 @@ fn xargs_exec_not_found() {
|
||||
|
||||
#[test]
|
||||
fn xargs_exec_verbose() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args([
|
||||
"-n2",
|
||||
"--verbose",
|
||||
@@ -422,8 +395,7 @@ fn xargs_exec_verbose() {
|
||||
|
||||
#[test]
|
||||
fn xargs_unterminated_quote() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args([
|
||||
"-n2",
|
||||
&path_to_testing_commandline(),
|
||||
@@ -441,8 +413,7 @@ fn xargs_unterminated_quote() {
|
||||
|
||||
#[test]
|
||||
fn xargs_zero_lines() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args([
|
||||
"-L0",
|
||||
&path_to_testing_commandline(),
|
||||
@@ -460,74 +431,64 @@ fn xargs_zero_lines() {
|
||||
|
||||
#[test]
|
||||
fn xargs_replace() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-i={}", "echo", "{} bar"])
|
||||
.write_stdin("foo")
|
||||
.assert()
|
||||
.stdout(predicate::str::contains("foo bar"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-i=_", "echo", "_ bar"])
|
||||
.write_stdin("foo")
|
||||
.assert()
|
||||
.stdout(predicate::str::contains("foo bar"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["--replace=_", "echo", "_ _ bar"])
|
||||
.write_stdin("foo")
|
||||
.assert()
|
||||
.stdout(predicate::str::contains("foo foo bar"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-i=_", "echo", "_ _ bar"])
|
||||
.write_stdin("foo")
|
||||
.assert()
|
||||
.stdout(predicate::str::contains("foo foo bar"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-i", "echo", "{} {} bar"])
|
||||
.write_stdin("foo")
|
||||
.assert()
|
||||
.stdout(predicate::str::contains("foo foo bar"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-I={}", "echo", "{} bar {}"])
|
||||
.write_stdin("foo")
|
||||
.assert()
|
||||
.stdout(predicate::str::contains("foo bar foo"));
|
||||
|
||||
// Combine the two options to see which one wins
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-I=_", "-i", "echo", "{} bar {}"])
|
||||
.write_stdin("foo")
|
||||
.assert()
|
||||
.stdout(predicate::str::contains("foo bar foo"));
|
||||
|
||||
// other order
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-i", "-I=_", "echo", "{} bar {}"])
|
||||
.write_stdin("foo")
|
||||
.assert()
|
||||
.stdout(predicate::str::contains("{} bar {}"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-i", "-I", "_", "echo", "{} bar _"])
|
||||
.write_stdin("foo")
|
||||
.assert()
|
||||
.stdout(predicate::str::contains("{} bar foo"));
|
||||
|
||||
// Expected to fail
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-I", "echo", "_ _ bar"])
|
||||
.write_stdin("foo")
|
||||
.assert()
|
||||
@@ -537,8 +498,7 @@ fn xargs_replace() {
|
||||
|
||||
#[test]
|
||||
fn xargs_replace_multiple_lines() {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-I", "_", "echo", "[_]"])
|
||||
.write_stdin("ab c\nd ef\ng")
|
||||
.assert()
|
||||
@@ -546,8 +506,7 @@ fn xargs_replace_multiple_lines() {
|
||||
.stderr(predicate::str::is_empty())
|
||||
.stdout(predicate::str::diff("[ab c]\n[d ef]\n[g]\n"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-I", "{}", "echo", "{} {} foo"])
|
||||
.write_stdin("bar\nbaz")
|
||||
.assert()
|
||||
@@ -555,8 +514,7 @@ fn xargs_replace_multiple_lines() {
|
||||
.stderr(predicate::str::is_empty())
|
||||
.stdout(predicate::str::diff("bar bar foo\nbaz baz foo\n"));
|
||||
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args(["-I", "non-exist", "echo"])
|
||||
.write_stdin("abc\ndef\ng")
|
||||
.assert()
|
||||
@@ -568,8 +526,7 @@ fn xargs_replace_multiple_lines() {
|
||||
#[test]
|
||||
fn xargs_help() {
|
||||
for option_style in ["-h", "--help"] {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args([option_style])
|
||||
.assert()
|
||||
.success()
|
||||
@@ -587,8 +544,7 @@ fn xargs_help() {
|
||||
#[test]
|
||||
fn xargs_version() {
|
||||
for option_style in ["-V", "--version"] {
|
||||
Command::cargo_bin("xargs")
|
||||
.expect("found binary")
|
||||
cargo_bin_cmd!("xargs")
|
||||
.args([option_style])
|
||||
.assert()
|
||||
.success()
|
||||
|
||||
Reference in New Issue
Block a user