mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-16 19:56:17 +00:00
Merge branch 'master' of github.com:uutils/coreutils into hbina-tr-reimplement-expansion
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
This commit is contained in:
commit
c4de592e90
34 changed files with 227 additions and 154 deletions
|
@ -15,6 +15,7 @@ fn test_missing_operand() {
|
|||
|
||||
#[test]
|
||||
fn test_enter_chroot_fails() {
|
||||
// NOTE: since #2689 this test also ensures that we don't regress #2687
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
at.mkdir("jail");
|
||||
|
@ -89,3 +90,26 @@ fn test_preference_of_userspec() {
|
|||
println!("result.stdout = {}", result.stdout_str());
|
||||
println!("result.stderr = {}", result.stderr_str());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_shell() {
|
||||
// NOTE: This test intends to trigger code which can only be reached with root permissions.
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
let dir = "CHROOT_DIR";
|
||||
at.mkdir(dir);
|
||||
|
||||
let shell = std::env::var("SHELL").unwrap_or_else(|_| "/bin/sh".to_string());
|
||||
let _expected = format!(
|
||||
"chroot: failed to run command '{}': No such file or directory",
|
||||
shell
|
||||
);
|
||||
|
||||
// TODO: [2021-09; jhscheer] uncomment if/when #2692 gets merged
|
||||
// if let Ok(result) = run_ucmd_as_root(&ts, &[dir]) {
|
||||
// result.stderr_contains(expected);
|
||||
// } else {
|
||||
// print!("TEST SKIPPED");
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -28,9 +28,7 @@ macro_rules! fixture_path {
|
|||
macro_rules! assert_fixture_exists {
|
||||
($fname:expr) => {{
|
||||
let fpath = fixture_path!($fname);
|
||||
if !fpath.exists() {
|
||||
panic!("Fixture missing: {:?}", fpath);
|
||||
}
|
||||
assert!(fpath.exists(), "Fixture missing: {:?}", fpath);
|
||||
}};
|
||||
}
|
||||
|
||||
|
@ -38,9 +36,7 @@ macro_rules! assert_fixture_exists {
|
|||
macro_rules! assert_fixture_not_exists {
|
||||
($fname:expr) => {{
|
||||
let fpath = PathBuf::from(format!("./fixtures/dd/{}", $fname));
|
||||
if fpath.exists() {
|
||||
panic!("Fixture present: {:?}", fpath);
|
||||
}
|
||||
assert!(!fpath.exists(), "Fixture present: {:?}", fpath);
|
||||
}};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// spell-checker:ignore abcdefghijklmnopqrstuvwxyz
|
||||
// * This file is part of the uutils coreutils package.
|
||||
// *
|
||||
// * For the full copyright and license information, please view the LICENSE
|
||||
|
@ -35,9 +36,10 @@ fn test_file() {
|
|||
{
|
||||
let mut f = File::create(&file).unwrap();
|
||||
// spell-checker:disable-next-line
|
||||
if f.write_all(b"abcdefghijklmnopqrstuvwxyz\n").is_err() {
|
||||
panic!("Test setup failed - could not write file");
|
||||
}
|
||||
assert!(
|
||||
!f.write_all(b"abcdefghijklmnopqrstuvwxyz\n").is_err(),
|
||||
"Test setup failed - could not write file"
|
||||
);
|
||||
}
|
||||
|
||||
new_ucmd!()
|
||||
|
@ -75,9 +77,10 @@ fn test_2files() {
|
|||
// spell-checker:disable-next-line
|
||||
for &(path, data) in &[(&file1, "abcdefghijklmnop"), (&file2, "qrstuvwxyz\n")] {
|
||||
let mut f = File::create(&path).unwrap();
|
||||
if f.write_all(data.as_bytes()).is_err() {
|
||||
panic!("Test setup failed - could not write file");
|
||||
}
|
||||
assert!(
|
||||
!f.write_all(data.as_bytes()).is_err(),
|
||||
"Test setup failed - could not write file"
|
||||
);
|
||||
}
|
||||
|
||||
new_ucmd!()
|
||||
|
@ -126,9 +129,10 @@ fn test_from_mixed() {
|
|||
let (data1, data2, data3) = ("abcdefg", "hijklmnop", "qrstuvwxyz\n");
|
||||
for &(path, data) in &[(&file1, data1), (&file3, data3)] {
|
||||
let mut f = File::create(&path).unwrap();
|
||||
if f.write_all(data.as_bytes()).is_err() {
|
||||
panic!("Test setup failed - could not write file");
|
||||
}
|
||||
assert!(
|
||||
!f.write_all(data.as_bytes()).is_err(),
|
||||
"Test setup failed - could not write file"
|
||||
);
|
||||
}
|
||||
|
||||
new_ucmd!()
|
||||
|
|
|
@ -1,6 +1,69 @@
|
|||
use crate::common::util::*;
|
||||
use std::io::Read;
|
||||
|
||||
#[test]
|
||||
fn test_hex_rejects_sign_after_identifier() {
|
||||
new_ucmd!()
|
||||
.args(&["0x-123ABC"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("invalid hexadecimal argument: '0x-123ABC'")
|
||||
.stderr_contains("for more information.");
|
||||
new_ucmd!()
|
||||
.args(&["0x+123ABC"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("invalid hexadecimal argument: '0x+123ABC'")
|
||||
.stderr_contains("for more information.");
|
||||
new_ucmd!()
|
||||
.args(&["-0x-123ABC"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("invalid hexadecimal argument: '-0x-123ABC'")
|
||||
.stderr_contains("for more information.");
|
||||
new_ucmd!()
|
||||
.args(&["-0x+123ABC"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("invalid hexadecimal argument: '-0x+123ABC'")
|
||||
.stderr_contains("for more information.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hex_lowercase_uppercase() {
|
||||
new_ucmd!()
|
||||
.args(&["0xa", "0xA"])
|
||||
.succeeds()
|
||||
.stdout_is("10\n");
|
||||
new_ucmd!()
|
||||
.args(&["0Xa", "0XA"])
|
||||
.succeeds()
|
||||
.stdout_is("10\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hex_big_number() {
|
||||
new_ucmd!()
|
||||
.args(&[
|
||||
"0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
|
||||
"0x100000000000000000000000000000000",
|
||||
])
|
||||
.succeeds()
|
||||
.stdout_is(
|
||||
"340282366920938463463374607431768211455\n340282366920938463463374607431768211456\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hex_identifier_in_wrong_place() {
|
||||
new_ucmd!()
|
||||
.args(&["1234ABCD0x"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("invalid hexadecimal argument: '1234ABCD0x'")
|
||||
.stderr_contains("for more information.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rejects_nan() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
|
|
@ -163,25 +163,23 @@ impl CmdResult {
|
|||
|
||||
/// asserts that the command resulted in a success (zero) status code
|
||||
pub fn success(&self) -> &CmdResult {
|
||||
if !self.success {
|
||||
panic!(
|
||||
"Command was expected to succeed.\nstdout = {}\n stderr = {}",
|
||||
self.stdout_str(),
|
||||
self.stderr_str()
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
self.success,
|
||||
"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 {
|
||||
if self.success {
|
||||
panic!(
|
||||
"Command was expected to fail.\nstdout = {}\n stderr = {}",
|
||||
self.stdout_str(),
|
||||
self.stderr_str()
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
!self.success,
|
||||
"Command was expected to fail.\nstdout = {}\n stderr = {}",
|
||||
self.stdout_str(),
|
||||
self.stderr_str()
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -197,12 +195,11 @@ 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 {
|
||||
if !self.stderr.is_empty() {
|
||||
panic!(
|
||||
"Expected stderr to be empty, but it's:\n{}",
|
||||
self.stderr_str()
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
self.stderr.is_empty(),
|
||||
"Expected stderr to be empty, but it's:\n{}",
|
||||
self.stderr_str()
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -213,12 +210,11 @@ 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 {
|
||||
if !self.stdout.is_empty() {
|
||||
panic!(
|
||||
"Expected stdout to be empty, but it's:\n{}",
|
||||
self.stderr_str()
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
self.stdout.is_empty(),
|
||||
"Expected stdout to be empty, but it's:\n{}",
|
||||
self.stderr_str()
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -868,9 +864,7 @@ impl UCommand {
|
|||
/// Add a parameter to the invocation. Path arguments are treated relative
|
||||
/// to the test environment directory.
|
||||
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut UCommand {
|
||||
if self.has_run {
|
||||
panic!("{}", ALREADY_RUN);
|
||||
}
|
||||
assert!(!self.has_run, ALREADY_RUN);
|
||||
self.comm_string.push(' ');
|
||||
self.comm_string
|
||||
.push_str(arg.as_ref().to_str().unwrap_or_default());
|
||||
|
@ -881,9 +875,7 @@ impl UCommand {
|
|||
/// Add multiple parameters to the invocation. Path arguments are treated relative
|
||||
/// to the test environment directory.
|
||||
pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> &mut UCommand {
|
||||
if self.has_run {
|
||||
panic!("{}", MULTIPLE_STDIN_MEANINGLESS);
|
||||
}
|
||||
assert!(!self.has_run, MULTIPLE_STDIN_MEANINGLESS);
|
||||
let strings = args
|
||||
.iter()
|
||||
.map(|s| s.as_ref().to_os_string())
|
||||
|
@ -901,9 +893,7 @@ impl UCommand {
|
|||
|
||||
/// provides standard input to feed in to the command when spawned
|
||||
pub fn pipe_in<T: Into<Vec<u8>>>(&mut self, input: T) -> &mut UCommand {
|
||||
if self.bytes_into_stdin.is_some() {
|
||||
panic!("{}", MULTIPLE_STDIN_MEANINGLESS);
|
||||
}
|
||||
assert!(!self.bytes_into_stdin.is_some(), MULTIPLE_STDIN_MEANINGLESS);
|
||||
self.bytes_into_stdin = Some(input.into());
|
||||
self
|
||||
}
|
||||
|
@ -918,9 +908,7 @@ impl UCommand {
|
|||
/// 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.bytes_into_stdin.is_none() {
|
||||
panic!("{}", NO_STDIN_MEANINGLESS);
|
||||
}
|
||||
assert!(!self.bytes_into_stdin.is_none(), NO_STDIN_MEANINGLESS);
|
||||
self.ignore_stdin_write_error = true;
|
||||
self
|
||||
}
|
||||
|
@ -930,9 +918,7 @@ impl UCommand {
|
|||
K: AsRef<OsStr>,
|
||||
V: AsRef<OsStr>,
|
||||
{
|
||||
if self.has_run {
|
||||
panic!("{}", ALREADY_RUN);
|
||||
}
|
||||
assert!(!self.has_run, ALREADY_RUN);
|
||||
self.raw.env(key, val);
|
||||
self
|
||||
}
|
||||
|
@ -951,9 +937,7 @@ impl UCommand {
|
|||
/// Spawns the command, feeds the stdin if any, and returns the
|
||||
/// child process immediately.
|
||||
pub fn run_no_wait(&mut self) -> Child {
|
||||
if self.has_run {
|
||||
panic!("{}", ALREADY_RUN);
|
||||
}
|
||||
assert!(!self.has_run, ALREADY_RUN);
|
||||
self.has_run = true;
|
||||
log_info("run", &self.comm_string);
|
||||
let mut child = self
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue