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
This commit is contained in:
commit
38659de66d
16 changed files with 764 additions and 194 deletions
|
@ -541,7 +541,7 @@ fn test_no_operands() {
|
|||
.arg("777")
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.stderr_is("chmod: missing operand");
|
||||
.usage_error("missing operand");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
// spell-checker:ignore (words) bamf chdir
|
||||
|
||||
#[cfg(not(windows))]
|
||||
use std::fs;
|
||||
// spell-checker:ignore (words) bamf chdir rlimit prlimit COMSPEC
|
||||
|
||||
use crate::common::util::*;
|
||||
use std::env;
|
||||
|
@ -80,6 +77,20 @@ fn test_combined_file_set_unset() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unset_invalid_variables() {
|
||||
use uucore::display::Quotable;
|
||||
|
||||
// Cannot test input with \0 in it, since output will also contain \0. rlimit::prlimit fails
|
||||
// with this error: Error { kind: InvalidInput, message: "nul byte found in provided data" }
|
||||
for var in &["", "a=b"] {
|
||||
new_ucmd!().arg("-u").arg(var).run().stderr_only(format!(
|
||||
"env: cannot unset {}: Invalid argument",
|
||||
var.quote()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_name_value_pair() {
|
||||
let out = new_ucmd!().arg("FOO=bar").run();
|
||||
|
@ -163,7 +174,7 @@ fn test_fail_null_with_program() {
|
|||
fn test_change_directory() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let temporary_directory = tempdir().unwrap();
|
||||
let temporary_path = fs::canonicalize(temporary_directory.path()).unwrap();
|
||||
let temporary_path = std::fs::canonicalize(temporary_directory.path()).unwrap();
|
||||
assert_ne!(env::current_dir().unwrap(), temporary_path);
|
||||
|
||||
// command to print out current working directory
|
||||
|
@ -179,27 +190,36 @@ fn test_change_directory() {
|
|||
assert_eq!(out.trim(), temporary_path.as_os_str())
|
||||
}
|
||||
|
||||
// no way to consistently get "current working directory", `cd` doesn't work @ CI
|
||||
// instead, we test that the unique temporary directory appears somewhere in the printed variables
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn test_change_directory() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let temporary_directory = tempdir().unwrap();
|
||||
let temporary_path = temporary_directory.path();
|
||||
|
||||
assert_ne!(env::current_dir().unwrap(), temporary_path);
|
||||
let temporary_path = temporary_directory.path();
|
||||
let temporary_path = temporary_path
|
||||
.strip_prefix(r"\\?\")
|
||||
.unwrap_or(temporary_path);
|
||||
|
||||
let env_cd = env::current_dir().unwrap();
|
||||
let env_cd = env_cd.strip_prefix(r"\\?\").unwrap_or(&env_cd);
|
||||
|
||||
assert_ne!(env_cd, temporary_path);
|
||||
|
||||
// COMSPEC is a variable that contains the full path to cmd.exe
|
||||
let cmd_path = env::var("COMSPEC").unwrap();
|
||||
|
||||
// command to print out current working directory
|
||||
let pwd = [&*cmd_path, "/C", "cd"];
|
||||
|
||||
let out = scene
|
||||
.ucmd()
|
||||
.arg("--chdir")
|
||||
.arg(&temporary_path)
|
||||
.args(&pwd)
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
|
||||
assert!(!out
|
||||
.lines()
|
||||
.any(|line| line.ends_with(temporary_path.file_name().unwrap().to_str().unwrap())));
|
||||
assert_eq!(out.trim(), temporary_path.as_os_str())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -314,3 +314,39 @@ fn test_rm_verbose_slash() {
|
|||
assert!(!at.dir_exists(dir));
|
||||
assert!(!at.file_exists(file_a));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rm_silently_accepts_presume_input_tty1() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file_1 = "test_rm_silently_accepts_presume_input_tty1";
|
||||
|
||||
at.touch(file_1);
|
||||
|
||||
ucmd.arg("--presume-input-tty").arg(file_1).succeeds();
|
||||
|
||||
assert!(!at.file_exists(file_1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rm_silently_accepts_presume_input_tty2() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file_2 = "test_rm_silently_accepts_presume_input_tty2";
|
||||
|
||||
at.touch(file_2);
|
||||
|
||||
ucmd.arg("---presume-input-tty").arg(file_2).succeeds();
|
||||
|
||||
assert!(!at.file_exists(file_2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rm_silently_accepts_presume_input_tty3() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file_3 = "test_rm_silently_accepts_presume_input_tty3";
|
||||
|
||||
at.touch(file_3);
|
||||
|
||||
ucmd.arg("----presume-input-tty").arg(file_3).succeeds();
|
||||
|
||||
assert!(!at.file_exists(file_3));
|
||||
}
|
||||
|
|
|
@ -358,6 +358,36 @@ fn test_positive_lines() {
|
|||
.stdout_is("c\nd\ne\n");
|
||||
}
|
||||
|
||||
/// Test for reading all but the first NUM lines: `tail -3`.
|
||||
#[test]
|
||||
fn test_obsolete_syntax_positive_lines() {
|
||||
new_ucmd!()
|
||||
.args(&["-3"])
|
||||
.pipe_in("a\nb\nc\nd\ne\n")
|
||||
.succeeds()
|
||||
.stdout_is("c\nd\ne\n");
|
||||
}
|
||||
|
||||
/// Test for reading all but the first NUM lines: `tail -n -10`.
|
||||
#[test]
|
||||
fn test_small_file() {
|
||||
new_ucmd!()
|
||||
.args(&["-n -10"])
|
||||
.pipe_in("a\nb\nc\nd\ne\n")
|
||||
.succeeds()
|
||||
.stdout_is("a\nb\nc\nd\ne\n");
|
||||
}
|
||||
|
||||
/// Test for reading all but the first NUM lines: `tail -10`.
|
||||
#[test]
|
||||
fn test_obsolete_syntax_small_file() {
|
||||
new_ucmd!()
|
||||
.args(&["-10"])
|
||||
.pipe_in("a\nb\nc\nd\ne\n")
|
||||
.succeeds()
|
||||
.stdout_is("a\nb\nc\nd\ne\n");
|
||||
}
|
||||
|
||||
/// Test for reading all lines, specified by `tail -n +0`.
|
||||
#[test]
|
||||
fn test_positive_zero_lines() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue