1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 21:47:46 +00:00

Merge branch 'uutils:master' into master

This commit is contained in:
backwaterred 2021-07-06 15:59:03 -07:00 committed by GitHub
commit 96f93488ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 954 additions and 197 deletions

View file

@ -292,6 +292,77 @@ fn _du_dereference(s: &str) {
}
}
#[test]
fn test_du_inodes_basic() {
let scene = TestScenario::new(util_name!());
let result = scene.ucmd().arg("--inodes").succeeds();
#[cfg(target_os = "linux")]
{
let result_reference = scene.cmd("du").arg("--inodes").run();
assert_eq!(result.stdout_str(), result_reference.stdout_str());
}
#[cfg(not(target_os = "linux"))]
_du_inodes_basic(result.stdout_str());
}
#[cfg(target_os = "windows")]
fn _du_inodes_basic(s: &str) {
assert_eq!(
s,
"2\t.\\subdir\\deeper\\deeper_dir
4\t.\\subdir\\deeper
3\t.\\subdir\\links
8\t.\\subdir
11\t.
"
);
}
#[cfg(not(target_os = "windows"))]
fn _du_inodes_basic(s: &str) {
assert_eq!(
s,
"2\t./subdir/deeper/deeper_dir
4\t./subdir/deeper
3\t./subdir/links
8\t./subdir
11\t.
"
);
}
#[test]
fn test_du_inodes() {
let scene = TestScenario::new(util_name!());
scene
.ucmd()
.arg("--summarize")
.arg("--inodes")
.succeeds()
.stdout_only("11\t.\n");
let result = scene
.ucmd()
.arg("--separate-dirs")
.arg("--inodes")
.succeeds();
#[cfg(target_os = "windows")]
result.stdout_contains("3\t.\\subdir\\links\n");
#[cfg(not(target_os = "windows"))]
result.stdout_contains("3\t./subdir/links\n");
result.stdout_contains("3\t.\n");
#[cfg(target_os = "linux")]
{
let result_reference = scene.cmd("du").arg("--separate-dirs").arg("--inodes").run();
assert_eq!(result.stdout_str(), result_reference.stdout_str());
}
}
#[test]
fn test_du_h_flag_empty_file() {
new_ucmd!()
@ -419,3 +490,96 @@ fn test_du_threshold() {
.stdout_does_not_contain("links")
.stdout_contains("deeper_dir");
}
#[test]
fn test_du_apparent_size() {
let scene = TestScenario::new(util_name!());
let result = scene.ucmd().arg("--apparent-size").succeeds();
#[cfg(target_os = "linux")]
{
let result_reference = scene.cmd("du").arg("--apparent-size").run();
assert_eq!(result.stdout_str(), result_reference.stdout_str());
}
#[cfg(not(target_os = "linux"))]
_du_apparent_size(result.stdout_str());
}
#[cfg(target_os = "windows")]
fn _du_apparent_size(s: &str) {
assert_eq!(
s,
"1\t.\\subdir\\deeper\\deeper_dir
1\t.\\subdir\\deeper
6\t.\\subdir\\links
6\t.\\subdir
6\t.
"
);
}
#[cfg(target_vendor = "apple")]
fn _du_apparent_size(s: &str) {
assert_eq!(
s,
"1\t./subdir/deeper/deeper_dir
1\t./subdir/deeper
6\t./subdir/links
6\t./subdir
6\t.
"
);
}
#[cfg(target_os = "freebsd")]
fn _du_apparent_size(s: &str) {
assert_eq!(
s,
"1\t./subdir/deeper/deeper_dir
2\t./subdir/deeper
6\t./subdir/links
8\t./subdir
8\t.
"
);
}
#[cfg(all(
not(target_vendor = "apple"),
not(target_os = "windows"),
not(target_os = "freebsd")
))]
fn _du_apparent_size(s: &str) {
assert_eq!(
s,
"5\t./subdir/deeper/deeper_dir
9\t./subdir/deeper
10\t./subdir/links
22\t./subdir
26\t.
"
);
}
#[test]
fn test_du_bytes() {
let scene = TestScenario::new(util_name!());
let result = scene.ucmd().arg("--bytes").succeeds();
#[cfg(target_os = "linux")]
{
let result_reference = scene.cmd("du").arg("--bytes").run();
assert_eq!(result.stdout_str(), result_reference.stdout_str());
}
#[cfg(target_os = "windows")]
result.stdout_contains("5145\t.\\subdir\n");
#[cfg(target_vendor = "apple")]
result.stdout_contains("5625\t./subdir\n");
#[cfg(target_os = "freebsd")]
result.stdout_contains("7193\t./subdir\n");
#[cfg(all(
not(target_vendor = "apple"),
not(target_os = "windows"),
not(target_os = "freebsd")
))]
result.stdout_contains("21529\t./subdir\n");
}

View file

@ -250,6 +250,28 @@ hello
);
}
#[test]
fn test_bad_utf8() {
let bytes: &[u8] = b"\xfc\x80\x80\x80\x80\xaf";
new_ucmd!()
.args(&["-c", "6"])
.pipe_in(bytes)
.succeeds()
.stdout_is_bytes(bytes);
}
#[test]
fn test_bad_utf8_lines() {
let input: &[u8] =
b"\xfc\x80\x80\x80\x80\xaf\nb\xfc\x80\x80\x80\x80\xaf\nb\xfc\x80\x80\x80\x80\xaf";
let output = b"\xfc\x80\x80\x80\x80\xaf\nb\xfc\x80\x80\x80\x80\xaf\n";
new_ucmd!()
.args(&["-n", "2"])
.pipe_in(input)
.succeeds()
.stdout_is_bytes(output);
}
#[test]
fn test_head_invalid_num() {
new_ucmd!()

View file

@ -696,3 +696,388 @@ fn test_install_dir() {
assert!(at.file_exists(&format!("{}/{}", dir, file1)));
assert!(at.file_exists(&format!("{}/{}", dir, file2)));
}
//
// test backup functionality
#[test]
fn test_install_backup_short_no_args_files() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_simple_backup_file_a";
let file_b = "test_install_simple_backup_file_b";
at.touch(file_a);
at.touch(file_b);
scene
.ucmd()
.arg("-b")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(at.file_exists(&format!("{}~", file_b)));
}
#[test]
fn test_install_backup_short_no_args_file_to_dir() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file = "test_install_simple_backup_file_a";
let dest_dir = "test_install_dest/";
let expect = format!("{}{}", dest_dir, file);
at.touch(file);
at.mkdir(dest_dir);
at.touch(&expect);
scene
.ucmd()
.arg("-b")
.arg(file)
.arg(dest_dir)
.succeeds()
.no_stderr();
assert!(at.file_exists(file));
assert!(at.file_exists(&expect));
assert!(at.file_exists(&format!("{}~", expect)));
}
// Long --backup option is tested separately as it requires a slightly different
// handling than '-b' does.
#[test]
fn test_install_backup_long_no_args_files() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_simple_backup_file_a";
let file_b = "test_install_simple_backup_file_b";
at.touch(file_a);
at.touch(file_b);
scene
.ucmd()
.arg("--backup")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(at.file_exists(&format!("{}~", file_b)));
}
#[test]
fn test_install_backup_long_no_args_file_to_dir() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file = "test_install_simple_backup_file_a";
let dest_dir = "test_install_dest/";
let expect = format!("{}{}", dest_dir, file);
at.touch(file);
at.mkdir(dest_dir);
at.touch(&expect);
scene
.ucmd()
.arg("--backup")
.arg(file)
.arg(dest_dir)
.succeeds()
.no_stderr();
assert!(at.file_exists(file));
assert!(at.file_exists(&expect));
assert!(at.file_exists(&format!("{}~", expect)));
}
#[test]
fn test_install_backup_short_custom_suffix() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_backup_custom_suffix_file_a";
let file_b = "test_install_backup_custom_suffix_file_b";
let suffix = "super-suffix-of-the-century";
at.touch(file_a);
at.touch(file_b);
scene
.ucmd()
.arg("-b")
.arg(format!("--suffix={}", suffix))
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(at.file_exists(&format!("{}{}", file_b, suffix)));
}
#[test]
fn test_install_backup_custom_suffix_via_env() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_backup_custom_suffix_file_a";
let file_b = "test_install_backup_custom_suffix_file_b";
let suffix = "super-suffix-of-the-century";
at.touch(file_a);
at.touch(file_b);
scene
.ucmd()
.arg("-b")
.env("SIMPLE_BACKUP_SUFFIX", suffix)
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(at.file_exists(&format!("{}{}", file_b, suffix)));
}
#[test]
fn test_install_backup_numbered_with_t() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_backup_numbering_file_a";
let file_b = "test_install_backup_numbering_file_b";
at.touch(file_a);
at.touch(file_b);
scene
.ucmd()
.arg("--backup=t")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(at.file_exists(&format!("{}.~1~", file_b)));
}
#[test]
fn test_install_backup_numbered_with_numbered() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_backup_numbering_file_a";
let file_b = "test_install_backup_numbering_file_b";
at.touch(file_a);
at.touch(file_b);
scene
.ucmd()
.arg("--backup=numbered")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(at.file_exists(&format!("{}.~1~", file_b)));
}
#[test]
fn test_install_backup_existing() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_backup_numbering_file_a";
let file_b = "test_install_backup_numbering_file_b";
at.touch(file_a);
at.touch(file_b);
scene
.ucmd()
.arg("--backup=existing")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(at.file_exists(&format!("{}~", file_b)));
}
#[test]
fn test_install_backup_nil() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_backup_numbering_file_a";
let file_b = "test_install_backup_numbering_file_b";
at.touch(file_a);
at.touch(file_b);
scene
.ucmd()
.arg("--backup=nil")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(at.file_exists(&format!("{}~", file_b)));
}
#[test]
fn test_install_backup_numbered_if_existing_backup_existing() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_backup_numbering_file_a";
let file_b = "test_install_backup_numbering_file_b";
let file_b_backup = "test_install_backup_numbering_file_b.~1~";
at.touch(file_a);
at.touch(file_b);
at.touch(file_b_backup);
scene
.ucmd()
.arg("--backup=existing")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(at.file_exists(file_b_backup));
assert!(at.file_exists(&*format!("{}.~2~", file_b)));
}
#[test]
fn test_install_backup_numbered_if_existing_backup_nil() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_backup_numbering_file_a";
let file_b = "test_install_backup_numbering_file_b";
let file_b_backup = "test_install_backup_numbering_file_b.~1~";
at.touch(file_a);
at.touch(file_b);
at.touch(file_b_backup);
scene
.ucmd()
.arg("--backup=nil")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(at.file_exists(file_b_backup));
assert!(at.file_exists(&*format!("{}.~2~", file_b)));
}
#[test]
fn test_install_backup_simple() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_backup_numbering_file_a";
let file_b = "test_install_backup_numbering_file_b";
at.touch(file_a);
at.touch(file_b);
scene
.ucmd()
.arg("--backup=simple")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(at.file_exists(&format!("{}~", file_b)));
}
#[test]
fn test_install_backup_never() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_backup_numbering_file_a";
let file_b = "test_install_backup_numbering_file_b";
at.touch(file_a);
at.touch(file_b);
scene
.ucmd()
.arg("--backup=never")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(at.file_exists(&format!("{}~", file_b)));
}
#[test]
fn test_install_backup_none() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_backup_numbering_file_a";
let file_b = "test_install_backup_numbering_file_b";
at.touch(file_a);
at.touch(file_b);
scene
.ucmd()
.arg("--backup=none")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(!at.file_exists(&format!("{}~", file_b)));
}
#[test]
fn test_install_backup_off() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_a = "test_install_backup_numbering_file_a";
let file_b = "test_install_backup_numbering_file_b";
at.touch(file_a);
at.touch(file_b);
scene
.ucmd()
.arg("--backup=off")
.arg(file_a)
.arg(file_b)
.succeeds()
.no_stderr();
assert!(at.file_exists(file_a));
assert!(at.file_exists(file_b));
assert!(!at.file_exists(&format!("{}~", file_b)));
}

View file

@ -951,3 +951,11 @@ fn test_conflict_check_out() {
);
}
}
#[test]
fn test_key_takes_one_arg() {
new_ucmd!()
.args(&["-k", "2.3", "keys_open_ended.txt"])
.succeeds()
.stdout_is_fixture("keys_open_ended.expected");
}