uutests: adjust the tests to use them

This commit is contained in:
Sylvestre Ledru 2025-03-28 09:51:51 +01:00
parent ccfcda531e
commit a0179ea239
102 changed files with 1018 additions and 157 deletions

View file

@ -2,7 +2,9 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_arch() {

View file

@ -4,7 +4,9 @@
// file that was distributed with this source code.
//
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_encode() {

View file

@ -2,7 +2,9 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_encode() {

View file

@ -4,9 +4,11 @@
// file that was distributed with this source code.
// spell-checker:ignore (words) reallylongexecutable nbaz
use crate::common::util::TestScenario;
#[cfg(any(unix, target_os = "redox"))]
use std::ffi::OsStr;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_help() {

View file

@ -5,7 +5,9 @@
// spell-checker: ignore (encodings) lsbf msbf
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_z85_not_padded_decode() {

View file

@ -4,16 +4,18 @@
// file that was distributed with this source code.
// spell-checker:ignore NOFILE nonewline cmdline
use crate::common::util::TestScenario;
#[cfg(not(windows))]
use crate::common::util::vec_of_size;
#[cfg(any(target_os = "linux", target_os = "android"))]
use rlimit::Resource;
#[cfg(target_os = "linux")]
#[cfg(unix)]
use std::fs::File;
use std::fs::OpenOptions;
#[cfg(not(windows))]
use std::process::Stdio;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
#[cfg(not(windows))]
use uutests::util::vec_of_size;
use uutests::util_name;
#[test]
fn test_output_simple() {
@ -668,3 +670,40 @@ fn test_appending_same_input_output() {
.no_stdout()
.stderr_contains("input file is output file");
}
#[cfg(unix)]
#[test]
fn test_uchild_when_no_capture_reading_from_infinite_source() {
use regex::Regex;
let ts = TestScenario::new("cat");
let expected_stdout = b"\0".repeat(12345);
let mut child = ts
.ucmd()
.set_stdin(Stdio::from(File::open("/dev/zero").unwrap()))
.set_stdout(Stdio::piped())
.run_no_wait();
child
.make_assertion()
.with_exact_output(12345, 0)
.stdout_only_bytes(expected_stdout);
child
.kill()
.make_assertion()
.with_current_output()
.stdout_matches(&Regex::new("[\0].*").unwrap())
.no_stderr();
}
#[test]
fn test_child_when_pipe_in() {
let ts = TestScenario::new("cat");
let mut child = ts.ucmd().set_stdin(Stdio::piped()).run_no_wait();
child.pipe_in("content");
child.wait().unwrap().stdout_only("content").success();
ts.ucmd().pipe_in("content").run().stdout_is("content");
}

View file

@ -10,7 +10,10 @@ use std::ffi::CString;
use std::path::Path;
use std::{io, iter, str};
use crate::common::util::*;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn version() {

View file

@ -4,8 +4,11 @@
// file that was distributed with this source code.
// spell-checker:ignore (words) nosuchgroup groupname
use crate::common::util::TestScenario;
use uucore::process::getegid;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_option() {

View file

@ -3,9 +3,13 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::{AtPath, TestScenario, UCommand};
use std::fs::{OpenOptions, Permissions, metadata, set_permissions};
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
use uutests::at_and_ucmd;
use uutests::util::{AtPath, TestScenario, UCommand};
use uutests::new_ucmd;
use uutests::util_name;
static TEST_FILE: &str = "file";
static REFERENCE_FILE: &str = "reference";

View file

@ -4,10 +4,11 @@
// file that was distributed with this source code.
// spell-checker:ignore (words) agroupthatdoesntexist auserthatdoesntexist cuuser groupname notexisting passgrp
use crate::common::util::{CmdResult, TestScenario, is_ci, run_ucmd_as_root};
#[cfg(any(target_os = "linux", target_os = "android"))]
use uucore::process::geteuid;
use uutests::new_ucmd;
use uutests::util::{CmdResult, TestScenario, is_ci, run_ucmd_as_root};
use uutests::util_name;
// Apparently some CI environments have configuration issues, e.g. with 'whoami' and 'id'.
// If we are running inside the CI and "needle" is in "stderr" skipping this test is
// considered okay. If we are not inside the CI this calls assert!(result.success).

View file

@ -4,9 +4,12 @@
// file that was distributed with this source code.
// spell-checker:ignore (words) araba newroot userspec chdir pwd's isroot
use uutests::at_and_ucmd;
use uutests::new_ucmd;
#[cfg(not(target_os = "android"))]
use crate::common::util::is_ci;
use crate::common::util::{TestScenario, run_ucmd_as_root};
use uutests::util::is_ci;
use uutests::util::{TestScenario, run_ucmd_as_root};
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -4,7 +4,10 @@
// file that was distributed with this source code.
// spell-checker:ignore (words) asdf algo algos asha mgmt xffname hexa GFYEQ HYQK Yqxb dont
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
const ALGOS: [&str; 11] = [
"sysv", "bsd", "crc", "md5", "sha1", "sha224", "sha256", "sha384", "sha512", "blake2b", "sm3",
@ -1681,7 +1684,7 @@ fn test_check_incorrectly_formatted_checksum_keeps_processing_hex() {
/// This module reimplements the cksum-base64.pl GNU test.
mod gnu_cksum_base64 {
use super::*;
use crate::common::util::log_info;
use uutests::util::log_info;
const PAIRS: [(&str, &str); 12] = [
("sysv", "0 0 f"),

View file

@ -4,7 +4,9 @@
// file that was distributed with this source code.
// spell-checker:ignore (words) defaultcheck nocheck helpb helpz nwordb nwordwordz wordtotal
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -4,7 +4,12 @@
// file that was distributed with this source code.
// spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE clob btrfs neve ROOTDIR USERDIR procfs outfile uufs xattrs
// spell-checker:ignore bdfl hlsl IRWXO IRWXG getfattr
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::path_concat;
use uutests::util::TestScenario;
use uutests::util_name;
#[cfg(not(windows))]
use std::fs::set_permissions;
@ -34,7 +39,7 @@ use std::time::Duration;
#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(feature = "truncate")]
use crate::common::util::PATH;
use uutests::util::PATH;
static TEST_EXISTING_FILE: &str = "existing_file.txt";
static TEST_HELLO_WORLD_SOURCE: &str = "hello_world.txt";
@ -60,7 +65,7 @@ static TEST_NONEXISTENT_FILE: &str = "nonexistent_file.txt";
unix,
not(any(target_os = "android", target_os = "macos", target_os = "openbsd"))
))]
use crate::common::util::compare_xattrs;
use uutests::util::compare_xattrs;
/// Assert that mode, ownership, and permissions of two metadata objects match.
#[cfg(all(not(windows), not(target_os = "freebsd")))]
@ -2372,7 +2377,7 @@ fn test_cp_target_file_dev_null() {
#[test]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
fn test_cp_one_file_system() {
use crate::common::util::AtPath;
use uutests::util::AtPath;
use walkdir::WalkDir;
let mut scene = TestScenario::new(util_name!());
@ -4669,7 +4674,8 @@ fn test_cp_no_dereference_attributes_only_with_symlink() {
/// contains the test for cp when the source and destination points to the same file
mod same_file {
use crate::common::util::TestScenario;
use uutests::util::TestScenario;
use uutests::util_name;
const FILE_NAME: &str = "foo";
const SYMLINK_NAME: &str = "symlink";
@ -5594,8 +5600,9 @@ mod same_file {
#[cfg(all(unix, not(target_os = "android")))]
mod link_deref {
use crate::common::util::{AtPath, TestScenario};
use std::os::unix::fs::MetadataExt;
use uutests::util::{AtPath, TestScenario};
use uutests::util_name;
const FILE: &str = "file";
const FILE_LINK: &str = "file_link";
@ -6037,8 +6044,8 @@ fn test_cp_no_file() {
not(any(target_os = "android", target_os = "macos", target_os = "openbsd"))
))]
fn test_cp_preserve_xattr_readonly_source() {
use crate::common::util::compare_xattrs;
use std::process::Command;
use uutests::util::compare_xattrs;
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

View file

@ -2,8 +2,11 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use glob::glob;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
/// Returns a string of numbers with the given range, each on a new line.
/// The upper bound is not included.

View file

@ -5,7 +5,10 @@
// spell-checker:ignore defg
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
static INPUT: &str = "lists.txt";

View file

@ -3,10 +3,13 @@ use chrono::{DateTime, Duration, Utc};
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use regex::Regex;
#[cfg(all(unix, not(target_os = "macos")))]
use uucore::process::geteuid;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -4,11 +4,14 @@
// file that was distributed with this source code.
// spell-checker:ignore fname, tname, fpath, specfile, testfile, unspec, ifile, ofile, outfile, fullblock, urand, fileio, atoe, atoibm, availible, behaviour, bmax, bremain, btotal, cflags, creat, ctable, ctty, datastructures, doesnt, etoa, fileout, fname, gnudd, iconvflags, iseek, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, oseek, outfile, parseargs, rlen, rmax, rposition, rremain, rsofar, rstat, sigusr, sigval, wlen, wstat abcdefghijklm abcdefghi nabcde nabcdefg abcdefg fifoname seekable
use crate::common::util::TestScenario;
#[cfg(all(unix, not(feature = "feat_selinux")))]
use crate::common::util::run_ucmd_as_root_with_stdin_stdout;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
#[cfg(unix)]
use uutests::util::run_ucmd_as_root_with_stdin_stdout;
#[cfg(all(not(windows), feature = "printf"))]
use crate::common::util::{TESTS_BINARY, UCommand};
use uutests::util::{UCommand, get_tests_binary};
use uutests::util_name;
use regex::Regex;
use uucore::io::OwnedFileDescriptorOrHandle;
@ -1505,9 +1508,9 @@ fn test_skip_input_fifo() {
#[test]
fn test_multiple_processes_reading_stdin() {
// TODO Investigate if this is possible on Windows.
let printf = format!("{TESTS_BINARY} printf 'abcdef\n'");
let dd_skip = format!("{TESTS_BINARY} dd bs=1 skip=3 count=0");
let dd = format!("{TESTS_BINARY} dd");
let printf = format!("{} printf 'abcdef\n'", get_tests_binary());
let dd_skip = format!("{} dd bs=1 skip=3 count=0", get_tests_binary());
let dd = format!("{} dd", get_tests_binary());
UCommand::new()
.arg(format!("{printf} | ( {dd_skip} && {dd} ) 2> /dev/null"))
.succeeds()
@ -1609,7 +1612,7 @@ fn test_reading_partial_blocks_from_fifo() {
// Start a `dd` process that reads from the fifo (so it will wait
// until the writer process starts).
let mut reader_command = Command::new(TESTS_BINARY);
let mut reader_command = Command::new(get_tests_binary());
let child = reader_command
.args(["dd", "ibs=3", "obs=3", &format!("if={fifoname}")])
.stdout(Stdio::piped())
@ -1653,7 +1656,7 @@ fn test_reading_partial_blocks_from_fifo_unbuffered() {
// until the writer process starts).
//
// `bs=N` takes precedence over `ibs=N` and `obs=N`.
let mut reader_command = Command::new(TESTS_BINARY);
let mut reader_command = Command::new(get_tests_binary());
let child = reader_command
.args(["dd", "bs=3", "ibs=1", "obs=1", &format!("if={fifoname}")])
.stdout(Stdio::piped())

View file

@ -12,7 +12,11 @@
use std::collections::HashSet;
use crate::common::util::TestScenario;
#[cfg(not(any(target_os = "freebsd", target_os = "windows")))]
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -2,8 +2,10 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use regex::Regex;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
/*
* As dir use the same functions than ls, we don't have to retest them here.

View file

@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore overridable colorterm
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
use dircolors::{OutputFmt, StrUtils, guess_syntax};

View file

@ -2,7 +2,9 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -7,9 +7,14 @@
#[cfg(not(windows))]
use regex::Regex;
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
#[cfg(not(target_os = "windows"))]
use crate::common::util::expected_result;
use uutests::unwrap_or_return;
use uutests::util::TestScenario;
#[cfg(not(target_os = "windows"))]
use uutests::util::expected_result;
use uutests::util_name;
#[cfg(not(target_os = "openbsd"))]
const SUB_DIR: &str = "subdir/deeper";

View file

@ -2,9 +2,12 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore (words) araba merci
// spell-checker:ignore (words) araba merci mright
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util::UCommand;
use uutests::util_name;
#[test]
fn test_default() {
@ -391,6 +394,64 @@ fn slash_eight_off_by_one() {
.stdout_only(r"\8");
}
#[test]
fn test_normalized_newlines_stdout_is() {
let res = new_ucmd!().args(&["-ne", "A\r\nB\nC"]).run();
res.normalized_newlines_stdout_is("A\r\nB\nC");
res.normalized_newlines_stdout_is("A\nB\nC");
res.normalized_newlines_stdout_is("A\nB\r\nC");
}
#[test]
fn test_normalized_newlines_stdout_is_fail() {
new_ucmd!()
.args(&["-ne", "A\r\nB\nC"])
.run()
.stdout_is("A\r\nB\nC");
}
#[test]
fn test_cmd_result_stdout_check_and_stdout_str_check() {
let result = new_ucmd!().arg("Hello world").run();
result.stdout_str_check(|stdout| stdout.ends_with("world\n"));
result.stdout_check(|stdout| stdout.get(0..2).unwrap().eq(b"He"));
result.no_stderr();
}
#[test]
fn test_cmd_result_stderr_check_and_stderr_str_check() {
let ts = TestScenario::new("echo");
let result = UCommand::new()
.arg(format!(
"{} {} Hello world >&2",
ts.bin_path.display(),
ts.util_name
))
.run();
result.stderr_str_check(|stderr| stderr.ends_with("world\n"));
result.stderr_check(|stdout| stdout.get(0..2).unwrap().eq(b"He"));
result.no_stdout();
}
#[test]
fn test_cmd_result_stdout_str_check_when_false_then_panics() {
new_ucmd!()
.args(&["-e", "\\f"])
.succeeds()
.stdout_only("\x0C\n");
}
#[cfg(unix)]
#[test]
fn test_cmd_result_signal_when_normal_exit_then_no_signal() {
let result = TestScenario::new("echo").ucmd().run();
assert!(result.signal().is_none());
}
mod posixly_correct {
use super::*;
@ -442,3 +503,56 @@ mod posixly_correct {
.stdout_only("foo");
}
}
#[test]
fn test_child_when_run_with_a_non_blocking_util() {
new_ucmd!()
.arg("hello world")
.run()
.success()
.stdout_only("hello world\n");
}
// Test basically that most of the methods of UChild are working
#[test]
fn test_uchild_when_run_no_wait_with_a_non_blocking_util() {
let mut child = new_ucmd!().arg("hello world").run_no_wait();
// check `child.is_alive()` and `child.delay()` is working
let mut trials = 10;
while child.is_alive() {
assert!(
trials > 0,
"Assertion failed: child process is still alive."
);
child.delay(500);
trials -= 1;
}
assert!(!child.is_alive());
// check `child.is_not_alive()` is working
assert!(child.is_not_alive());
// check the current output is correct
std::assert_eq!(child.stdout(), "hello world\n");
assert!(child.stderr().is_empty());
// check the current output of echo is empty. We already called `child.stdout()` and `echo`
// exited so there's no additional output after the first call of `child.stdout()`
assert!(child.stdout().is_empty());
assert!(child.stderr().is_empty());
// check that we're still able to access all output of the child process, even after exit
// and call to `child.stdout()`
std::assert_eq!(child.stdout_all(), "hello world\n");
assert!(child.stderr_all().is_empty());
// we should be able to call kill without panics, even if the process already exited
child.make_assertion().is_not_alive();
child.kill();
// we should be able to call wait without panics and apply some assertions
child.wait().unwrap().code_is(0).no_stdout().no_stderr();
}

View file

@ -2,12 +2,9 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore (words) bamf chdir rlimit prlimit COMSPEC cout cerr FFFD
// spell-checker:ignore (words) bamf chdir rlimit prlimit COMSPEC cout cerr FFFD winsize xpixel ypixel
#![allow(clippy::missing_errors_doc)]
use crate::common::util::TestScenario;
#[cfg(unix)]
use crate::common::util::UChild;
#[cfg(unix)]
use nix::sys::signal::Signal;
#[cfg(feature = "echo")]
@ -17,6 +14,13 @@ use std::path::Path;
#[cfg(unix)]
use std::process::Command;
use tempfile::tempdir;
use uutests::new_ucmd;
#[cfg(unix)]
use uutests::util::TerminalSimulation;
use uutests::util::TestScenario;
#[cfg(unix)]
use uutests::util::UChild;
use uutests::util_name;
#[cfg(unix)]
struct Target {
@ -520,7 +524,7 @@ fn test_split_string_into_args_debug_output_whitespace_handling() {
fn test_gnu_e20() {
let scene = TestScenario::new(util_name!());
let env_bin = String::from(crate::common::util::TESTS_BINARY) + " " + util_name!();
let env_bin = String::from(uutests::util::get_tests_binary()) + " " + util_name!();
let (input, output) = (
[
@ -1516,3 +1520,205 @@ mod test_raw_string_parser {
);
}
}
#[cfg(unix)]
#[test]
fn test_simulation_of_terminal_false() {
let scene = TestScenario::new("util");
let out = scene.ccmd("env").arg("sh").arg("is_a_tty.sh").succeeds();
std::assert_eq!(
String::from_utf8_lossy(out.stdout()),
"stdin is not a tty\nstdout is not a tty\nstderr is not a tty\n"
);
std::assert_eq!(
String::from_utf8_lossy(out.stderr()),
"This is an error message.\n"
);
}
#[cfg(unix)]
#[test]
fn test_simulation_of_terminal_true() {
let scene = TestScenario::new("util");
let out = scene
.ccmd("env")
.arg("sh")
.arg("is_a_tty.sh")
.terminal_simulation(true)
.succeeds();
std::assert_eq!(
String::from_utf8_lossy(out.stdout()),
"stdin is a tty\r\nterminal size: 30 80\r\nstdout is a tty\r\nstderr is a tty\r\n"
);
std::assert_eq!(
String::from_utf8_lossy(out.stderr()),
"This is an error message.\r\n"
);
}
#[cfg(unix)]
#[test]
fn test_simulation_of_terminal_for_stdin_only() {
let scene = TestScenario::new("util");
let out = scene
.ccmd("env")
.arg("sh")
.arg("is_a_tty.sh")
.terminal_sim_stdio(TerminalSimulation {
stdin: true,
stdout: false,
stderr: false,
..Default::default()
})
.succeeds();
std::assert_eq!(
String::from_utf8_lossy(out.stdout()),
"stdin is a tty\nterminal size: 30 80\nstdout is not a tty\nstderr is not a tty\n"
);
std::assert_eq!(
String::from_utf8_lossy(out.stderr()),
"This is an error message.\n"
);
}
#[cfg(unix)]
#[test]
fn test_simulation_of_terminal_for_stdout_only() {
let scene = TestScenario::new("util");
let out = scene
.ccmd("env")
.arg("sh")
.arg("is_a_tty.sh")
.terminal_sim_stdio(TerminalSimulation {
stdin: false,
stdout: true,
stderr: false,
..Default::default()
})
.succeeds();
std::assert_eq!(
String::from_utf8_lossy(out.stdout()),
"stdin is not a tty\r\nstdout is a tty\r\nstderr is not a tty\r\n"
);
std::assert_eq!(
String::from_utf8_lossy(out.stderr()),
"This is an error message.\n"
);
}
#[cfg(unix)]
#[test]
fn test_simulation_of_terminal_for_stderr_only() {
let scene = TestScenario::new("util");
let out = scene
.ccmd("env")
.arg("sh")
.arg("is_a_tty.sh")
.terminal_sim_stdio(TerminalSimulation {
stdin: false,
stdout: false,
stderr: true,
..Default::default()
})
.succeeds();
std::assert_eq!(
String::from_utf8_lossy(out.stdout()),
"stdin is not a tty\nstdout is not a tty\nstderr is a tty\n"
);
std::assert_eq!(
String::from_utf8_lossy(out.stderr()),
"This is an error message.\r\n"
);
}
#[cfg(unix)]
#[test]
fn test_simulation_of_terminal_size_information() {
let scene = TestScenario::new("util");
let out = scene
.ccmd("env")
.arg("sh")
.arg("is_a_tty.sh")
.terminal_sim_stdio(TerminalSimulation {
size: Some(libc::winsize {
ws_col: 40,
ws_row: 10,
ws_xpixel: 40 * 8,
ws_ypixel: 10 * 10,
}),
stdout: true,
stdin: true,
stderr: true,
})
.succeeds();
std::assert_eq!(
String::from_utf8_lossy(out.stdout()),
"stdin is a tty\r\nterminal size: 10 40\r\nstdout is a tty\r\nstderr is a tty\r\n"
);
std::assert_eq!(
String::from_utf8_lossy(out.stderr()),
"This is an error message.\r\n"
);
}
#[cfg(unix)]
#[test]
fn test_simulation_of_terminal_pty_sends_eot_automatically() {
let scene = TestScenario::new("util");
let mut cmd = scene.ccmd("env");
cmd.timeout(std::time::Duration::from_secs(10));
cmd.args(&["cat", "-"]);
cmd.terminal_simulation(true);
let child = cmd.run_no_wait();
let out = child.wait().unwrap(); // cat would block if there is no eot
std::assert_eq!(String::from_utf8_lossy(out.stderr()), "");
std::assert_eq!(String::from_utf8_lossy(out.stdout()), "\r\n");
}
#[cfg(unix)]
#[test]
fn test_simulation_of_terminal_pty_pipes_into_data_and_sends_eot_automatically() {
let scene = TestScenario::new("util");
let message = "Hello stdin forwarding!";
let mut cmd = scene.ccmd("env");
cmd.args(&["cat", "-"]);
cmd.terminal_simulation(true);
cmd.pipe_in(message);
let child = cmd.run_no_wait();
let out = child.wait().unwrap();
std::assert_eq!(
String::from_utf8_lossy(out.stdout()),
format!("{message}\r\n")
);
std::assert_eq!(String::from_utf8_lossy(out.stderr()), "");
}
#[cfg(unix)]
#[test]
fn test_simulation_of_terminal_pty_write_in_data_and_sends_eot_automatically() {
let scene = TestScenario::new("util");
let mut cmd = scene.ccmd("env");
cmd.args(&["cat", "-"]);
cmd.terminal_simulation(true);
let mut child = cmd.run_no_wait();
child.write_in("Hello stdin forwarding via write_in!");
let out = child.wait().unwrap();
std::assert_eq!(
String::from_utf8_lossy(out.stdout()),
"Hello stdin forwarding via write_in!\r\n"
);
std::assert_eq!(String::from_utf8_lossy(out.stderr()), "");
}

View file

@ -2,8 +2,10 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uucore::display::Quotable;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
// spell-checker:ignore (ToDO) taaaa tbbbb tcccc
#[test]

View file

@ -7,7 +7,9 @@
// spell-checker:ignore abbccd abcac acabc andand bigcmp bignum emptysub
// spell-checker:ignore orempty oror
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_no_arguments() {
@ -400,7 +402,9 @@ fn test_long_input() {
/// Regroup the testcases of the GNU test expr.pl
mod gnu_expr {
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_a() {

View file

@ -10,7 +10,9 @@
clippy::cast_sign_loss
)]
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
use std::time::{Duration, SystemTime};
@ -44,11 +46,11 @@ fn test_repeated_exponents() {
#[cfg(feature = "sort")]
#[cfg(not(target_os = "android"))]
fn test_parallel() {
use crate::common::util::AtPath;
use hex_literal::hex;
use sha1::{Digest, Sha1};
use std::{fs::OpenOptions, time::Duration};
use tempfile::TempDir;
use uutests::util::AtPath;
// factor should only flush the buffer at line breaks
let n_integers = 100_000;
let mut input_string = String::new();

View file

@ -2,13 +2,12 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use regex::Regex;
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
use std::fs::OpenOptions;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_no_args() {
new_ucmd!().fails().no_output();

View file

@ -2,7 +2,9 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -2,7 +2,9 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -5,7 +5,10 @@
//spell-checker: ignore coreutil
use crate::common::util::{TestScenario, check_coreutil_version, expected_result, whoami};
use uutests::new_ucmd;
use uutests::unwrap_or_return;
use uutests::util::{TestScenario, check_coreutil_version, expected_result, whoami};
use uutests::util_name;
const VERSION_MIN_MULTIPLE_USERS: &str = "8.31"; // this feature was introduced in GNU's coreutils 8.31

View file

@ -2,7 +2,10 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
// spell-checker:ignore checkfile, nonames, testf, ntestf
macro_rules! get_hash(
($str:expr) => (
@ -14,7 +17,7 @@ macro_rules! test_digest {
($($id:ident $t:ident $size:expr)*) => ($(
mod $id {
use crate::common::util::*;
use uutests::util::*;
static DIGEST_ARG: &'static str = concat!("--", stringify!($t));
static BITS_ARG: &'static str = concat!("--bits=", stringify!($size));
static EXPECTED_FILE: &'static str = concat!(stringify!($id), ".expected");
@ -72,6 +75,9 @@ macro_rules! test_digest {
#[cfg(windows)]
#[test]
fn test_text_mode() {
use uutests::new_ucmd;
use uutests::util_name;
// TODO Replace this with hard-coded files that store the
// expected output of text mode on an input file that has
// "\r\n" line endings.

View file

@ -6,7 +6,6 @@
// spell-checker:ignore (words) bogusfile emptyfile abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstu
// spell-checker:ignore (words) seekable
use crate::common::util::TestScenario;
#[cfg(all(
not(target_os = "windows"),
not(target_os = "macos"),
@ -15,7 +14,9 @@ use crate::common::util::TestScenario;
not(target_os = "openbsd")
))]
use std::io::Read;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
static INPUT: &str = "lorem_ipsum.txt";
#[test]

View file

@ -2,8 +2,10 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use regex::Regex;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_normal() {

View file

@ -2,7 +2,9 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_hostname() {

View file

@ -5,7 +5,10 @@
// spell-checker:ignore (ToDO) coreutil
use crate::common::util::{TestScenario, check_coreutil_version, expected_result, is_ci, whoami};
use uutests::new_ucmd;
use uutests::unwrap_or_return;
use uutests::util::{TestScenario, check_coreutil_version, expected_result, is_ci, whoami};
use uutests::util_name;
const VERSION_MIN_MULTIPLE_USERS: &str = "8.31"; // this feature was introduced in GNU's coreutils 8.31

View file

@ -4,7 +4,6 @@
// file that was distributed with this source code.
// spell-checker:ignore (words) helloworld nodir objdump n'source
use crate::common::util::{TestScenario, is_ci, run_ucmd_as_root};
#[cfg(not(target_os = "openbsd"))]
use filetime::FileTime;
use std::fs;
@ -14,6 +13,10 @@ use std::process::Command;
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::thread::sleep;
use uucore::process::{getegid, geteuid};
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::{TestScenario, is_ci, run_ucmd_as_root};
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -4,13 +4,15 @@
// file that was distributed with this source code.
// spell-checker:ignore (words) autoformat nocheck
use crate::common::util::TestScenario;
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
use std::fs::OpenOptions;
#[cfg(unix)]
use std::{ffi::OsStr, os::unix::ffi::OsStrExt};
#[cfg(windows)]
use std::{ffi::OsString, os::windows::ffi::OsStringExt};
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -2,13 +2,13 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore IAMNOTASIGNAL
use crate::common::util::TestScenario;
use regex::Regex;
use std::os::unix::process::ExitStatusExt;
use std::process::{Child, Command};
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
// A child process the tests will try to kill.
struct Target {

View file

@ -2,7 +2,10 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -4,8 +4,11 @@
// file that was distributed with this source code.
#![allow(clippy::similar_names)]
use crate::common::util::TestScenario;
use std::path::PathBuf;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -2,8 +2,10 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::{TestScenario, is_ci};
use std::env;
use uutests::new_ucmd;
use uutests::util::{TestScenario, is_ci};
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -10,9 +10,6 @@
clippy::cast_possible_truncation
)]
use crate::common::util::TestScenario;
#[cfg(any(unix, feature = "feat_selinux"))]
use crate::common::util::expected_result;
#[cfg(all(unix, feature = "chmod"))]
use nix::unistd::{close, dup};
use regex::Regex;
@ -29,6 +26,13 @@ use std::path::Path;
use std::path::PathBuf;
use std::thread::sleep;
use std::time::Duration;
use uutests::new_ucmd;
#[cfg(unix)]
use uutests::unwrap_or_return;
use uutests::util::TestScenario;
#[cfg(any(unix, feature = "feat_selinux"))]
use uutests::util::expected_result;
use uutests::{at_and_ucmd, util_name};
const LONG_ARGS: &[&str] = &[
"-l",
@ -2232,6 +2236,7 @@ fn test_ls_recursive_1() {
#[cfg(unix)]
mod quoting {
use super::TestScenario;
use uutests::util_name;
/// Create a directory with "dirname", then for each check, assert that the
/// output is correct.

View file

@ -7,11 +7,15 @@
#![allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
use crate::common::util::TestScenario;
#[cfg(not(windows))]
use libc::mode_t;
#[cfg(not(windows))]
use std::os::unix::fs::PermissionsExt;
#[cfg(not(windows))]
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -2,7 +2,9 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -2,7 +2,9 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
#[cfg(not(windows))]

View file

@ -4,7 +4,10 @@
// file that was distributed with this source code.
// spell-checker:ignore (words) gpghome
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
use uucore::display::Quotable;

View file

@ -2,8 +2,12 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use std::io::IsTerminal;
#[cfg(target_family = "unix")]
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_more_no_arg() {

View file

@ -4,10 +4,12 @@
// file that was distributed with this source code.
//
// spell-checker:ignore mydir
use crate::common::util::TestScenario;
use filetime::FileTime;
use rstest::rstest;
use std::io::Write;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::{at_and_ucmd, util_name};
#[test]
fn test_mv_invalid_arg() {
@ -1670,7 +1672,7 @@ fn test_mv_dir_into_path_slash() {
fn test_acl() {
use std::process::Command;
use crate::common::util::compare_xattrs;
use uutests::util::compare_xattrs;
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
@ -1766,10 +1768,11 @@ fn test_move_should_not_fallback_to_copy() {
#[cfg(target_os = "linux")]
mod inter_partition_copying {
use crate::common::util::TestScenario;
use std::fs::{read_to_string, set_permissions, write};
use std::os::unix::fs::{PermissionsExt, symlink};
use tempfile::TempDir;
use uutests::util::TestScenario;
use uutests::util_name;
// Ensure that the copying code used in an inter-partition move unlinks the destination symlink.
#[test]
@ -1823,6 +1826,7 @@ mod inter_partition_copying {
// that it would output the proper error message.
#[test]
pub(crate) fn test_mv_unlinks_dest_symlink_error_message() {
use uutests::util::TestScenario;
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

View file

@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore libc's setpriority
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
#[cfg(not(target_os = "android"))]

View file

@ -4,7 +4,10 @@
// file that was distributed with this source code.
//
// spell-checker:ignore binvalid finvalid hinvalid iinvalid linvalid nabcabc nabcabcabc ninvalid vinvalid winvalid dabc näää
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -3,9 +3,12 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore winsize Openpty openpty xpixel ypixel ptyprocess
use crate::common::util::TestScenario;
#[cfg(not(target_os = "openbsd"))]
use std::thread::sleep;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
// General observation: nohup.out will not be created in tests run by cargo test
// because stdin/stdout is not attached to a TTY.

View file

@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore incorrectnumber
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -4,7 +4,9 @@
// file that was distributed with this source code.
// spell-checker:ignore (paths) gnutest ronna quetta
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -5,8 +5,11 @@
// spell-checker:ignore abcdefghijklmnopqrstuvwxyz Anone
use crate::common::util::TestScenario;
use unindent::unindent;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
// octal dump of 'abcdefghijklmnopqrstuvwxyz\n'
static ALPHA_OUT: &str = "

View file

@ -5,7 +5,10 @@
// spell-checker:ignore bsdutils toybox
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
struct TestData<'b> {
name: &'b str,

View file

@ -2,7 +2,9 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_no_args() {

View file

@ -3,13 +3,16 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
#[cfg(target_os = "openbsd")]
use crate::common::util::TestScenario;
#[cfg(not(target_os = "openbsd"))]
use crate::common::util::{TestScenario, expected_result};
use pinky::Capitalize;
#[cfg(not(target_os = "openbsd"))]
use uucore::entries::{Locate, Passwd};
use uutests::new_ucmd;
use uutests::unwrap_or_return;
#[cfg(target_os = "openbsd")]
use uutests::util::TestScenario;
#[cfg(not(target_os = "openbsd"))]
use uutests::util::{TestScenario, expected_result};
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -4,9 +4,11 @@
// file that was distributed with this source code.
// spell-checker:ignore (ToDO) Sdivide
use crate::common::util::{TestScenario, UCommand};
use chrono::{DateTime, Duration, Utc};
use std::fs::metadata;
use uutests::new_ucmd;
use uutests::util::{TestScenario, UCommand};
use uutests::util_name;
const DATE_TIME_FORMAT: &str = "%b %d %H:%M %Y";

View file

@ -2,7 +2,8 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_get_all() {

View file

@ -2,7 +2,9 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn basic_literal() {

View file

@ -3,7 +3,10 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore roff
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -6,7 +6,10 @@
use std::path::PathBuf;
use crate::common::util::{TestScenario, UCommand};
use uutests::new_ucmd;
use uutests::util::{TestScenario, UCommand};
//use uutests::at_and_ucmd;
use uutests::{at_and_ucmd, util_name};
#[test]
fn test_invalid_arg() {

View file

@ -3,7 +3,10 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore regfile
use crate::common::util::{TestScenario, get_root_path};
use uutests::new_ucmd;
use uutests::path_concat;
use uutests::util::{TestScenario, get_root_path};
use uutests::{at_and_ucmd, util_name};
static GIBBERISH: &str = "supercalifragilisticexpialidocious";

View file

@ -3,7 +3,10 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore nusr
use crate::common::util::{TestScenario, get_root_path};
use uutests::new_ucmd;
use uutests::path_concat;
use uutests::util::{TestScenario, get_root_path};
use uutests::{at_and_ucmd, util_name};
#[cfg(windows)]
use regex::Regex;

View file

@ -6,7 +6,10 @@
use std::process::Stdio;
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {
@ -777,6 +780,64 @@ fn test_non_utf8() {
assert!(!at.file_exists(file));
}
#[test]
fn test_uchild_when_run_no_wait_with_a_blocking_command() {
let ts = TestScenario::new("rm");
let at = &ts.fixtures;
at.mkdir("a");
at.touch("a/empty");
#[cfg(target_vendor = "apple")]
let delay: u64 = 2000;
#[cfg(not(target_vendor = "apple"))]
let delay: u64 = 1000;
let yes = if cfg!(windows) { "y\r\n" } else { "y\n" };
let mut child = ts
.ucmd()
.set_stdin(Stdio::piped())
.stderr_to_stdout()
.args(&["-riv", "a"])
.run_no_wait();
child
.make_assertion_with_delay(delay)
.is_alive()
.with_current_output()
.stdout_is("rm: descend into directory 'a'? ");
#[cfg(windows)]
let expected = "rm: descend into directory 'a'? \
rm: remove regular empty file 'a\\empty'? ";
#[cfg(unix)]
let expected = "rm: descend into directory 'a'? \
rm: remove regular empty file 'a/empty'? ";
child.write_in(yes);
child
.make_assertion_with_delay(delay)
.is_alive()
.with_all_output()
.stdout_is(expected);
#[cfg(windows)]
let expected = "removed 'a\\empty'\nrm: remove directory 'a'? ";
#[cfg(unix)]
let expected = "removed 'a/empty'\nrm: remove directory 'a'? ";
child
.write_in(yes)
.make_assertion_with_delay(delay)
.is_alive()
.with_exact_output(44, 0)
.stdout_only(expected);
let expected = "removed directory 'a'\n";
child.write_in(yes);
child.wait().unwrap().stdout_only(expected).success();
}
#[test]
fn test_recursive_interactive() {
let (at, mut ucmd) = at_and_ucmd!();

View file

@ -2,7 +2,10 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
const DIR: &str = "dir";
const DIR_FILE: &str = "dir/file";

View file

@ -6,7 +6,9 @@
#![cfg(feature = "feat_selinux")]
use crate::common::util::*;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
// TODO: Check the implementation of `--compute` somehow.

View file

@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore lmnop xlmnop
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -5,7 +5,10 @@
// spell-checker:ignore wipesync
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -4,7 +4,10 @@
// file that was distributed with this source code.
// spell-checker:ignore (ToDO) unwritable
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -5,10 +5,13 @@
use rstest::rstest;
// spell-checker:ignore dont SIGBUS SIGSEGV sigsegv sigbus
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[cfg(unix)]
use nix::sys::signal::Signal::{SIGBUS, SIGSEGV};
use std::io::ErrorKind;
use std::time::{Duration, Instant};
#[test]
@ -252,8 +255,8 @@ fn test_sleep_when_input_has_only_whitespace_then_error(#[case] input: &str) {
#[test]
fn test_sleep_when_multiple_input_some_with_error_then_shows_all_errors() {
let expected = "invalid time interval 'abc': Invalid input: abc\n\
sleep: invalid time interval '1years': Invalid time unit: 'years' at position 2\n\
sleep: invalid time interval ' ': Found only whitespace in input";
sleep: invalid time interval '1years': Invalid time unit: 'years' at position 2\n\
sleep: invalid time interval ' ': Found only whitespace in input";
// Even if one of the arguments is valid, but the rest isn't, we should still fail and exit early.
// So, the timeout of 10 seconds ensures we haven't executed `thread::sleep` with the only valid
@ -272,3 +275,141 @@ fn test_negative_interval() {
.fails()
.usage_error("invalid time interval '-1': Number was negative");
}
#[cfg(unix)]
#[test]
#[should_panic = "Program must be run first or has not finished"]
fn test_cmd_result_signal_when_still_running_then_panic() {
let mut child = TestScenario::new("sleep").ucmd().arg("60").run_no_wait();
child
.make_assertion()
.is_alive()
.with_current_output()
.signal();
}
#[cfg(unix)]
#[test]
fn test_cmd_result_signal_when_kill_then_signal() {
let mut child = TestScenario::new("sleep").ucmd().arg("60").run_no_wait();
child.kill();
child
.make_assertion()
.is_not_alive()
.with_current_output()
.signal_is(9)
.signal_name_is("SIGKILL")
.signal_name_is("KILL")
.signal_name_is("9")
.signal()
.expect("Signal was none");
let result = child.wait().unwrap();
result
.signal_is(9)
.signal_name_is("SIGKILL")
.signal_name_is("KILL")
.signal_name_is("9")
.signal()
.expect("Signal was none");
}
#[cfg(unix)]
#[rstest]
#[case::signal_only_part_of_name("IGKILL")] // spell-checker: disable-line
#[case::signal_just_sig("SIG")]
#[case::signal_value_too_high("100")]
#[case::signal_value_negative("-1")]
#[should_panic = "Invalid signal name or value"]
fn test_cmd_result_signal_when_invalid_signal_name_then_panic(#[case] signal_name: &str) {
let mut child = TestScenario::new("sleep").ucmd().arg("60").run_no_wait();
child.kill();
let result = child.wait().unwrap();
result.signal_name_is(signal_name);
}
#[test]
#[cfg(unix)]
fn test_cmd_result_signal_name_is_accepts_lowercase() {
let mut child = TestScenario::new("sleep").ucmd().arg("60").run_no_wait();
child.kill();
let result = child.wait().unwrap();
result.signal_name_is("sigkill");
result.signal_name_is("kill");
}
#[test]
fn test_uchild_when_wait_and_timeout_is_reached_then_timeout_error() {
let ts = TestScenario::new("sleep");
let child = ts
.ucmd()
.timeout(Duration::from_secs(1))
.arg("10.0")
.run_no_wait();
match child.wait() {
Err(error) if error.kind() == ErrorKind::Other => {
std::assert_eq!(error.to_string(), "wait: Timeout of '1s' reached");
}
Err(error) => panic!("Assertion failed: Expected error with timeout but was: {error}"),
Ok(_) => panic!("Assertion failed: Expected timeout of `wait`."),
}
}
#[rstest]
#[timeout(Duration::from_secs(5))]
fn test_uchild_when_kill_and_timeout_higher_than_kill_time_then_no_panic() {
let ts = TestScenario::new("sleep");
let mut child = ts
.ucmd()
.timeout(Duration::from_secs(60))
.arg("20.0")
.run_no_wait();
child.kill().make_assertion().is_not_alive();
}
#[test]
fn test_uchild_when_try_kill_and_timeout_is_reached_then_error() {
let ts = TestScenario::new("sleep");
let mut child = ts.ucmd().timeout(Duration::ZERO).arg("10.0").run_no_wait();
match child.try_kill() {
Err(error) if error.kind() == ErrorKind::Other => {
std::assert_eq!(error.to_string(), "kill: Timeout of '0s' reached");
}
Err(error) => panic!("Assertion failed: Expected error with timeout but was: {error}"),
Ok(()) => panic!("Assertion failed: Expected timeout of `try_kill`."),
}
}
#[test]
#[should_panic = "kill: Timeout of '0s' reached"]
fn test_uchild_when_kill_with_timeout_and_timeout_is_reached_then_panic() {
let ts = TestScenario::new("sleep");
let mut child = ts.ucmd().timeout(Duration::ZERO).arg("10.0").run_no_wait();
child.kill();
panic!("Assertion failed: Expected timeout of `kill`.");
}
#[test]
#[should_panic(expected = "wait: Timeout of '1.1s' reached")]
fn test_ucommand_when_run_with_timeout_and_timeout_is_reached_then_panic() {
let ts = TestScenario::new("sleep");
ts.ucmd()
.timeout(Duration::from_millis(1100))
.arg("10.0")
.run();
panic!("Assertion failed: Expected timeout of `run`.")
}
#[rstest]
#[timeout(Duration::from_secs(10))]
fn test_ucommand_when_run_with_timeout_higher_then_execution_time_then_no_panic() {
let ts = TestScenario::new("sleep");
ts.ucmd().timeout(Duration::from_secs(60)).arg("1.0").run();
}

View file

@ -8,7 +8,10 @@
use std::time::Duration;
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
fn test_helper(file_name: &str, possible_args: &[&str]) {
for args in possible_args {

View file

@ -4,7 +4,6 @@
// file that was distributed with this source code.
// spell-checker:ignore xzaaa sixhundredfiftyonebytes ninetyonebytes threebytes asciilowercase ghijkl mnopq rstuv wxyz fivelines twohundredfortyonebytes onehundredlines nbbbb dxen ncccc rlimit NOFILE
use crate::common::util::{AtPath, TestScenario};
use rand::{Rng, SeedableRng, rng};
use regex::Regex;
#[cfg(any(target_os = "linux", target_os = "android"))]
@ -16,6 +15,11 @@ use std::{
fs::{File, read_dir},
io::{BufWriter, Read, Write},
};
use uutests::util::{AtPath, TestScenario};
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util_name;
fn random_chars(n: usize) -> String {
rng()

View file

@ -3,7 +3,11 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::{TestScenario, expected_result};
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::unwrap_or_return;
use uutests::util::{TestScenario, expected_result};
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -2,8 +2,10 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use uutests::new_ucmd;
#[cfg(not(target_os = "windows"))]
use crate::common::util::TestScenario;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn invalid_input() {

View file

@ -4,7 +4,9 @@
// file that was distributed with this source code.
// spell-checker:ignore parenb parmrk ixany iuclc onlcr ofdel icanon noflsh
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -2,7 +2,10 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -2,9 +2,11 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use std::fs;
use tempfile::tempdir;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore axxbxx bxxaxx axxx axxxx xxaxx xxax xxxxa axyz zyax zyxa
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -13,12 +13,6 @@
clippy::cast_possible_truncation
)]
use crate::common::random::{AlphanumericNewline, RandomizedString};
use crate::common::util::TestScenario;
#[cfg(unix)]
use crate::common::util::expected_result;
#[cfg(not(windows))]
use crate::common::util::is_ci;
use pretty_assertions::assert_eq;
use rand::distr::Alphanumeric;
use rstest::rstest;
@ -45,6 +39,18 @@ use tail::chunks::BUFFER_SIZE as CHUNK_BUFFER_SIZE;
not(target_os = "openbsd")
))]
use tail::text;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::random::{AlphanumericNewline, RandomizedString};
#[cfg(unix)]
use uutests::unwrap_or_return;
use uutests::util::TestScenario;
#[cfg(unix)]
use uutests::util::expected_result;
#[cfg(unix)]
#[cfg(not(windows))]
use uutests::util::is_ci;
use uutests::util_name;
const FOOBAR_TXT: &str = "foobar.txt";
const FOOBAR_2_TXT: &str = "foobar2.txt";
@ -4805,3 +4811,39 @@ fn test_following_with_pid() {
child.kill();
}
// This error was first detected when running tail so tail is used here but
// should fail with any command that takes piped input.
// See also https://github.com/uutils/coreutils/issues/3895
#[test]
#[cfg_attr(not(feature = "expensive_tests"), ignore)]
fn test_when_piped_input_then_no_broken_pipe() {
let ts = TestScenario::new("tail");
for i in 0..10000 {
dbg!(i);
let test_string = "a\nb\n";
ts.ucmd()
.args(&["-n", "0"])
.pipe_in(test_string)
.succeeds()
.no_stdout()
.no_stderr();
}
}
#[test]
fn test_child_when_run_with_stderr_to_stdout() {
let ts = TestScenario::new("tail");
let at = &ts.fixtures;
at.write("data", "file data\n");
let expected_stdout = "==> data <==\n\
file data\n\
tail: cannot open 'missing' for reading: No such file or directory\n";
ts.ucmd()
.args(&["data", "missing"])
.stderr_to_stdout()
.fails()
.stdout_only(expected_stdout);
}

View file

@ -4,7 +4,9 @@
// file that was distributed with this source code.
#![allow(clippy::borrow_as_ptr)]
use crate::common::util::TestScenario;
use uutests::util::TestScenario;
use uutests::{at_and_ucmd, new_ucmd, util_name};
use regex::Regex;
#[cfg(target_os = "linux")]
use std::fmt::Write;
@ -160,12 +162,15 @@ fn test_tee_no_more_writeable_2() {
#[cfg(target_os = "linux")]
mod linux_only {
use crate::common::util::{AtPath, CmdResult, TestScenario, UCommand};
use uutests::util::{AtPath, CmdResult, TestScenario, UCommand};
use std::fmt::Write;
use std::fs::File;
use std::process::Stdio;
use std::time::Duration;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util_name;
fn make_broken_pipe() -> File {
use libc::c_int;

View file

@ -5,7 +5,10 @@
// spell-checker:ignore (words) egid euid pseudofloat
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_empty_test_equivalent_to_false() {

View file

@ -3,7 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore dont
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -4,12 +4,15 @@
// file that was distributed with this source code.
// spell-checker:ignore (formats) cymdhm cymdhms mdhm mdhms ymdhm ymdhms datetime mktime
use crate::common::util::{AtPath, TestScenario};
use filetime::FileTime;
#[cfg(not(target_os = "freebsd"))]
use filetime::set_symlink_file_times;
use std::fs::remove_file;
use std::path::PathBuf;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::{AtPath, TestScenario};
use uutests::util_name;
fn get_file_times(at: &AtPath, path: &str) -> (FileTime, FileTime) {
let m = at.metadata(path);

View file

@ -3,7 +3,10 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore aabbaa aabbcc aabc abbb abbbcddd abcc abcdefabcdef abcdefghijk abcdefghijklmn abcdefghijklmnop ABCDEFGHIJKLMNOPQRS abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFZZ abcxyz ABCXYZ abcxyzabcxyz ABCXYZABCXYZ acbdef alnum amzamz AMZXAMZ bbbd cclass cefgm cntrl compl dabcdef dncase Gzabcdefg PQRST upcase wxyzz xdigit XXXYYY xycde xyyye xyyz xyzzzzxyzzzz ZABCDEF Zamz Cdefghijkl Cdefghijklmn asdfqqwweerr qwerr asdfqwer qwer aassddffqwer asdfqwer
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[cfg(unix)]
use std::{ffi::OsStr, os::unix::ffi::OsStrExt};

View file

@ -2,12 +2,12 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use regex::Regex;
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
use std::fs::OpenOptions;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_no_args() {

View file

@ -5,8 +5,11 @@
// spell-checker:ignore (words) RFILE
use crate::common::util::TestScenario;
use std::io::{Seek, SeekFrom, Write};
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
static FILE1: &str = "truncate_test_1";
static FILE2: &str = "truncate_test_2";

View file

@ -4,7 +4,10 @@
// file that was distributed with this source code.
#![allow(clippy::cast_possible_wrap)]
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -4,7 +4,9 @@
// file that was distributed with this source code.
use std::fs::File;
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
#[cfg(not(windows))]

View file

@ -2,7 +2,10 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -3,7 +3,10 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore contenta
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -4,8 +4,11 @@
// file that was distributed with this source code.
// spell-checker:ignore nabcd badoption schar
use crate::common::util::TestScenario;
use uucore::posix::OBSOLETE;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
static INPUT: &str = "sorted.txt";
static OUTPUT: &str = "sorted-output.txt";

View file

@ -2,7 +2,10 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -6,7 +6,10 @@
// spell-checker:ignore bincode serde utmp runlevel testusr testx
#![allow(clippy::cast_possible_wrap, clippy::unreadable_literal)]
use crate::common::util::TestScenario;
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[cfg(not(any(target_os = "macos", target_os = "openbsd")))]
use bincode::serialize;

View file

@ -2,7 +2,9 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
#[test]
fn test_invalid_arg() {

View file

@ -2,8 +2,10 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::TestScenario;
use regex::Regex;
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
/*
* As vdir use the same functions than ls, we don't have to retest them here.

View file

@ -3,7 +3,11 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use crate::common::util::{TestScenario, vec_of_size};
#[cfg(target_os = "linux")]
use uutests::at_and_ucmd;
use uutests::new_ucmd;
use uutests::util::{TestScenario, vec_of_size};
use uutests::util_name;
// spell-checker:ignore (flags) lwmcL clmwL ; (path) bogusfile emptyfile manyemptylines moby notrailingnewline onelongemptyline onelongword weirdchars
#[test]

View file

@ -5,8 +5,10 @@
// spell-checker:ignore (flags) runlevel mesg
use crate::common::util::{TestScenario, expected_result};
use uutests::new_ucmd;
use uutests::unwrap_or_return;
use uutests::util::{TestScenario, expected_result};
use uutests::util_name;
#[test]
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);

Some files were not shown because too many files have changed in this diff Show more