1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 04:27:45 +00:00

Merge branch 'master' into ls/dereference-command-line

This commit is contained in:
Sylvestre Ledru 2021-04-17 10:30:42 +02:00 committed by GitHub
commit eec389fa94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
106 changed files with 2942 additions and 1382 deletions

View file

@ -2,17 +2,13 @@ use crate::common::util::*;
#[test]
fn test_arch() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.run();
assert!(result.success);
new_ucmd!().succeeds();
}
#[test]
fn test_arch_help() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("--help").run();
assert!(result.success);
assert!(result.stdout.contains("architecture name"));
new_ucmd!()
.arg("--help")
.succeeds()
.stdout_contains("architecture name");
}

View file

@ -66,7 +66,7 @@ fn test_zero_param() {
}
fn expect_error(input: Vec<&str>) {
assert!(new_ucmd!().args(&input).fails().no_stdout().stderr.len() > 0);
assert!(new_ucmd!().args(&input).fails().no_stdout().stderr().len() > 0);
}
#[test]

View file

@ -1,7 +1,5 @@
#[cfg(unix)]
extern crate unix_socket;
use crate::common::util::*;
use std::io::Read;
#[test]
fn test_output_simple() {
@ -11,6 +9,131 @@ fn test_output_simple() {
.stdout_only("abcde\nfghij\nklmno\npqrst\nuvwxyz\n");
}
#[test]
fn test_no_options() {
for fixture in &["empty.txt", "alpha.txt", "nonewline.txt"] {
// Give fixture through command line file argument
new_ucmd!()
.args(&[fixture])
.succeeds()
.stdout_is_fixture(fixture);
// Give fixture through stdin
new_ucmd!()
.pipe_in_fixture(fixture)
.succeeds()
.stdout_is_fixture(fixture);
}
}
#[test]
#[cfg(unix)]
fn test_no_options_big_input() {
for &n in &[
0,
1,
42,
16 * 1024 - 7,
16 * 1024 - 1,
16 * 1024,
16 * 1024 + 1,
16 * 1024 + 3,
32 * 1024,
64 * 1024,
80 * 1024,
96 * 1024,
112 * 1024,
128 * 1024,
] {
let data = vec_of_size(n);
let data2 = data.clone();
assert_eq!(data.len(), data2.len());
new_ucmd!().pipe_in(data).succeeds().stdout_is_bytes(&data2);
}
}
#[test]
#[cfg(unix)]
fn test_fifo_symlink() {
use std::fs::OpenOptions;
use std::io::Write;
use std::thread;
let s = TestScenario::new(util_name!());
s.fixtures.mkdir("dir");
s.fixtures.mkfifo("dir/pipe");
assert!(s.fixtures.is_fifo("dir/pipe"));
// Make cat read the pipe through a symlink
s.fixtures.symlink_file("dir/pipe", "sympipe");
let proc = s.ucmd().args(&["sympipe"]).run_no_wait();
let data = vec_of_size(128 * 1024);
let data2 = data.clone();
let pipe_path = s.fixtures.plus("dir/pipe");
let thread = thread::spawn(move || {
let mut pipe = OpenOptions::new()
.write(true)
.create(false)
.open(pipe_path)
.unwrap();
pipe.write_all(&data).unwrap();
});
let output = proc.wait_with_output().unwrap();
assert_eq!(&output.stdout, &data2);
thread.join().unwrap();
}
#[test]
fn test_directory() {
let s = TestScenario::new(util_name!());
s.fixtures.mkdir("test_directory");
s.ucmd()
.args(&["test_directory"])
.fails()
.stderr_is("cat: test_directory: Is a directory");
}
#[test]
fn test_directory_and_file() {
let s = TestScenario::new(util_name!());
s.fixtures.mkdir("test_directory2");
for fixture in &["empty.txt", "alpha.txt", "nonewline.txt"] {
s.ucmd()
.args(&["test_directory2", fixture])
.fails()
.stderr_is("cat: test_directory2: Is a directory")
.stdout_is_fixture(fixture);
}
}
#[test]
#[cfg(unix)]
fn test_three_directories_and_file_and_stdin() {
let s = TestScenario::new(util_name!());
s.fixtures.mkdir("test_directory3");
s.fixtures.mkdir("test_directory3/test_directory4");
s.fixtures.mkdir("test_directory3/test_directory5");
s.ucmd()
.args(&[
"test_directory3/test_directory4",
"alpha.txt",
"-",
"filewhichdoesnotexist.txt",
"nonewline.txt",
"test_directory3/test_directory5",
"test_directory3/../test_directory3/test_directory5",
"test_directory3",
])
.pipe_in("stdout bytes")
.fails()
.stderr_is_fixture("three_directories_and_file_and_stdin.stderr.expected")
.stdout_is(
"abcde\nfghij\nklmno\npqrst\nuvwxyz\nstdout bytestext without a trailing newline",
);
}
#[test]
fn test_output_multi_files_print_all_chars() {
new_ucmd!()
@ -149,13 +272,64 @@ fn test_squeeze_blank_before_numbering() {
}
}
/// This tests reading from Unix character devices
#[test]
#[cfg(foo)]
#[cfg(unix)]
fn test_dev_random() {
let mut buf = [0; 2048];
let mut proc = new_ucmd!().args(&["/dev/random"]).run_no_wait();
let mut proc_stdout = proc.stdout.take().unwrap();
proc_stdout.read_exact(&mut buf).unwrap();
let num_zeroes = buf.iter().fold(0, |mut acc, &n| {
if n == 0 {
acc += 1;
}
acc
});
// The probability of more than 512 zero bytes is essentially zero if the
// output is truly random.
assert!(num_zeroes < 512);
proc.kill().unwrap();
}
/// Reading from /dev/full should return an infinite amount of zero bytes.
/// Wikipedia says there is support on Linux, FreeBSD, and NetBSD.
#[test]
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
fn test_dev_full() {
let mut buf = [0; 2048];
let mut proc = new_ucmd!().args(&["/dev/full"]).run_no_wait();
let mut proc_stdout = proc.stdout.take().unwrap();
let expected = [0; 2048];
proc_stdout.read_exact(&mut buf).unwrap();
assert_eq!(&buf[..], &expected[..]);
proc.kill().unwrap();
}
#[test]
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
fn test_dev_full_show_all() {
let mut buf = [0; 2048];
let mut proc = new_ucmd!().args(&["-A", "/dev/full"]).run_no_wait();
let mut proc_stdout = proc.stdout.take().unwrap();
proc_stdout.read_exact(&mut buf).unwrap();
let expected: Vec<u8> = (0..buf.len())
.map(|n| if n & 1 == 0 { b'^' } else { b'@' })
.collect();
assert_eq!(&buf[..], &expected[..]);
proc.kill().unwrap();
}
#[test]
#[cfg(unix)]
fn test_domain_socket() {
use self::tempdir::TempDir;
use self::unix_socket::UnixListener;
use std::io::prelude::*;
use std::thread;
use tempdir::TempDir;
use unix_socket::UnixListener;
let dir = TempDir::new("unix_socket").expect("failed to create dir");
let socket_path = dir.path().join("sock");

View file

@ -149,7 +149,7 @@ fn test_big_h() {
.arg("bin")
.arg("/proc/self/fd")
.fails()
.stderr
.stderr_str()
.lines()
.fold(0, |acc, _| acc + 1)
> 1

View file

@ -48,7 +48,7 @@ fn run_single_test(test: &TestCase, at: AtPath, mut ucmd: UCommand) {
}
let r = ucmd.run();
if !r.success {
println!("{}", r.stderr);
println!("{}", r.stderr_str());
panic!("{:?}: failed", ucmd.raw);
}
@ -297,13 +297,14 @@ fn test_chmod_recursive() {
mkfile(&at.plus_as_string("a/b/c/c"), 0o100444);
mkfile(&at.plus_as_string("z/y"), 0o100444);
let result = ucmd
.arg("-R")
ucmd.arg("-R")
.arg("--verbose")
.arg("-r,a+w")
.arg("a")
.arg("z")
.succeeds();
.succeeds()
.stderr_contains(&"to 333 (-wx-wx-wx)")
.stderr_contains(&"to 222 (-w--w--w-)");
assert_eq!(at.metadata("z/y").permissions().mode(), 0o100222);
assert_eq!(at.metadata("a/a").permissions().mode(), 0o100222);
@ -312,8 +313,6 @@ fn test_chmod_recursive() {
println!("mode {:o}", at.metadata("a").permissions().mode());
assert_eq!(at.metadata("a").permissions().mode(), 0o40333);
assert_eq!(at.metadata("z").permissions().mode(), 0o40333);
assert!(result.stderr.contains("to 333 (-wx-wx-wx)"));
assert!(result.stderr.contains("to 222 (-w--w--w-)"));
unsafe {
umask(original_umask);
@ -322,30 +321,24 @@ fn test_chmod_recursive() {
#[test]
fn test_chmod_non_existing_file() {
let (_at, mut ucmd) = at_and_ucmd!();
let result = ucmd
new_ucmd!()
.arg("-R")
.arg("--verbose")
.arg("-r,a+w")
.arg("dont-exist")
.fails();
assert!(result
.stderr
.contains("cannot access 'dont-exist': No such file or directory"));
.fails()
.stderr_contains(&"cannot access 'dont-exist': No such file or directory");
}
#[test]
fn test_chmod_preserve_root() {
let (_at, mut ucmd) = at_and_ucmd!();
let result = ucmd
new_ucmd!()
.arg("-R")
.arg("--preserve-root")
.arg("755")
.arg("/")
.fails();
assert!(result
.stderr
.contains("chmod: error: it is dangerous to operate recursively on '/'"));
.fails()
.stderr_contains(&"chmod: error: it is dangerous to operate recursively on '/'");
}
#[test]
@ -362,33 +355,27 @@ fn test_chmod_symlink_non_existing_file() {
let expected_stderr = &format!("cannot operate on dangling symlink '{}'", test_symlink);
at.symlink_file(non_existing, test_symlink);
let mut result;
// this cannot succeed since the symbolic link dangles
result = scene.ucmd().arg("755").arg("-v").arg(test_symlink).fails();
println!("stdout = {:?}", result.stdout);
println!("stderr = {:?}", result.stderr);
assert!(result.stdout.contains(expected_stdout));
assert!(result.stderr.contains(expected_stderr));
assert_eq!(result.code, Some(1));
scene.ucmd()
.arg("755")
.arg("-v")
.arg(test_symlink)
.fails()
.code_is(1)
.stdout_contains(expected_stdout)
.stderr_contains(expected_stderr);
// this should be the same than with just '-v' but without stderr
result = scene
.ucmd()
scene.ucmd()
.arg("755")
.arg("-v")
.arg("-f")
.arg(test_symlink)
.fails();
println!("stdout = {:?}", result.stdout);
println!("stderr = {:?}", result.stderr);
assert!(result.stdout.contains(expected_stdout));
assert!(result.stderr.is_empty());
assert_eq!(result.code, Some(1));
.run()
.code_is(1)
.no_stderr()
.stdout_contains(expected_stdout);
}
#[test]
@ -405,18 +392,15 @@ fn test_chmod_symlink_non_existing_file_recursive() {
non_existing,
&format!("{}/{}", test_directory, test_symlink),
);
let mut result;
// this should succeed
result = scene
.ucmd()
scene.ucmd()
.arg("-R")
.arg("755")
.arg(test_directory)
.succeeds();
assert_eq!(result.code, Some(0));
assert!(result.stdout.is_empty());
assert!(result.stderr.is_empty());
.succeeds()
.no_stderr()
.no_stdout();
let expected_stdout = &format!(
"mode of '{}' retained as 0755 (rwxr-xr-x)\nneither symbolic link '{}/{}' nor referent has been changed",
@ -424,37 +408,25 @@ fn test_chmod_symlink_non_existing_file_recursive() {
);
// '-v': this should succeed without stderr
result = scene
.ucmd()
scene.ucmd()
.arg("-R")
.arg("-v")
.arg("755")
.arg(test_directory)
.succeeds();
println!("stdout = {:?}", result.stdout);
println!("stderr = {:?}", result.stderr);
assert!(result.stdout.contains(expected_stdout));
assert!(result.stderr.is_empty());
assert_eq!(result.code, Some(0));
.succeeds()
.stdout_contains(expected_stdout)
.no_stderr();
// '-vf': this should be the same than with just '-v'
result = scene
.ucmd()
scene.ucmd()
.arg("-R")
.arg("-v")
.arg("-f")
.arg("755")
.arg(test_directory)
.succeeds();
println!("stdout = {:?}", result.stdout);
println!("stderr = {:?}", result.stderr);
assert!(result.stdout.contains(expected_stdout));
assert!(result.stderr.is_empty());
assert_eq!(result.code, Some(0));
.succeeds()
.stdout_contains(expected_stdout)
.no_stderr();
}
#[test]

View file

@ -53,22 +53,22 @@ fn test_chown_myself() {
// test chown username file.txt
let scene = TestScenario::new(util_name!());
let result = scene.cmd("whoami").run();
if is_ci() && result.stderr.contains("No such user/group") {
if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("results {}", result.stdout);
let username = result.stdout.trim_end();
println!("results {}", result.stdout_str());
let username = result.stdout_str().trim_end();
let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1";
at.touch(file1);
let result = ucmd.arg(username).arg(file1).run();
println!("results stdout {}", result.stdout);
println!("results stderr {}", result.stderr);
if is_ci() && result.stderr.contains("invalid user") {
println!("results stdout {}", result.stdout_str());
println!("results stderr {}", result.stderr_str());
if is_ci() && result.stderr_str().contains("invalid user") {
// In the CI, some server are failing to return id.
// As seems to be a configuration issue, ignoring it
return;
@ -81,24 +81,24 @@ fn test_chown_myself_second() {
// test chown username: file.txt
let scene = TestScenario::new(util_name!());
let result = scene.cmd("whoami").run();
if is_ci() && result.stderr.contains("No such user/group") {
if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("results {}", result.stdout);
println!("results {}", result.stdout_str());
let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1";
at.touch(file1);
let result = ucmd
.arg(result.stdout.trim_end().to_owned() + ":")
.arg(result.stdout_str().trim_end().to_owned() + ":")
.arg(file1)
.run();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
assert!(result.success);
}
@ -107,31 +107,31 @@ fn test_chown_myself_group() {
// test chown username:group file.txt
let scene = TestScenario::new(util_name!());
let result = scene.cmd("whoami").run();
if is_ci() && result.stderr.contains("No such user/group") {
if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("user name = {}", result.stdout);
let username = result.stdout.trim_end();
println!("user name = {}", result.stdout_str());
let username = result.stdout_str().trim_end();
let result = scene.cmd("id").arg("-gn").run();
if is_ci() && result.stderr.contains("No such user/group") {
if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("group name = {}", result.stdout);
let group = result.stdout.trim_end();
println!("group name = {}", result.stdout_str());
let group = result.stdout_str().trim_end();
let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1";
let perm = username.to_owned() + ":" + group;
at.touch(file1);
let result = ucmd.arg(perm).arg(file1).run();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
if is_ci() && result.stderr.contains("chown: invalid group:") {
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr_str().contains("chown: invalid group:") {
// With some Ubuntu into the CI, we can get this answer
return;
}
@ -143,27 +143,27 @@ fn test_chown_only_group() {
// test chown :group file.txt
let scene = TestScenario::new(util_name!());
let result = scene.cmd("whoami").run();
if is_ci() && result.stderr.contains("No such user/group") {
if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("results {}", result.stdout);
println!("results {}", result.stdout_str());
let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1";
let perm = ":".to_owned() + result.stdout.trim_end();
let perm = ":".to_owned() + result.stdout_str().trim_end();
at.touch(file1);
let result = ucmd.arg(perm).arg(file1).run();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr.contains("Operation not permitted") {
if is_ci() && result.stderr_str().contains("Operation not permitted") {
// With ubuntu with old Rust in the CI, we can get an error
return;
}
if is_ci() && result.stderr.contains("chown: invalid group:") {
if is_ci() && result.stderr_str().contains("chown: invalid group:") {
// With mac into the CI, we can get this answer
return;
}
@ -174,14 +174,14 @@ fn test_chown_only_group() {
fn test_chown_only_id() {
// test chown 1111 file.txt
let result = TestScenario::new("id").ucmd_keepenv().arg("-u").run();
if is_ci() && result.stderr.contains("No such user/group") {
if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
let id = String::from(result.stdout.trim());
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
let id = String::from(result.stdout_str().trim());
let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1";
@ -189,9 +189,9 @@ fn test_chown_only_id() {
at.touch(file1);
let result = ucmd.arg(id).arg(file1).run();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
if is_ci() && result.stderr.contains("chown: invalid user:") {
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr_str().contains("chown: invalid user:") {
// With some Ubuntu into the CI, we can get this answer
return;
}
@ -202,14 +202,14 @@ fn test_chown_only_id() {
fn test_chown_only_group_id() {
// test chown :1111 file.txt
let result = TestScenario::new("id").ucmd_keepenv().arg("-g").run();
if is_ci() && result.stderr.contains("No such user/group") {
if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
let id = String::from(result.stdout.trim());
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
let id = String::from(result.stdout_str().trim());
let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1";
@ -219,9 +219,9 @@ fn test_chown_only_group_id() {
let result = ucmd.arg(perm).arg(file1).run();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
if is_ci() && result.stderr.contains("chown: invalid group:") {
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr_str().contains("chown: invalid group:") {
// With mac into the CI, we can get this answer
return;
}
@ -232,24 +232,24 @@ fn test_chown_only_group_id() {
fn test_chown_both_id() {
// test chown 1111:1111 file.txt
let result = TestScenario::new("id").ucmd_keepenv().arg("-u").run();
if is_ci() && result.stderr.contains("No such user/group") {
if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
let id_user = String::from(result.stdout.trim());
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
let id_user = String::from(result.stdout_str().trim());
let result = TestScenario::new("id").ucmd_keepenv().arg("-g").run();
if is_ci() && result.stderr.contains("No such user/group") {
if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
let id_group = String::from(result.stdout.trim());
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
let id_group = String::from(result.stdout_str().trim());
let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1";
@ -258,10 +258,10 @@ fn test_chown_both_id() {
let perm = id_user + &":".to_owned() + &id_group;
let result = ucmd.arg(perm).arg(file1).run();
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr.contains("invalid user") {
if is_ci() && result.stderr_str().contains("invalid user") {
// In the CI, some server are failing to return id.
// As seems to be a configuration issue, ignoring it
return;
@ -274,24 +274,24 @@ fn test_chown_both_id() {
fn test_chown_both_mix() {
// test chown 1111:1111 file.txt
let result = TestScenario::new("id").ucmd_keepenv().arg("-u").run();
if is_ci() && result.stderr.contains("No such user/group") {
if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
let id_user = String::from(result.stdout.trim());
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
let id_user = String::from(result.stdout_str().trim());
let result = TestScenario::new("id").ucmd_keepenv().arg("-gn").run();
if is_ci() && result.stderr.contains("No such user/group") {
if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
let group_name = String::from(result.stdout.trim());
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
let group_name = String::from(result.stdout_str().trim());
let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1";
@ -301,7 +301,7 @@ fn test_chown_both_mix() {
let result = ucmd.arg(perm).arg(file1).run();
if is_ci() && result.stderr.contains("invalid user") {
if is_ci() && result.stderr_str().contains("invalid user") {
// In the CI, some server are failing to return id.
// As seems to be a configuration issue, ignoring it
return;
@ -313,14 +313,14 @@ fn test_chown_both_mix() {
fn test_chown_recursive() {
let scene = TestScenario::new(util_name!());
let result = scene.cmd("whoami").run();
if is_ci() && result.stderr.contains("No such user/group") {
if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
let username = result.stdout.trim_end();
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
let username = result.stdout_str().trim_end();
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("a");
@ -339,31 +339,32 @@ fn test_chown_recursive() {
.arg("a")
.arg("z")
.run();
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
if is_ci() && result.stderr.contains("invalid user") {
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr_str().contains("invalid user") {
// In the CI, some server are failing to return id.
// As seems to be a configuration issue, ignoring it
return;
}
assert!(result.stderr.contains("ownership of 'a/a' retained as"));
assert!(result.stderr.contains("ownership of 'z/y' retained as"));
assert!(result.success);
result
.stderr_contains(&"ownership of 'a/a' retained as")
.stderr_contains(&"ownership of 'z/y' retained as")
.success();
}
#[test]
fn test_root_preserve() {
let scene = TestScenario::new(util_name!());
let result = scene.cmd("whoami").run();
if is_ci() && result.stderr.contains("No such user/group") {
if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
let username = result.stdout.trim_end();
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
let username = result.stdout_str().trim_end();
let result = new_ucmd!()
.arg("--preserve-root")
@ -371,9 +372,9 @@ fn test_root_preserve() {
.arg(username)
.arg("/")
.fails();
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
if is_ci() && result.stderr.contains("invalid user") {
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr_str().contains("invalid user") {
// In the CI, some server are failing to return id.
// As seems to be a configuration issue, ignoring it
return;

View file

@ -64,14 +64,14 @@ fn test_preference_of_userspec() {
// As seems to be a configuration issue, ignoring it
return;
}
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
let username = result.stdout.trim_end();
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
let username = result.stdout_str().trim_end();
let ts = TestScenario::new("id");
let result = ts.cmd("id").arg("-g").arg("-n").run();
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr.contains("cannot find name for user ID") {
// In the CI, some server are failing to return id.
@ -79,7 +79,7 @@ fn test_preference_of_userspec() {
return;
}
let group_name = result.stdout.trim_end();
let group_name = result.stdout_str().trim_end();
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("a");
@ -93,6 +93,6 @@ fn test_preference_of_userspec() {
.arg(format!("--userspec={}:{}", username, group_name))
.run();
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
}

View file

@ -35,14 +35,19 @@ fn test_empty() {
}
#[test]
#[ignore]
fn test_arg_overrides_stdin() {
let (at, mut ucmd) = at_and_ucmd!();
let input = "foobarfoobar";
at.touch("a");
let result = ucmd.arg("a").pipe_in(input.as_bytes()).run();
let result = ucmd
.arg("a")
.pipe_in(input.as_bytes())
// the command might have exited before all bytes have been pipe in.
// in that case, we don't care about the error (broken pipe)
.ignore_stdin_write_error()
.run();
println!("{}, {}", result.stdout, result.stderr);

View file

@ -275,8 +275,8 @@ fn test_cp_arg_no_clobber_twice() {
.arg("dest.txt")
.run();
println!("stderr = {:?}", result.stderr);
println!("stdout = {:?}", result.stdout);
println!("stderr = {:?}", result.stderr_str());
println!("stdout = {:?}", result.stdout_str());
assert!(result.success);
assert!(result.stderr.is_empty());
assert_eq!(at.read("source.txt"), "");
@ -317,8 +317,8 @@ fn test_cp_arg_force() {
.arg(TEST_HELLO_WORLD_DEST)
.run();
println!("{:?}", result.stderr);
println!("{:?}", result.stdout);
println!("{:?}", result.stderr_str());
println!("{:?}", result.stdout_str());
assert!(result.success);
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
@ -602,7 +602,7 @@ fn test_cp_deref_folder_to_folder() {
.arg(TEST_COPY_FROM_FOLDER)
.arg(TEST_COPY_TO_FOLDER_NEW)
.run();
println!("cp output {}", result.stdout);
println!("cp output {}", result.stdout_str());
// Check that the exit code represents a successful copy.
assert!(result.success);
@ -611,12 +611,12 @@ fn test_cp_deref_folder_to_folder() {
{
let scene2 = TestScenario::new("ls");
let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run();
println!("ls source {}", result.stdout);
println!("ls source {}", result.stdout_str());
let path_to_new_symlink = at.subdir.join(TEST_COPY_TO_FOLDER_NEW);
let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run();
println!("ls dest {}", result.stdout);
println!("ls dest {}", result.stdout_str());
}
#[cfg(windows)]
@ -706,7 +706,7 @@ fn test_cp_no_deref_folder_to_folder() {
.arg(TEST_COPY_FROM_FOLDER)
.arg(TEST_COPY_TO_FOLDER_NEW)
.run();
println!("cp output {}", result.stdout);
println!("cp output {}", result.stdout_str());
// Check that the exit code represents a successful copy.
assert!(result.success);
@ -715,12 +715,12 @@ fn test_cp_no_deref_folder_to_folder() {
{
let scene2 = TestScenario::new("ls");
let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run();
println!("ls source {}", result.stdout);
println!("ls source {}", result.stdout_str());
let path_to_new_symlink = at.subdir.join(TEST_COPY_TO_FOLDER_NEW);
let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run();
println!("ls dest {}", result.stdout);
println!("ls dest {}", result.stdout_str());
}
#[cfg(windows)]
@ -809,7 +809,7 @@ fn test_cp_archive() {
let scene2 = TestScenario::new("ls");
let result = scene2.cmd("ls").arg("-al").arg(at.subdir).run();
println!("ls dest {}", result.stdout);
println!("ls dest {}", result.stdout_str());
assert_eq!(creation, creation2);
assert!(result.success);
}
@ -863,7 +863,7 @@ fn test_cp_archive_recursive() {
.arg(&at.subdir.join(TEST_COPY_TO_FOLDER))
.run();
println!("ls dest {}", result.stdout);
println!("ls dest {}", result.stdout_str());
let scene2 = TestScenario::new("ls");
let result = scene2
@ -872,7 +872,7 @@ fn test_cp_archive_recursive() {
.arg(&at.subdir.join(TEST_COPY_TO_FOLDER_NEW))
.run();
println!("ls dest {}", result.stdout);
println!("ls dest {}", result.stdout_str());
assert!(at.file_exists(
&at.subdir
.join(TEST_COPY_TO_FOLDER_NEW)
@ -946,7 +946,7 @@ fn test_cp_preserve_timestamps() {
let scene2 = TestScenario::new("ls");
let result = scene2.cmd("ls").arg("-al").arg(at.subdir).run();
println!("ls dest {}", result.stdout);
println!("ls dest {}", result.stdout_str());
assert_eq!(creation, creation2);
assert!(result.success);
}
@ -984,7 +984,7 @@ fn test_cp_dont_preserve_timestamps() {
let scene2 = TestScenario::new("ls");
let result = scene2.cmd("ls").arg("-al").arg(at.subdir).run();
println!("ls dest {}", result.stdout);
println!("ls dest {}", result.stdout_str());
println!("creation {:?} / {:?}", creation, creation2);
assert_ne!(creation, creation2);

View file

@ -28,13 +28,13 @@ fn test_date_rfc_3339() {
// Check that the output matches the regexp
let rfc_regexp = r"(\d+)-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])\s([01]\d|2[0-3]):([0-5]\d):([0-5]\d|60)(\.\d+)?(([Zz])|([\+|\-]([01]\d|2[0-3])))";
let re = Regex::new(rfc_regexp).unwrap();
assert!(re.is_match(&result.stdout.trim()));
assert!(re.is_match(&result.stdout_str().trim()));
result = scene.ucmd().arg("--rfc-3339=seconds").succeeds();
// Check that the output matches the regexp
let re = Regex::new(rfc_regexp).unwrap();
assert!(re.is_match(&result.stdout.trim()));
assert!(re.is_match(&result.stdout_str().trim()));
}
#[test]
@ -73,13 +73,13 @@ fn test_date_format_y() {
assert!(result.success);
let mut re = Regex::new(r"^\d{4}$").unwrap();
assert!(re.is_match(&result.stdout.trim()));
assert!(re.is_match(&result.stdout_str().trim()));
result = scene.ucmd().arg("+%y").succeeds();
assert!(result.success);
re = Regex::new(r"^\d{2}$").unwrap();
assert!(re.is_match(&result.stdout.trim()));
assert!(re.is_match(&result.stdout_str().trim()));
}
#[test]
@ -90,13 +90,13 @@ fn test_date_format_m() {
assert!(result.success);
let mut re = Regex::new(r"\S+").unwrap();
assert!(re.is_match(&result.stdout.trim()));
assert!(re.is_match(&result.stdout_str().trim()));
result = scene.ucmd().arg("+%m").succeeds();
assert!(result.success);
re = Regex::new(r"^\d{2}$").unwrap();
assert!(re.is_match(&result.stdout.trim()));
assert!(re.is_match(&result.stdout_str().trim()));
}
#[test]
@ -107,20 +107,20 @@ fn test_date_format_day() {
assert!(result.success);
let mut re = Regex::new(r"\S+").unwrap();
assert!(re.is_match(&result.stdout.trim()));
assert!(re.is_match(&result.stdout_str().trim()));
result = scene.ucmd().arg("+%A").succeeds();
assert!(result.success);
re = Regex::new(r"\S+").unwrap();
assert!(re.is_match(&result.stdout.trim()));
assert!(re.is_match(&result.stdout_str().trim()));
result = scene.ucmd().arg("+%u").succeeds();
assert!(result.success);
re = Regex::new(r"^\d{1}$").unwrap();
assert!(re.is_match(&result.stdout.trim()));
assert!(re.is_match(&result.stdout_str().trim()));
}
#[test]
@ -131,7 +131,7 @@ fn test_date_format_full_day() {
assert!(result.success);
let re = Regex::new(r"\S+ \d{4}-\d{2}-\d{2}").unwrap();
assert!(re.is_match(&result.stdout.trim()));
assert!(re.is_match(&result.stdout_str().trim()));
}
#[test]

View file

@ -7,10 +7,9 @@ const SUB_LINK: &str = "subdir/links/sublink.txt";
#[test]
fn test_du_basics() {
let (_at, mut ucmd) = at_and_ucmd!();
let result = ucmd.run();
assert!(result.success);
assert_eq!(result.stderr, "");
new_ucmd!()
.succeeds()
.no_stderr();
}
#[cfg(target_vendor = "apple")]
fn _du_basics(s: String) {
@ -22,7 +21,7 @@ fn _du_basics(s: String) {
assert_eq!(s, answer);
}
#[cfg(not(target_vendor = "apple"))]
fn _du_basics(s: String) {
fn _du_basics(s: &str) {
let answer = "28\t./subdir
8\t./subdir/deeper
16\t./subdir/links
@ -38,19 +37,19 @@ fn test_du_basics_subdir() {
let result = ucmd.arg(SUB_DIR).run();
assert!(result.success);
assert_eq!(result.stderr, "");
_du_basics_subdir(result.stdout);
_du_basics_subdir(result.stdout_str());
}
#[cfg(target_vendor = "apple")]
fn _du_basics_subdir(s: String) {
fn _du_basics_subdir(s: &str) {
assert_eq!(s, "4\tsubdir/deeper\n");
}
#[cfg(target_os = "windows")]
fn _du_basics_subdir(s: String) {
fn _du_basics_subdir(s: &str) {
assert_eq!(s, "0\tsubdir/deeper\n");
}
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
fn _du_basics_subdir(s: String) {
fn _du_basics_subdir(s: &str) {
// MS-WSL linux has altered expected output
if !is_wsl() {
assert_eq!(s, "8\tsubdir/deeper\n");
@ -64,7 +63,7 @@ fn test_du_basics_bad_name() {
let (_at, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("bad_name").run();
assert_eq!(result.stdout, "");
assert_eq!(result.stdout_str(), "");
assert_eq!(
result.stderr,
"du: error: bad_name: No such file or directory\n"
@ -81,20 +80,20 @@ fn test_du_soft_link() {
let result = ts.ucmd().arg(SUB_DIR_LINKS).run();
assert!(result.success);
assert_eq!(result.stderr, "");
_du_soft_link(result.stdout);
_du_soft_link(result.stdout_str());
}
#[cfg(target_vendor = "apple")]
fn _du_soft_link(s: String) {
fn _du_soft_link(s: &str) {
// 'macos' host variants may have `du` output variation for soft links
assert!((s == "12\tsubdir/links\n") || (s == "16\tsubdir/links\n"));
}
#[cfg(target_os = "windows")]
fn _du_soft_link(s: String) {
fn _du_soft_link(s: &str) {
assert_eq!(s, "8\tsubdir/links\n");
}
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
fn _du_soft_link(s: String) {
fn _du_soft_link(s: &str) {
// MS-WSL linux has altered expected output
if !is_wsl() {
assert_eq!(s, "16\tsubdir/links\n");
@ -114,19 +113,19 @@ fn test_du_hard_link() {
assert!(result.success);
assert_eq!(result.stderr, "");
// We do not double count hard links as the inodes are identical
_du_hard_link(result.stdout);
_du_hard_link(result.stdout_str());
}
#[cfg(target_vendor = "apple")]
fn _du_hard_link(s: String) {
fn _du_hard_link(s: &str) {
assert_eq!(s, "12\tsubdir/links\n")
}
#[cfg(target_os = "windows")]
fn _du_hard_link(s: String) {
fn _du_hard_link(s: &str) {
assert_eq!(s, "8\tsubdir/links\n")
}
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
fn _du_hard_link(s: String) {
fn _du_hard_link(s: &str) {
// MS-WSL linux has altered expected output
if !is_wsl() {
assert_eq!(s, "16\tsubdir/links\n");
@ -142,19 +141,19 @@ fn test_du_d_flag() {
let result = ts.ucmd().arg("-d").arg("1").run();
assert!(result.success);
assert_eq!(result.stderr, "");
_du_d_flag(result.stdout);
_du_d_flag(result.stdout_str());
}
#[cfg(target_vendor = "apple")]
fn _du_d_flag(s: String) {
fn _du_d_flag(s: &str) {
assert_eq!(s, "16\t./subdir\n20\t./\n");
}
#[cfg(target_os = "windows")]
fn _du_d_flag(s: String) {
fn _du_d_flag(s: &str) {
assert_eq!(s, "8\t./subdir\n8\t./\n");
}
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
fn _du_d_flag(s: String) {
fn _du_d_flag(s: &str) {
// MS-WSL linux has altered expected output
if !is_wsl() {
assert_eq!(s, "28\t./subdir\n36\t./\n");
@ -167,10 +166,11 @@ fn _du_d_flag(s: String) {
fn test_du_h_flag_empty_file() {
let ts = TestScenario::new("du");
let result = ts.ucmd().arg("-h").arg("empty.txt").run();
assert!(result.success);
assert_eq!(result.stderr, "");
assert_eq!(result.stdout, "0\tempty.txt\n");
ts.ucmd()
.arg("-h")
.arg("empty.txt")
.succeeds()
.stdout_only("0\tempty.txt\n");
}
#[cfg(feature = "touch")]
@ -190,3 +190,33 @@ fn test_du_time() {
assert_eq!(result.stderr, "");
assert_eq!(result.stdout, "0\t2015-05-15 00:00\tdate_test\n");
}
#[cfg(not(target_os = "windows"))]
#[cfg(feature = "chmod")]
#[test]
fn test_du_no_permission() {
let ts = TestScenario::new("du");
let chmod = ts.ccmd("chmod").arg("-r").arg(SUB_DIR_LINKS).run();
println!("chmod output: {:?}", chmod);
assert!(chmod.success);
let result = ts.ucmd().arg(SUB_DIR_LINKS).run();
ts.ccmd("chmod").arg("+r").arg(SUB_DIR_LINKS).run();
assert!(result.success);
assert_eq!(
result.stderr,
"du: cannot read directory subdir/links: Permission denied (os error 13)\n"
);
_du_no_permission(result.stdout);
}
#[cfg(target_vendor = "apple")]
fn _du_no_permission(s: String) {
assert_eq!(s, "0\tsubdir/links\n");
}
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
fn _du_no_permission(s: String) {
assert_eq!(s, "4\tsubdir/links\n");
}

View file

@ -2,22 +2,20 @@ use crate::common::util::*;
#[test]
fn test_default() {
//CmdResult.stdout_only(...) trims trailing newlines
assert_eq!("hi\n", new_ucmd!().arg("hi").succeeds().no_stderr().stdout);
new_ucmd!()
.arg("hi")
.succeeds()
.stdout_only("hi\n");
}
#[test]
fn test_no_trailing_newline() {
//CmdResult.stdout_only(...) trims trailing newlines
assert_eq!(
"hi",
new_ucmd!()
.arg("-n")
.arg("hi")
.succeeds()
.no_stderr()
.stdout
);
new_ucmd!()
.arg("-n")
.arg("hi")
.succeeds()
.no_stderr()
.stdout_only("hi");
}
#[test]
@ -192,39 +190,38 @@ fn test_hyphen_values_inside_string() {
new_ucmd!()
.arg("'\"\n'CXXFLAGS=-g -O2'\n\"'")
.succeeds()
.stdout
.contains("CXXFLAGS");
.stdout_contains("CXXFLAGS");
}
#[test]
fn test_hyphen_values_at_start() {
let result = new_ucmd!()
new_ucmd!()
.arg("-E")
.arg("-test")
.arg("araba")
.arg("-merci")
.run();
assert!(result.success);
assert_eq!(false, result.stdout.contains("-E"));
assert_eq!(result.stdout, "-test araba -merci\n");
.run()
.success()
.stdout_does_not_contain("-E")
.stdout_is("-test araba -merci\n");
}
#[test]
fn test_hyphen_values_between() {
let result = new_ucmd!().arg("test").arg("-E").arg("araba").run();
new_ucmd!()
.arg("test")
.arg("-E")
.arg("araba")
.run()
.success()
.stdout_is("test -E araba\n");
assert!(result.success);
assert_eq!(result.stdout, "test -E araba\n");
let result = new_ucmd!()
new_ucmd!()
.arg("dumdum ")
.arg("dum dum dum")
.arg("-e")
.arg("dum")
.run();
assert!(result.success);
assert_eq!(result.stdout, "dumdum dum dum dum -e dum\n");
assert_eq!(true, result.stdout.contains("-e"));
.run()
.success()
.stdout_is("dumdum dum dum dum -e dum\n");
}

View file

@ -8,45 +8,35 @@ use tempfile::tempdir;
#[test]
fn test_env_help() {
assert!(new_ucmd!()
new_ucmd!()
.arg("--help")
.succeeds()
.no_stderr()
.stdout
.contains("OPTIONS:"));
.stdout_contains("OPTIONS:");
}
#[test]
fn test_env_version() {
assert!(new_ucmd!()
new_ucmd!()
.arg("--version")
.succeeds()
.no_stderr()
.stdout
.contains(util_name!()));
.stdout_contains(util_name!());
}
#[test]
fn test_echo() {
// assert!(new_ucmd!().arg("printf").arg("FOO-bar").succeeds().no_stderr().stdout.contains("FOO-bar"));
let mut cmd = new_ucmd!();
cmd.arg("echo").arg("FOO-bar");
println!("cmd={:?}", cmd);
let result = new_ucmd!()
.arg("echo")
.arg("FOO-bar")
.succeeds();
let result = cmd.run();
println!("success={:?}", result.success);
println!("stdout={:?}", result.stdout);
println!("stderr={:?}", result.stderr);
assert!(result.success);
let out = result.stdout.trim_end();
assert_eq!(out, "FOO-bar");
assert_eq!(result.stdout_str().trim(), "FOO-bar");
}
#[test]
fn test_file_option() {
let out = new_ucmd!().arg("-f").arg("vars.conf.txt").run().stdout;
let out = new_ucmd!().arg("-f").arg("vars.conf.txt").run().stdout_move_str();
assert_eq!(
out.lines()
@ -63,7 +53,7 @@ fn test_combined_file_set() {
.arg("vars.conf.txt")
.arg("FOO=bar.alt")
.run()
.stdout;
.stdout_move_str();
assert_eq!(out.lines().filter(|&line| line == "FOO=bar.alt").count(), 1);
}
@ -76,8 +66,8 @@ fn test_combined_file_set_unset() {
.arg("-f")
.arg("vars.conf.txt")
.arg("FOO=bar.alt")
.run()
.stdout;
.succeeds()
.stdout_move_str();
assert_eq!(
out.lines()
@ -89,17 +79,17 @@ fn test_combined_file_set_unset() {
#[test]
fn test_single_name_value_pair() {
let out = new_ucmd!().arg("FOO=bar").run().stdout;
let out = new_ucmd!().arg("FOO=bar").run();
assert!(out.lines().any(|line| line == "FOO=bar"));
assert!(out.stdout_str().lines().any(|line| line == "FOO=bar"));
}
#[test]
fn test_multiple_name_value_pairs() {
let out = new_ucmd!().arg("FOO=bar").arg("ABC=xyz").run().stdout;
let out = new_ucmd!().arg("FOO=bar").arg("ABC=xyz").run();
assert_eq!(
out.lines()
out.stdout_str().lines()
.filter(|&line| line == "FOO=bar" || line == "ABC=xyz")
.count(),
2
@ -110,13 +100,8 @@ fn test_multiple_name_value_pairs() {
fn test_ignore_environment() {
let scene = TestScenario::new(util_name!());
let out = scene.ucmd().arg("-i").run().stdout;
assert_eq!(out, "");
let out = scene.ucmd().arg("-").run().stdout;
assert_eq!(out, "");
scene.ucmd().arg("-i").run().no_stdout();
scene.ucmd().arg("-").run().no_stdout();
}
#[test]
@ -126,8 +111,8 @@ fn test_null_delimiter() {
.arg("--null")
.arg("FOO=bar")
.arg("ABC=xyz")
.run()
.stdout;
.succeeds()
.stdout_move_str();
let mut vars: Vec<_> = out.split('\0').collect();
assert_eq!(vars.len(), 3);
@ -145,8 +130,8 @@ fn test_unset_variable() {
.ucmd_keepenv()
.arg("-u")
.arg("HOME")
.run()
.stdout;
.succeeds()
.stdout_move_str();
assert_eq!(out.lines().any(|line| line.starts_with("HOME=")), false);
}
@ -173,8 +158,8 @@ fn test_change_directory() {
.arg("--chdir")
.arg(&temporary_path)
.arg(pwd)
.run()
.stdout;
.succeeds()
.stdout_move_str();
assert_eq!(out.trim(), temporary_path.as_os_str())
}
@ -193,8 +178,8 @@ fn test_change_directory() {
.ucmd()
.arg("--chdir")
.arg(&temporary_path)
.run()
.stdout;
.succeeds()
.stdout_move_str();
assert_eq!(
out.lines()
.any(|line| line.ends_with(temporary_path.file_name().unwrap().to_str().unwrap())),
@ -214,6 +199,6 @@ fn test_fail_change_directory() {
.arg(some_non_existing_path)
.arg("pwd")
.fails()
.stderr;
.stderr_move_str();
assert!(out.contains("env: cannot change directory to "));
}

View file

@ -2,57 +2,54 @@ use crate::common::util::*;
#[test]
fn test_with_tab() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("with-tab.txt").run();
assert!(result.success);
assert!(result.stdout.contains(" "));
assert!(!result.stdout.contains("\t"));
new_ucmd!()
.arg("with-tab.txt")
.succeeds()
.stdout_contains(" ")
.stdout_does_not_contain("\t");
}
#[test]
fn test_with_trailing_tab() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("with-trailing-tab.txt").run();
assert!(result.success);
assert!(result.stdout.contains("with tabs=> "));
assert!(!result.stdout.contains("\t"));
new_ucmd!()
.arg("with-trailing-tab.txt")
.succeeds()
.stdout_contains("with tabs=> ")
.stdout_does_not_contain("\t");
}
#[test]
fn test_with_trailing_tab_i() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("with-trailing-tab.txt").arg("-i").run();
assert!(result.success);
assert!(result.stdout.contains(" // with tabs=>\t"));
new_ucmd!()
.arg("with-trailing-tab.txt")
.arg("-i")
.succeeds()
.stdout_contains(" // with tabs=>\t");
}
#[test]
fn test_with_tab_size() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("with-tab.txt").arg("--tabs=10").run();
assert!(result.success);
assert!(result.stdout.contains(" "));
new_ucmd!()
.arg("with-tab.txt")
.arg("--tabs=10")
.succeeds()
.stdout_contains(" ");
}
#[test]
fn test_with_space() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("with-spaces.txt").run();
assert!(result.success);
assert!(result.stdout.contains(" return"));
new_ucmd!()
.arg("with-spaces.txt")
.succeeds()
.stdout_contains(" return");
}
#[test]
fn test_with_multiple_files() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("with-spaces.txt").arg("with-tab.txt").run();
assert!(result.success);
assert!(result.stdout.contains(" return"));
assert!(result.stdout.contains(" "));
new_ucmd!()
.arg("with-spaces.txt")
.arg("with-tab.txt")
.succeeds()
.stdout_contains(" return")
.stdout_contains(" ");
}

View file

@ -32,13 +32,10 @@ fn test_first_100000_integers() {
}
println!("STDIN='{}'", instring);
let result = new_ucmd!().pipe_in(instring.as_bytes()).run();
let stdout = result.stdout;
assert!(result.success);
let result = new_ucmd!().pipe_in(instring.as_bytes()).succeeds();
// `seq 0 100000 | factor | sha1sum` => "4ed2d8403934fa1c76fe4b84c5d4b8850299c359"
let hash_check = sha1::Sha1::from(stdout.as_bytes()).hexdigest();
let hash_check = sha1::Sha1::from(result.stdout()).hexdigest();
assert_eq!(hash_check, "4ed2d8403934fa1c76fe4b84c5d4b8850299c359");
}

View file

@ -5,7 +5,7 @@ fn test_fmt() {
let result = new_ucmd!().arg("one-word-per-line.txt").run();
//.stdout_is_fixture("call_graph.expected");
assert_eq!(
result.stdout.trim(),
result.stdout_str().trim(),
"this is a file with one word per line"
);
}
@ -15,7 +15,7 @@ fn test_fmt_q() {
let result = new_ucmd!().arg("-q").arg("one-word-per-line.txt").run();
//.stdout_is_fixture("call_graph.expected");
assert_eq!(
result.stdout.trim(),
result.stdout_str().trim(),
"this is a file with one word per line"
);
}
@ -42,7 +42,7 @@ fn test_fmt_w() {
.arg("one-word-per-line.txt")
.run();
//.stdout_is_fixture("call_graph.expected");
assert_eq!(result.stdout.trim(), "this is a file with one word per line");
assert_eq!(result.stdout_str().trim(), "this is a file with one word per line");
}

View file

@ -2,26 +2,25 @@ use crate::common::util::*;
#[test]
fn test_groups() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.run();
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
if is_ci() && result.stdout.trim().is_empty() {
let result = new_ucmd!().run();
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stdout_str().trim().is_empty() {
// In the CI, some server are failing to return the group.
// As seems to be a configuration issue, ignoring it
return;
}
assert!(result.success);
assert!(!result.stdout.trim().is_empty());
assert!(!result.stdout_str().trim().is_empty());
}
#[test]
fn test_groups_arg() {
// get the username with the "id -un" command
let result = TestScenario::new("id").ucmd_keepenv().arg("-un").run();
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
let s1 = String::from(result.stdout.trim());
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
let s1 = String::from(result.stdout_str().trim());
if is_ci() && s1.parse::<f64>().is_ok() {
// In the CI, some server are failing to return id -un.
// So, if we are getting a uid, just skip this test
@ -29,18 +28,18 @@ fn test_groups_arg() {
return;
}
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
assert!(result.success);
assert!(!result.stdout.is_empty());
let username = result.stdout.trim();
assert!(!result.stdout_str().is_empty());
let username = result.stdout_str().trim();
// call groups with the user name to check that we
// are getting something
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(username).run();
println!("result.stdout {}", result.stdout);
println!("result.stderr = {}", result.stderr);
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
assert!(result.success);
assert!(!result.stdout.is_empty());
assert!(!result.stdout_str().is_empty());
}

View file

@ -17,14 +17,14 @@ macro_rules! test_digest {
fn test_single_file() {
let ts = TestScenario::new("hashsum");
assert_eq!(ts.fixtures.read(EXPECTED_FILE),
get_hash!(ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("input.txt").succeeds().no_stderr().stdout));
get_hash!(ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("input.txt").succeeds().no_stderr().stdout_str()));
}
#[test]
fn test_stdin() {
let ts = TestScenario::new("hashsum");
assert_eq!(ts.fixtures.read(EXPECTED_FILE),
get_hash!(ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).pipe_in_fixture("input.txt").succeeds().no_stderr().stdout));
get_hash!(ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).pipe_in_fixture("input.txt").succeeds().no_stderr().stdout_str()));
}
}
)*)

View file

@ -9,5 +9,5 @@ fn test_normal() {
assert!(result.success);
let re = Regex::new(r"^[0-9a-f]{8}").unwrap();
assert!(re.is_match(&result.stdout.trim()));
assert!(re.is_match(&result.stdout_str()));
}

View file

@ -6,8 +6,8 @@ fn test_hostname() {
let ls_short_res = new_ucmd!().arg("-s").succeeds();
let ls_domain_res = new_ucmd!().arg("-d").succeeds();
assert!(ls_default_res.stdout.len() >= ls_short_res.stdout.len());
assert!(ls_default_res.stdout.len() >= ls_domain_res.stdout.len());
assert!(ls_default_res.stdout().len() >= ls_short_res.stdout().len());
assert!(ls_default_res.stdout().len() >= ls_domain_res.stdout().len());
}
// FixME: fails for "MacOS"
@ -17,14 +17,14 @@ fn test_hostname_ip() {
let result = new_ucmd!().arg("-i").run();
println!("{:#?}", result);
assert!(result.success);
assert!(!result.stdout.trim().is_empty());
assert!(!result.stdout_str().trim().is_empty());
}
#[test]
fn test_hostname_full() {
let result = new_ucmd!().arg("-f").succeeds();
assert!(!result.stdout.trim().is_empty());
let ls_short_res = new_ucmd!().arg("-s").succeeds();
assert!(result.stdout.trim().contains(ls_short_res.stdout.trim()));
assert!(!ls_short_res.stdout_str().trim().is_empty());
new_ucmd!().arg("-f").succeeds()
.stdout_contains(ls_short_res.stdout_str().trim());
}

View file

@ -9,33 +9,29 @@ fn return_whoami_username() -> String {
return String::from("");
}
result.stdout.trim().to_string()
result.stdout_str().trim().to_string()
}
#[test]
fn test_id() {
let scene = TestScenario::new(util_name!());
let mut result = scene.ucmd().arg("-u").run();
let result = new_ucmd!().arg("-u").run();
if result.stderr.contains("cannot find name for user ID") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
assert!(result.success);
let uid = String::from(result.stdout.trim());
result = scene.ucmd().run();
let uid = result.success().stdout_str().trim();
let result = new_ucmd!().run();
if is_ci() && result.stderr.contains("cannot find name for user ID") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
if !result.stderr.contains("Could not find uid") {
if !result.stderr_str().contains("Could not find uid") {
// Verify that the id found by --user/-u exists in the list
assert!(result.stdout.contains(&uid));
result.success().stdout_contains(&uid);
}
}
@ -47,88 +43,64 @@ fn test_id_from_name() {
return;
}
let scene = TestScenario::new(util_name!());
let result = scene.ucmd().arg(&username).succeeds();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
assert!(result.success);
let uid = String::from(result.stdout.trim());
let result = scene.ucmd().succeeds();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
// Verify that the id found by --user/-u exists in the list
assert!(result.stdout.contains(&uid));
// Verify that the username found by whoami exists in the list
assert!(result.stdout.contains(&username));
let result = new_ucmd!().arg(&username).succeeds();
let uid = result.stdout_str().trim();
new_ucmd!().succeeds()
// Verify that the id found by --user/-u exists in the list
.stdout_contains(uid)
// Verify that the username found by whoami exists in the list
.stdout_contains(username);
}
#[test]
fn test_id_name_from_id() {
let mut scene = TestScenario::new(util_name!());
let result = scene.ucmd().arg("-u").run();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
assert!(result.success);
let uid = String::from(result.stdout.trim());
let result = new_ucmd!().arg("-u").succeeds();
let uid = result.stdout_str().trim();
scene = TestScenario::new(util_name!());
let result = scene.ucmd().arg("-nu").arg(uid).run();
let result = new_ucmd!().arg("-nu").arg(uid).run();
if is_ci() && result.stderr.contains("No such user/group") {
// In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it
return;
}
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
assert!(result.success);
let username_id = String::from(result.stdout.trim());
let username_id = result
.success()
.stdout_str()
.trim();
scene = TestScenario::new("whoami");
let result = scene.cmd("whoami").run();
let scene = TestScenario::new("whoami");
let result = scene.cmd("whoami").succeeds();
let username_whoami = result.stdout.trim();
let username_whoami = result.stdout_str().trim();
assert_eq!(username_id, username_whoami);
}
#[test]
fn test_id_group() {
let scene = TestScenario::new(util_name!());
let mut result = scene.ucmd().arg("-g").succeeds();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
assert!(result.success);
let s1 = String::from(result.stdout.trim());
let mut result = new_ucmd!().arg("-g").succeeds();
let s1 = result.stdout_str().trim();
assert!(s1.parse::<f64>().is_ok());
result = scene.ucmd().arg("--group").succeeds();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
assert!(result.success);
let s1 = String::from(result.stdout.trim());
result = new_ucmd!().arg("--group").succeeds();
let s1 = result.stdout_str().trim();
assert!(s1.parse::<f64>().is_ok());
}
#[test]
fn test_id_groups() {
let scene = TestScenario::new(util_name!());
let result = scene.ucmd().arg("-G").succeeds();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
let result = new_ucmd!().arg("-G").succeeds();
assert!(result.success);
let groups = result.stdout.trim().split_whitespace();
let groups = result.stdout_str().trim().split_whitespace();
for s in groups {
assert!(s.parse::<f64>().is_ok());
}
let result = scene.ucmd().arg("--groups").succeeds();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
let result = new_ucmd!().arg("--groups").succeeds();
assert!(result.success);
let groups = result.stdout.trim().split_whitespace();
let groups = result.stdout_str().trim().split_whitespace();
for s in groups {
assert!(s.parse::<f64>().is_ok());
}
@ -136,15 +108,12 @@ fn test_id_groups() {
#[test]
fn test_id_user() {
let scene = TestScenario::new(util_name!());
let mut result = scene.ucmd().arg("-u").succeeds();
assert!(result.success);
let s1 = String::from(result.stdout.trim());
let mut result = new_ucmd!().arg("-u").succeeds();
let s1 = result.stdout_str().trim();
assert!(s1.parse::<f64>().is_ok());
result = scene.ucmd().arg("--user").succeeds();
assert!(result.success);
let s1 = String::from(result.stdout.trim());
result = new_ucmd!().arg("--user").succeeds();
let s1 = result.stdout_str().trim();
assert!(s1.parse::<f64>().is_ok());
}
@ -156,17 +125,13 @@ fn test_id_pretty_print() {
return;
}
let scene = TestScenario::new(util_name!());
let result = scene.ucmd().arg("-p").run();
if result.stdout.trim() == "" {
let result = new_ucmd!().arg("-p").run();
if result.stdout_str().trim() == "" {
// Sometimes, the CI is failing here with
// old rust versions on Linux
return;
}
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
assert!(result.success);
assert!(result.stdout.contains(&username));
result.success().stdout_contains(username);
}
#[test]
@ -176,12 +141,7 @@ fn test_id_password_style() {
// Sometimes, the CI is failing here
return;
}
let scene = TestScenario::new(util_name!());
let result = scene.ucmd().arg("-P").succeeds();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
assert!(result.success);
assert!(result.stdout.starts_with(&username));
let result = new_ucmd!().arg("-P").succeeds();
assert!(result.stdout_str().starts_with(&username));
}

View file

@ -2,6 +2,8 @@ use crate::common::util::*;
use filetime::FileTime;
use rust_users::*;
use std::os::unix::fs::PermissionsExt;
#[cfg(not(windows))]
use std::process::Command;
#[cfg(target_os = "linux")]
use std::thread::sleep;
@ -193,12 +195,8 @@ fn test_install_mode_numeric() {
let mode_arg = "-m 0333";
at.mkdir(dir2);
let result = scene.ucmd().arg(mode_arg).arg(file).arg(dir2).run();
scene.ucmd().arg(mode_arg).arg(file).arg(dir2).succeeds();
println!("stderr = {:?}", result.stderr);
println!("stdout = {:?}", result.stdout);
assert!(result.success);
let dest_file = &format!("{}/{}", dir2, file);
assert!(at.file_exists(file));
assert!(at.file_exists(dest_file));
@ -311,16 +309,13 @@ fn test_install_target_new_file_with_group() {
.arg(format!("{}/{}", dir, file))
.run();
println!("stderr = {:?}", result.stderr);
println!("stdout = {:?}", result.stdout);
if is_ci() && result.stderr.contains("error: no such group:") {
if is_ci() && result.stderr_str().contains("error: no such group:") {
// In the CI, some server are failing to return the group.
// As seems to be a configuration issue, ignoring it
return;
}
assert!(result.success);
result.success();
assert!(at.file_exists(file));
assert!(at.file_exists(&format!("{}/{}", dir, file)));
}
@ -341,16 +336,13 @@ fn test_install_target_new_file_with_owner() {
.arg(format!("{}/{}", dir, file))
.run();
println!("stderr = {:?}", result.stderr);
println!("stdout = {:?}", result.stdout);
if is_ci() && result.stderr.contains("error: no such user:") {
// In the CI, some server are failing to return the user id.
// As seems to be a configuration issue, ignoring it
return;
}
assert!(result.success);
result.success();
assert!(at.file_exists(file));
assert!(at.file_exists(&format!("{}/{}", dir, file)));
}
@ -364,13 +356,10 @@ fn test_install_target_new_file_failing_nonexistent_parent() {
at.touch(file1);
let err = ucmd
.arg(file1)
ucmd.arg(file1)
.arg(format!("{}/{}", dir, file2))
.fails()
.stderr;
assert!(err.contains("not a directory"))
.stderr_contains(&"not a directory");
}
#[test]
@ -415,18 +404,12 @@ fn test_install_copy_file() {
#[test]
#[cfg(target_os = "linux")]
fn test_install_target_file_dev_null() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let (at, mut ucmd) = at_and_ucmd!();
let file1 = "/dev/null";
let file2 = "target_file";
let result = scene.ucmd().arg(file1).arg(file2).run();
println!("stderr = {:?}", result.stderr);
println!("stdout = {:?}", result.stdout);
assert!(result.success);
ucmd.arg(file1).arg(file2).succeeds();
assert!(at.file_exists(file2));
}
@ -566,3 +549,97 @@ fn test_install_copy_then_compare_file_with_extra_mode() {
assert!(after_install_sticky != after_install_sticky_again);
}
const STRIP_TARGET_FILE: &str = "helloworld_installed";
const SYMBOL_DUMP_PROGRAM: &str = "objdump";
const STRIP_SOURCE_FILE_SYMBOL: &str = "main";
fn strip_source_file() -> &'static str {
if cfg!(target_os = "macos") {
"helloworld_macos"
} else {
"helloworld_linux"
}
}
#[test]
#[cfg(not(windows))]
fn test_install_and_strip() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
scene
.ucmd()
.arg("-s")
.arg(strip_source_file())
.arg(STRIP_TARGET_FILE)
.succeeds()
.no_stderr();
let output = Command::new(SYMBOL_DUMP_PROGRAM)
.arg("-t")
.arg(at.plus(STRIP_TARGET_FILE))
.output()
.unwrap();
let stdout = String::from_utf8(output.stdout).unwrap();
assert!(!stdout.contains(STRIP_SOURCE_FILE_SYMBOL));
}
#[test]
#[cfg(not(windows))]
fn test_install_and_strip_with_program() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
scene
.ucmd()
.arg("-s")
.arg("--strip-program")
.arg("/usr/bin/strip")
.arg(strip_source_file())
.arg(STRIP_TARGET_FILE)
.succeeds()
.no_stderr();
let output = Command::new(SYMBOL_DUMP_PROGRAM)
.arg("-t")
.arg(at.plus(STRIP_TARGET_FILE))
.output()
.unwrap();
let stdout = String::from_utf8(output.stdout).unwrap();
assert!(!stdout.contains(STRIP_SOURCE_FILE_SYMBOL));
}
#[test]
#[cfg(not(windows))]
fn test_install_and_strip_with_invalid_program() {
let scene = TestScenario::new(util_name!());
let stderr = scene
.ucmd()
.arg("-s")
.arg("--strip-program")
.arg("/bin/date")
.arg(strip_source_file())
.arg(STRIP_TARGET_FILE)
.fails()
.stderr;
assert!(stderr.contains("strip program failed"));
}
#[test]
#[cfg(not(windows))]
fn test_install_and_strip_with_non_existent_program() {
let scene = TestScenario::new(util_name!());
let stderr = scene
.ucmd()
.arg("-s")
.arg("--strip-program")
.arg("/usr/bin/non_existent_program")
.arg(strip_source_file())
.arg(STRIP_TARGET_FILE)
.fails()
.stderr;
assert!(stderr.contains("No such file or directory"));
}

View file

@ -520,10 +520,7 @@ fn test_symlink_no_deref_dir() {
scene.ucmd().args(&["-sn", dir1, link]).fails();
// Try with the no-deref
let result = scene.ucmd().args(&["-sfn", dir1, link]).run();
println!("stdout {}", result.stdout);
println!("stderr {}", result.stderr);
assert!(result.success);
scene.ucmd().args(&["-sfn", dir1, link]).succeeds();
assert!(at.dir_exists(dir1));
assert!(at.dir_exists(dir2));
assert!(at.is_symlink(link));
@ -566,10 +563,7 @@ fn test_symlink_no_deref_file() {
scene.ucmd().args(&["-sn", file1, link]).fails();
// Try with the no-deref
let result = scene.ucmd().args(&["-sfn", file1, link]).run();
println!("stdout {}", result.stdout);
println!("stderr {}", result.stderr);
assert!(result.success);
scene.ucmd().args(&["-sfn", file1, link]).succeeds();
assert!(at.file_exists(file1));
assert!(at.file_exists(file2));
assert!(at.is_symlink(link));

View file

@ -3,23 +3,19 @@ use std::env;
#[test]
fn test_normal() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.run();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
let result = new_ucmd!().run();
println!("env::var(CI).is_ok() = {}", env::var("CI").is_ok());
for (key, value) in env::vars() {
println!("{}: {}", key, value);
}
if (is_ci() || is_wsl()) && result.stderr.contains("error: no login name") {
if (is_ci() || is_wsl()) && result.stderr_str().contains("error: no login name") {
// ToDO: investigate WSL failure
// In the CI, some server are failing to return logname.
// As seems to be a configuration issue, ignoring it
return;
}
assert!(result.success);
assert!(!result.stdout.trim().is_empty());
result.success();
assert!(!result.stdout_str().trim().is_empty());
}

View file

@ -1 +1,51 @@
// ToDO: add tests
use crate::common::util::*;
#[test]
fn test_shred_remove() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_shred_remove_a";
let file_b = "test_shred_remove_b";
// Create file_a and file_b.
at.touch(file_a);
at.touch(file_b);
// Shred file_a.
scene.ucmd().arg("-u").arg(file_a).run();
// file_a was deleted, file_b exists.
assert!(!at.file_exists(file_a));
assert!(at.file_exists(file_b));
}
#[cfg(not(target_os = "freebsd"))]
#[test]
fn test_shred_force() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file = "test_shred_force";
// Create file_a.
at.touch(file);
assert!(at.file_exists(file));
// Make file_a readonly.
at.set_readonly(file);
// Try shred -u.
let result = scene.ucmd().arg("-u").arg(file).run();
println!("stderr = {:?}", result.stderr);
println!("stdout = {:?}", result.stdout);
// file_a was not deleted because it is readonly.
assert!(at.file_exists(file));
// Try shred -u -f.
scene.ucmd().arg("-u").arg("-f").arg(file).run();
// file_a was deleted.
assert!(!at.file_exists(file));
}

View file

@ -1,5 +1,50 @@
use crate::common::util::*;
fn test_helper(file_name: &str, args: &str) {
new_ucmd!()
.arg(args)
.arg(format!("{}.txt", file_name))
.succeeds()
.stdout_is_fixture(format!("{}.expected", file_name));
}
#[test]
fn test_months_whitespace() {
test_helper("months-whitespace", "-M");
}
#[test]
fn test_version_empty_lines() {
new_ucmd!()
.arg("-V")
.arg("version-empty-lines.txt")
.succeeds()
.stdout_is("\n\n\n\n\n\n\n1.2.3-alpha\n1.2.3-alpha2\n\t\t\t1.12.4\n11.2.3\n");
}
#[test]
fn test_human_numeric_whitespace() {
test_helper("human-numeric-whitespace", "-h");
}
#[test]
fn test_multiple_decimals_general() {
new_ucmd!()
.arg("-g")
.arg("multiple_decimals_general.txt")
.succeeds()
.stdout_is("\n\n\n\n\n\n\n\nCARAvan\n-2028789030\n-896689\n-8.90880\n-1\n-.05\n000\n00000001\n1\n1.040000000\n1.444\n1.58590\n8.013\n45\n46.89\n576,446.88800000\n576,446.890\n 4567.\n4567.1\n4567.34\n\t\t\t\t\t\t\t\t\t\t4567..457\n\t\t\t\t37800\n\t\t\t\t\t\t45670.89079.098\n\t\t\t\t\t\t45670.89079.1\n4798908.340000000000\n4798908.45\n4798908.8909800\n");
}
#[test]
fn test_multiple_decimals_numeric() {
new_ucmd!()
.arg("-n")
.arg("multiple_decimals_numeric.txt")
.succeeds()
.stdout_is("-2028789030\n-896689\n-8.90880\n-1\n-.05\n\n\n\n\n\n\n\n\n000\nCARAvan\n00000001\n1\n1.040000000\n1.444\n1.58590\n8.013\n45\n46.89\n 4567.\n4567.1\n4567.34\n\t\t\t\t\t\t\t\t\t\t4567..457\n\t\t\t\t37800\n\t\t\t\t\t\t45670.89079.098\n\t\t\t\t\t\t45670.89079.1\n576,446.88800000\n576,446.890\n4798908.340000000000\n4798908.45\n4798908.8909800\n");
}
#[test]
fn test_check_zero_terminated_failure() {
new_ucmd!()
@ -44,6 +89,21 @@ fn test_random_shuffle_contains_all_lines() {
assert_eq!(result_sorted, expected);
}
#[test]
fn test_random_shuffle_two_runs_not_the_same() {
// check to verify that two random shuffles are not equal; this has the
// potential to fail in the very unlikely event that the random order is the same
// as the starting order, or if both random sorts end up having the same order.
const FILE: &'static str = "default_unsorted_ints.expected";
let (at, _ucmd) = at_and_ucmd!();
let result = new_ucmd!().arg("-R").arg(FILE).run().stdout;
let expected = at.read(FILE);
let unexpected = new_ucmd!().arg("-R").arg(FILE).run().stdout;
assert_ne!(result, expected);
assert_ne!(result, unexpected);
}
#[test]
fn test_random_shuffle_contains_two_runs_not_the_same() {
// check to verify that two random shuffles are not equal; this has the
@ -144,10 +204,10 @@ fn test_dictionary_order2() {
fn test_non_printing_chars() {
for non_printing_chars_param in vec!["-i"] {
new_ucmd!()
.pipe_in("a👦🏻aa b\naaaa b")
.pipe_in("a👦🏻aa\naaaa")
.arg(non_printing_chars_param)
.succeeds()
.stdout_only("aaaa b\na👦🏻aa b\n");
.stdout_only("a👦🏻aa\naaaa\n");
}
}
@ -182,6 +242,16 @@ fn test_mixed_floats_ints_chars_numeric_unique() {
test_helper("mixed_floats_ints_chars_numeric_unique", "-nu");
}
#[test]
fn test_words_unique() {
test_helper("words_unique", "-u");
}
#[test]
fn test_numeric_unique() {
test_helper("numeric_unique", "-nu");
}
#[test]
fn test_mixed_floats_ints_chars_numeric_reverse() {
test_helper("mixed_floats_ints_chars_numeric_unique_reverse", "-nur");
@ -266,6 +336,166 @@ fn test_numeric_unique_ints2() {
}
}
#[test]
fn test_keys_open_ended() {
let input = "aa bb cc\ndd aa ff\ngg aa cc\n";
new_ucmd!()
.args(&["-k", "2.2"])
.pipe_in(input)
.succeeds()
.stdout_only("gg aa cc\ndd aa ff\naa bb cc\n");
}
#[test]
fn test_keys_closed_range() {
let input = "aa bb cc\ndd aa ff\ngg aa cc\n";
new_ucmd!()
.args(&["-k", "2.2,2.2"])
.pipe_in(input)
.succeeds()
.stdout_only("dd aa ff\ngg aa cc\naa bb cc\n");
}
#[test]
fn test_keys_multiple_ranges() {
let input = "aa bb cc\ndd aa ff\ngg aa cc\n";
new_ucmd!()
.args(&["-k", "2,2", "-k", "3,3"])
.pipe_in(input)
.succeeds()
.stdout_only("gg aa cc\ndd aa ff\naa bb cc\n");
}
#[test]
fn test_keys_no_field_match() {
let input = "aa aa aa aa\naa bb cc\ndd aa ff\n";
new_ucmd!()
.args(&["-k", "4,4"])
.pipe_in(input)
.succeeds()
.stdout_only("aa bb cc\ndd aa ff\naa aa aa aa\n");
}
#[test]
fn test_keys_no_char_match() {
let input = "aaa\nba\nc\n";
new_ucmd!()
.args(&["-k", "1.2"])
.pipe_in(input)
.succeeds()
.stdout_only("c\nba\naaa\n");
}
#[test]
fn test_keys_custom_separator() {
let input = "aaxbbxcc\nddxaaxff\nggxaaxcc\n";
new_ucmd!()
.args(&["-k", "2.2,2.2", "-t", "x"])
.pipe_in(input)
.succeeds()
.stdout_only("ddxaaxff\nggxaaxcc\naaxbbxcc\n");
}
#[test]
fn test_keys_invalid_field() {
new_ucmd!()
.args(&["-k", "1."])
.fails()
.stderr_only("sort: error: failed to parse character index for key `1.`: cannot parse integer from empty string");
}
#[test]
fn test_keys_invalid_field_option() {
new_ucmd!()
.args(&["-k", "1.1x"])
.fails()
.stderr_only("sort: error: invalid option for key: `x`");
}
#[test]
fn test_keys_invalid_field_zero() {
new_ucmd!()
.args(&["-k", "0.1"])
.fails()
.stderr_only("sort: error: field index was 0");
}
#[test]
fn test_keys_with_options() {
let input = "aa 3 cc\ndd 1 ff\ngg 2 cc\n";
for param in &[
&["-k", "2,2n"][..],
&["-k", "2n,2"][..],
&["-k", "2,2", "-n"][..],
] {
new_ucmd!()
.args(param)
.pipe_in(input)
.succeeds()
.stdout_only("dd 1 ff\ngg 2 cc\naa 3 cc\n");
}
}
#[test]
fn test_keys_with_options_blanks_start() {
let input = "aa 3 cc\ndd 1 ff\ngg 2 cc\n";
for param in &[&["-k", "2b,2"][..], &["-k", "2,2", "-b"][..]] {
new_ucmd!()
.args(param)
.pipe_in(input)
.succeeds()
.stdout_only("dd 1 ff\ngg 2 cc\naa 3 cc\n");
}
}
#[test]
fn test_keys_with_options_blanks_end() {
let input = "a b
a b
a b
";
new_ucmd!()
.args(&["-k", "1,2.1b", "-s"])
.pipe_in(input)
.succeeds()
.stdout_only(
"a b
a b
a b
",
);
}
#[test]
fn test_keys_stable() {
let input = "a b
a b
a b
";
new_ucmd!()
.args(&["-k", "1,2.1", "-s"])
.pipe_in(input)
.succeeds()
.stdout_only(
"a b
a b
a b
",
);
}
#[test]
fn test_keys_empty_match() {
let input = "a a a a
aaaa
";
new_ucmd!()
.args(&["-k", "1,1", "-t", "a"])
.pipe_in(input)
.succeeds()
.stdout_only(input);
}
#[test]
fn test_zero_terminated() {
test_helper("zero-terminated", "-z");
@ -355,11 +585,3 @@ fn test_check_silent() {
.fails()
.stdout_is("");
}
fn test_helper(file_name: &str, args: &str) {
new_ucmd!()
.arg(args)
.arg(format!("{}{}", file_name, ".txt"))
.succeeds()
.stdout_is_fixture(format!("{}{}", file_name, ".expected"));
}

View file

@ -1,13 +1,65 @@
#[cfg(not(target_os = "windows"))]
use crate::common::util::*;
#[cfg(not(target_os = "windows"))]
#[test]
fn test_stdbuf_unbuffered_stdout() {
if cfg!(target_os = "linux") {
// This is a basic smoke test
new_ucmd!()
.args(&["-o0", "head"])
.pipe_in("The quick brown fox jumps over the lazy dog.")
.run()
.stdout_is("The quick brown fox jumps over the lazy dog.");
}
// This is a basic smoke test
new_ucmd!()
.args(&["-o0", "head"])
.pipe_in("The quick brown fox jumps over the lazy dog.")
.run()
.stdout_is("The quick brown fox jumps over the lazy dog.");
}
#[cfg(not(target_os = "windows"))]
#[test]
fn test_stdbuf_line_buffered_stdout() {
new_ucmd!()
.args(&["-oL", "head"])
.pipe_in("The quick brown fox jumps over the lazy dog.")
.run()
.stdout_is("The quick brown fox jumps over the lazy dog.");
}
#[cfg(not(target_os = "windows"))]
#[test]
fn test_stdbuf_no_buffer_option_fails() {
new_ucmd!().args(&["head"]).fails().stderr_is(
"error: The following required arguments were not provided:\n \
--error <MODE>\n \
--input <MODE>\n \
--output <MODE>\n\n\
USAGE:\n \
stdbuf OPTION... COMMAND\n\n\
For more information try --help",
);
}
#[cfg(not(target_os = "windows"))]
#[test]
fn test_stdbuf_trailing_var_arg() {
new_ucmd!()
.args(&["-i", "1024", "tail", "-1"])
.pipe_in("The quick brown fox\njumps over the lazy dog.")
.run()
.stdout_is("jumps over the lazy dog.");
}
#[cfg(not(target_os = "windows"))]
#[test]
fn test_stdbuf_line_buffering_stdin_fails() {
new_ucmd!()
.args(&["-i", "L", "head"])
.fails()
.stderr_is("stdbuf: error: line buffering stdin is meaningless\nTry 'stdbuf --help' for more information.");
}
#[cfg(not(target_os = "windows"))]
#[test]
fn test_stdbuf_invalid_mode_fails() {
new_ucmd!()
.args(&["-i", "1024R", "head"])
.fails()
.stderr_is("stdbuf: error: invalid mode 1024R\nTry 'stdbuf --help' for more information.");
}

View file

@ -29,6 +29,7 @@ fn set_file_times(at: &AtPath, path: &str, atime: FileTime, mtime: FileTime) {
fn str_to_filetime(format: &str, s: &str) -> FileTime {
let mut tm = time::strptime(s, format).unwrap();
tm.tm_utcoff = time::now().tm_utcoff;
tm.tm_isdst = -1; // Unknown flag DST
let ts = tm.to_timespec();
FileTime::from_unix_time(ts.sec as i64, ts.nsec as u32)
}
@ -352,3 +353,21 @@ fn test_touch_set_date() {
assert_eq!(atime, start_of_year);
assert_eq!(mtime, start_of_year);
}
#[test]
fn test_touch_mtime_dst_succeeds() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_touch_set_mtime_dst_succeeds";
ucmd.args(&["-m", "-t", "202103140300", file])
.succeeds()
.no_stderr();
assert!(at.file_exists(file));
let target_time = str_to_filetime("%Y%m%d%H%M", "202103140300");
let (_, mtime) = get_file_times(&at, file);
eprintln!("target_time: {:?}", target_time);
eprintln!("mtime: {:?}", mtime);
assert!(target_time == mtime);
}

View file

@ -1,5 +1,33 @@
use crate::common::util::*;
#[test]
fn test_count_bytes_large_stdin() {
for &n in &[
0,
1,
42,
16 * 1024 - 7,
16 * 1024 - 1,
16 * 1024,
16 * 1024 + 1,
16 * 1024 + 3,
32 * 1024,
64 * 1024,
80 * 1024,
96 * 1024,
112 * 1024,
128 * 1024,
] {
let data = vec_of_size(n);
let expected = format!("{}\n", n);
new_ucmd!()
.args(&["-c"])
.pipe_in(data)
.succeeds()
.stdout_is_bytes(&expected.as_bytes());
}
}
#[test]
fn test_stdin_default() {
new_ucmd!()

View file

@ -1,40 +1,3 @@
/// Assertion helper macro for [`CmdResult`] types
///
/// [`CmdResult`]: crate::tests::common::util::CmdResult
#[macro_export]
macro_rules! assert_empty_stderr(
($cond:expr) => (
if $cond.stderr.len() > 0 {
panic!("stderr: {}", $cond.stderr_str())
}
);
);
/// Assertion helper macro for [`CmdResult`] types
///
/// [`CmdResult`]: crate::tests::common::util::CmdResult
#[macro_export]
macro_rules! assert_empty_stdout(
($cond:expr) => (
if $cond.stdout.len() > 0 {
panic!("stdout: {}", $cond.stdout_str())
}
);
);
/// Assertion helper macro for [`CmdResult`] types
///
/// [`CmdResult`]: crate::tests::common::util::CmdResult
#[macro_export]
macro_rules! assert_no_error(
($cond:expr) => (
assert!($cond.success);
if $cond.stderr.len() > 0 {
panic!("stderr: {}", $cond.stderr_str())
}
);
);
/// Platform-independent helper for constructing a PathBuf from individual elements
#[macro_export]
macro_rules! path_concat {

View file

@ -33,6 +33,8 @@ static ALREADY_RUN: &str = " you have already run this UCommand, if you want to
testing();";
static MULTIPLE_STDIN_MEANINGLESS: &str = "Ucommand is designed around a typical use case of: provide args and input stream -> spawn process -> block until completion -> return output streams. For verifying that a particular section of the input stream is what causes a particular behavior, use the Command type directly.";
static NO_STDIN_MEANINGLESS: &str = "Setting this flag has no effect if there is no stdin";
/// Test if the program is running under CI
pub fn is_ci() -> bool {
std::env::var("CI")
@ -64,7 +66,7 @@ fn read_scenario_fixture<S: AsRef<OsStr>>(tmpd: &Option<Rc<TempDir>>, file_rel_p
/// A command result is the outputs of a command (streams and status code)
/// within a struct which has convenience assertion functions about those outputs
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CmdResult {
//tmpd is used for convenience functions for asserts against fixtures
tmpd: Option<Rc<TempDir>>,
@ -130,6 +132,11 @@ impl CmdResult {
self.code.expect("Program must be run first")
}
pub fn code_is(&self, expected_code: i32) -> &CmdResult {
assert_eq!(self.code(), expected_code);
self
}
/// Returns the program's TempDir
/// Panics if not present
pub fn tmpd(&self) -> Rc<TempDir> {
@ -146,13 +153,25 @@ impl CmdResult {
/// asserts that the command resulted in a success (zero) status code
pub fn success(&self) -> &CmdResult {
assert!(self.success);
if !self.success {
panic!(
"Command was expected to succeed.\nstdout = {}\n stderr = {}",
self.stdout_str(),
self.stderr_str()
);
}
self
}
/// asserts that the command resulted in a failure (non-zero) status code
pub fn failure(&self) -> &CmdResult {
assert!(!self.success);
if self.success {
panic!(
"Command was expected to fail.\nstdout = {}\n stderr = {}",
self.stdout_str(),
self.stderr_str()
);
}
self
}
@ -168,7 +187,12 @@ impl CmdResult {
/// 1. you can not know exactly what stdout will be or
/// 2. you know that stdout will also be empty
pub fn no_stderr(&self) -> &CmdResult {
assert!(self.stderr.is_empty());
if !self.stderr.is_empty() {
panic!(
"Expected stderr to be empty, but it's:\n{}",
self.stderr_str()
);
}
self
}
@ -179,7 +203,12 @@ impl CmdResult {
/// 1. you can not know exactly what stderr will be or
/// 2. you know that stderr will also be empty
pub fn no_stdout(&self) -> &CmdResult {
assert!(self.stdout.is_empty());
if !self.stdout.is_empty() {
panic!(
"Expected stdout to be empty, but it's:\n{}",
self.stderr_str()
);
}
self
}
@ -222,6 +251,12 @@ impl CmdResult {
self
}
/// Like stdout_is_fixture, but for stderr
pub fn stderr_is_fixture<T: AsRef<OsStr>>(&self, file_rel_path: T) -> &CmdResult {
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
self.stderr_is_bytes(contents)
}
/// asserts that
/// 1. the command resulted in stdout stream output that equals the
/// passed in value
@ -271,10 +306,34 @@ impl CmdResult {
self
}
pub fn stderr_contains<T: AsRef<str>>(&self, cmp: &T) -> &CmdResult {
pub fn stderr_contains<T: AsRef<str>>(&self, cmp: T) -> &CmdResult {
assert!(self.stderr_str().contains(cmp.as_ref()));
self
}
pub fn stdout_does_not_contain<T: AsRef<str>>(&self, cmp: T) -> &CmdResult {
assert!(!self.stdout_str().contains(cmp.as_ref()));
self
}
pub fn stderr_does_not_contain<T: AsRef<str>>(&self, cmp: T) -> &CmdResult {
assert!(!self.stderr_str().contains(cmp.as_ref()));
self
}
pub fn stdout_matches(&self, regex: &regex::Regex) -> &CmdResult {
if !regex.is_match(self.stdout_str()) {
panic!("Stdout does not match regex:\n{}", self.stdout_str())
}
self
}
pub fn stdout_does_not_match(&self, regex: &regex::Regex) -> &CmdResult {
if regex.is_match(self.stdout_str()) {
panic!("Stdout matches regex:\n{}", self.stdout_str())
}
self
}
}
pub fn log_info<T: AsRef<str>, U: AsRef<str>>(msg: T, par: U) {
@ -351,6 +410,13 @@ impl AtPath {
String::from(self.minus(name).to_str().unwrap())
}
pub fn set_readonly(&self, name: &str) {
let metadata = fs::metadata(self.plus(name)).unwrap();
let mut permissions = metadata.permissions();
permissions.set_readonly(true);
fs::set_permissions(self.plus(name), permissions).unwrap();
}
pub fn open(&self, name: &str) -> File {
log_info("open", self.plus_as_string(name));
File::open(self.plus(name)).unwrap()
@ -624,6 +690,7 @@ pub struct UCommand {
tmpd: Option<Rc<TempDir>>,
has_run: bool,
stdin: Option<Vec<u8>>,
ignore_stdin_write_error: bool,
}
impl UCommand {
@ -653,6 +720,7 @@ impl UCommand {
},
comm_string: String::from(arg.as_ref().to_str().unwrap()),
stdin: None,
ignore_stdin_write_error: false,
}
}
@ -705,6 +773,17 @@ impl UCommand {
self.pipe_in(contents)
}
/// Ignores error caused by feeding stdin to the command.
/// This is typically useful to test non-standard workflows
/// like feeding something to a command that does not read it
pub fn ignore_stdin_write_error(&mut self) -> &mut UCommand {
if self.stdin.is_none() {
panic!("{}", NO_STDIN_MEANINGLESS);
}
self.ignore_stdin_write_error = true;
self
}
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut UCommand
where
K: AsRef<OsStr>,
@ -725,7 +804,7 @@ impl UCommand {
}
self.has_run = true;
log_info("run", &self.comm_string);
let mut result = self
let mut child = self
.raw
.stdin(Stdio::piped())
.stdout(Stdio::piped())
@ -734,15 +813,19 @@ impl UCommand {
.unwrap();
if let Some(ref input) = self.stdin {
result
let write_result = child
.stdin
.take()
.unwrap_or_else(|| panic!("Could not take child process stdin"))
.write_all(input)
.unwrap_or_else(|e| panic!("{}", e));
.write_all(input);
if !self.ignore_stdin_write_error {
if let Err(e) = write_result {
panic!("failed to write to stdin of child: {}", e)
}
}
}
result
child
}
/// Spawns the command, feeds the stdin if any, waits for the result
@ -797,3 +880,220 @@ pub fn read_size(child: &mut Child, size: usize) -> String {
.unwrap();
String::from_utf8(output).unwrap()
}
pub fn vec_of_size(n: usize) -> Vec<u8> {
let mut result = Vec::new();
for _ in 0..n {
result.push('a' as u8);
}
assert_eq!(result.len(), n);
result
}
/// Sanity checks for test utils
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_code_is() {
let res = CmdResult {
tmpd: None,
code: Some(32),
success: false,
stdout: "".into(),
stderr: "".into(),
};
res.code_is(32);
}
#[test]
#[should_panic]
fn test_code_is_fail() {
let res = CmdResult {
tmpd: None,
code: Some(32),
success: false,
stdout: "".into(),
stderr: "".into(),
};
res.code_is(1);
}
#[test]
fn test_failure() {
let res = CmdResult {
tmpd: None,
code: None,
success: false,
stdout: "".into(),
stderr: "".into(),
};
res.failure();
}
#[test]
#[should_panic]
fn test_failure_fail() {
let res = CmdResult {
tmpd: None,
code: None,
success: true,
stdout: "".into(),
stderr: "".into(),
};
res.failure();
}
#[test]
fn test_success() {
let res = CmdResult {
tmpd: None,
code: None,
success: true,
stdout: "".into(),
stderr: "".into(),
};
res.success();
}
#[test]
#[should_panic]
fn test_success_fail() {
let res = CmdResult {
tmpd: None,
code: None,
success: false,
stdout: "".into(),
stderr: "".into(),
};
res.success();
}
#[test]
fn test_no_std_errout() {
let res = CmdResult {
tmpd: None,
code: None,
success: true,
stdout: "".into(),
stderr: "".into(),
};
res.no_stderr();
res.no_stdout();
}
#[test]
#[should_panic]
fn test_no_stderr_fail() {
let res = CmdResult {
tmpd: None,
code: None,
success: true,
stdout: "".into(),
stderr: "asdfsadfa".into(),
};
res.no_stderr();
}
#[test]
#[should_panic]
fn test_no_stdout_fail() {
let res = CmdResult {
tmpd: None,
code: None,
success: true,
stdout: "asdfsadfa".into(),
stderr: "".into(),
};
res.no_stdout();
}
#[test]
fn test_std_does_not_contain() {
let res = CmdResult {
tmpd: None,
code: None,
success: true,
stdout: "This is a likely error message\n".into(),
stderr: "This is a likely error message\n".into(),
};
res.stdout_does_not_contain("unlikely");
res.stderr_does_not_contain("unlikely");
}
#[test]
#[should_panic]
fn test_stdout_does_not_contain_fail() {
let res = CmdResult {
tmpd: None,
code: None,
success: true,
stdout: "This is a likely error message\n".into(),
stderr: "".into(),
};
res.stdout_does_not_contain("likely");
}
#[test]
#[should_panic]
fn test_stderr_does_not_contain_fail() {
let res = CmdResult {
tmpd: None,
code: None,
success: true,
stdout: "".into(),
stderr: "This is a likely error message\n".into(),
};
res.stderr_does_not_contain("likely");
}
#[test]
fn test_stdout_matches() {
let res = CmdResult {
tmpd: None,
code: None,
success: true,
stdout: "This is a likely error message\n".into(),
stderr: "This is a likely error message\n".into(),
};
let positive = regex::Regex::new(".*likely.*").unwrap();
let negative = regex::Regex::new(".*unlikely.*").unwrap();
res.stdout_matches(&positive);
res.stdout_does_not_match(&negative);
}
#[test]
#[should_panic]
fn test_stdout_matches_fail() {
let res = CmdResult {
tmpd: None,
code: None,
success: true,
stdout: "This is a likely error message\n".into(),
stderr: "This is a likely error message\n".into(),
};
let negative = regex::Regex::new(".*unlikely.*").unwrap();
res.stdout_matches(&negative);
}
#[test]
#[should_panic]
fn test_stdout_not_matches_fail() {
let res = CmdResult {
tmpd: None,
code: None,
success: true,
stdout: "This is a likely error message\n".into(),
stderr: "This is a likely error message\n".into(),
};
let positive = regex::Regex::new(".*likely.*").unwrap();
res.stdout_does_not_match(&positive);
}
}

0
tests/fixtures/cat/empty.txt vendored Normal file
View file

View file

@ -0,0 +1,5 @@
cat: test_directory3/test_directory4: Is a directory
cat: filewhichdoesnotexist.txt: No such file or directory (os error 2)
cat: test_directory3/test_directory5: Is a directory
cat: test_directory3/../test_directory3/test_directory5: Is a directory
cat: test_directory3: Is a directory

3
tests/fixtures/install/helloworld.rs vendored Normal file
View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello World!");
}

BIN
tests/fixtures/install/helloworld_linux vendored Executable file

Binary file not shown.

BIN
tests/fixtures/install/helloworld_macos vendored Executable file

Binary file not shown.

View file

@ -0,0 +1,11 @@
456K
4568K
456M
6.2G

View file

@ -0,0 +1,11 @@
456K
456M
4568K
6.2G

View file

@ -0,0 +1,20 @@
4798908.8909800
4798908.45
4798908.340000000000
576,446.890
576,446.88800000
37800
4567.
46.89
45
8.013
1.58590
1.444
1.040000000
1
-.05
-1
-8.90880
-896689
-2028789030

View file

@ -0,0 +1,8 @@
JAN
FEb
apr
apr
JUNNNN
AUG

View file

@ -0,0 +1,8 @@
JAN
JUNNNN
AUG
apr
apr
FEb

View file

@ -0,0 +1,33 @@
-2028789030
-896689
-8.90880
-1
-.05
000
CARAvan
00000001
1
1.040000000
1.444
1.58590
8.013
45
46.89
4567..457
4567.
4567.1
4567.34
37800
576,446.88800000
576,446.890
4798908.340000000000
4798908.45
4798908.8909800

View file

@ -0,0 +1,35 @@
576,446.890
576,446.88800000
4567.1
4567..457
45670.89079.1
45670.89079.098
4567.34
4567.
45
46.89
-1
1
00000001
4798908.340000000000
4798908.45
4798908.8909800
37800
-2028789030
-896689
CARAvan
-8.90880
-.05
1.444
1.58590
1.040000000
8.013
000

View file

@ -0,0 +1,35 @@
576,446.890
576,446.88800000
4567.1
4567..457
45670.89079.1
45670.89079.098
4567.34
4567.
45
46.89
-1
1
00000001
4798908.340000000000
4798908.45
4798908.8909800
37800
-2028789030
-896689
CARAvan
-8.90880
-.05
1.444
1.58590
1.040000000
8.013
000

View file

@ -0,0 +1,2 @@
-10 bb
aa

View file

@ -0,0 +1,3 @@
aa
-10 bb
-10 aa

View file

@ -0,0 +1,11 @@
1.2.3-alpha
1.2.3-alpha2
11.2.3
1.12.4

View file

@ -0,0 +1,11 @@
11.2.3
1.2.3-alpha2
1.2.3-alpha
1.12.4

View file

@ -0,0 +1,3 @@
aaa
bbb
zzz

4
tests/fixtures/sort/words_unique.txt vendored Normal file
View file

@ -0,0 +1,4 @@
zzz
aaa
bbb
bbb