1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 03:26:18 +00:00

Merge branch 'main' into issue-5766

This commit is contained in:
Sylvestre Ledru 2024-01-06 22:55:54 +01:00 committed by GitHub
commit b309d64e78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 435 additions and 94 deletions

View file

@ -3681,3 +3681,23 @@ fn test_cp_seen_file() {
assert!(at.plus("c").join("f").exists());
assert!(at.plus("c").join("f.~1~").exists());
}
#[test]
fn test_cp_path_ends_with_terminator() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.mkdir("a");
ts.ucmd().arg("-r").arg("-T").arg("a").arg("e/").succeeds();
}
#[test]
fn test_cp_no_such() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("b");
ts.ucmd()
.arg("b")
.arg("no-such/")
.fails()
.stderr_is("cp: 'no-such/' is not a directory\n");
}

View file

@ -2622,6 +2622,70 @@ fn test_ls_quoting_style() {
}
}
#[test]
fn test_ls_quoting_style_env_var_default() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch(at.plus_as_string("foo-1"));
at.touch(at.plus_as_string("bar-2"));
// If no quoting style argument is provided, the QUOTING_STYLE environment variable
// shall be used.
let correct_c = "\"bar-2\"\n\"foo-1\"";
scene
.ucmd()
.env("QUOTING_STYLE", "c")
.succeeds()
.stdout_only(format!("{correct_c}\n"));
}
#[test]
fn test_ls_quoting_style_arg_overrides_env_var() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch(at.plus_as_string("foo-1"));
at.touch(at.plus_as_string("bar-2"));
// The quoting style given by the env variable should be
// overridden by any escape style provided by argument.
for (arg, correct) in [
("--quoting-style=literal", "foo-1"),
("-N", "foo-1"),
("--quoting-style=escape", "foo-1"),
("-b", "foo-1"),
("--quoting-style=shell-escape", "foo-1"),
("--quoting-style=shell-escape-always", "'foo-1'"),
("--quoting-style=shell", "foo-1"),
("--quoting-style=shell-always", "'foo-1'"),
] {
scene
.ucmd()
.env("QUOTING_STYLE", "c")
.arg("--hide-control-chars")
.arg(arg)
.arg("foo-1")
.succeeds()
.stdout_only(format!("{correct}\n"));
}
// Another loop to check for the C quoting style that is used as a default above.
for (arg, correct) in [
("--quoting-style=c", "\"foo-1\""),
("-Q", "\"foo-1\""),
("--quote-name", "\"foo-1\""),
] {
scene
.ucmd()
.env("QUOTING_STYLE", "literal")
.arg("--hide-control-chars")
.arg(arg)
.arg("foo-1")
.succeeds()
.stdout_only(format!("{correct}\n"));
}
}
#[test]
fn test_ls_quoting_and_color() {
let scene = TestScenario::new(util_name!());

View file

@ -1556,6 +1556,19 @@ fn test_mv_dir_into_file_where_both_are_files() {
.stderr_contains("mv: cannot stat 'a/': Not a directory");
}
#[test]
fn test_mv_dir_into_path_slash() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.mkdir("a");
scene.ucmd().arg("a").arg("e/").succeeds();
assert!(at.dir_exists("e"));
at.mkdir("b");
at.mkdir("f");
scene.ucmd().arg("b").arg("f/").succeeds();
assert!(at.dir_exists("f/b"));
}
// Todo:
// $ at.touch a b

View file

@ -786,3 +786,17 @@ fn test_default_g_precision() {
.succeeds()
.stdout_only("000001e+06\n");
}
#[test]
fn test_invalid_format() {
new_ucmd!()
.args(&["-f", "%%g", "1"])
.fails()
.no_stdout()
.stderr_contains("format '%%g' has no % directive");
new_ucmd!()
.args(&["-f", "%g%g", "1"])
.fails()
.no_stdout()
.stderr_contains("format '%g%g' has too many % directives");
}

View file

@ -2,6 +2,9 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore wipesync
use crate::common::util::TestScenario;
#[test]
@ -9,8 +12,82 @@ fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
}
#[test]
fn test_invalid_remove_arg() {
new_ucmd!().arg("--remove=unknown").fails().code_is(1);
}
#[test]
fn test_shred() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_shred";
let file_original_content = "test_shred file content";
at.write(file, file_original_content);
ucmd.arg(file).succeeds();
// File exists
assert!(at.file_exists(file));
// File is obfuscated
assert!(at.read_bytes(file) != file_original_content.as_bytes());
}
#[test]
fn test_shred_remove() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_shred_remove";
at.touch(file);
ucmd.arg("--remove").arg(file).succeeds();
// File was deleted
assert!(!at.file_exists(file));
}
#[test]
fn test_shred_remove_unlink() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_shred_remove_unlink";
at.touch(file);
ucmd.arg("--remove=unlink").arg(file).succeeds();
// File was deleted
assert!(!at.file_exists(file));
}
#[test]
fn test_shred_remove_wipe() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_shred_remove_wipe";
at.touch(file);
ucmd.arg("--remove=wipe").arg(file).succeeds();
// File was deleted
assert!(!at.file_exists(file));
}
#[test]
fn test_shred_remove_wipesync() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_shred_remove_wipesync";
at.touch(file);
ucmd.arg("--remove=wipesync").arg(file).succeeds();
// File was deleted
assert!(!at.file_exists(file));
}
#[test]
fn test_shred_u() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;