mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-16 19:56:17 +00:00
Fix merge conflict in tests/by-util/test_cp.rs
This commit is contained in:
commit
0379fca260
63 changed files with 1178 additions and 554 deletions
|
@ -385,6 +385,24 @@ fn test_cp_arg_suffix() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_suffix_hyphen_value() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg("-b")
|
||||
.arg("--suffix")
|
||||
.arg("-v")
|
||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||
.succeeds();
|
||||
|
||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||
assert_eq!(
|
||||
at.read(&*format!("{}-v", TEST_HOW_ARE_YOU_SOURCE)),
|
||||
"How are you?\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_custom_backup_suffix_via_env() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
@ -1489,3 +1507,13 @@ fn test_dir_recursive_copy() {
|
|||
.fails()
|
||||
.stderr_contains("cannot copy a directory");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_dir_vs_file() {
|
||||
new_ucmd!()
|
||||
.arg("-R")
|
||||
.arg(TEST_COPY_FROM_FOLDER)
|
||||
.arg(TEST_EXISTING_FILE)
|
||||
.fails()
|
||||
.stderr_only("cp: cannot overwrite non-directory with directory");
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// 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, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, outfile, parseargs, rlen, rmax, rposition, rremain, rsofar, rstat, sigusr, sigval, wlen, wstat abcdefghijklm
|
||||
// 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, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, outfile, parseargs, rlen, rmax, rposition, rremain, rsofar, rstat, sigusr, sigval, wlen, wstat abcdefghijklm abcdefghi
|
||||
|
||||
use crate::common::util::*;
|
||||
|
||||
|
@ -178,6 +178,59 @@ fn test_stdin_stdout_count_w_multiplier() {
|
|||
.success();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_b_multiplier() {
|
||||
// "2b" means 2 * 512, which is 1024.
|
||||
new_ucmd!()
|
||||
.args(&["bs=2b", "count=1"])
|
||||
.pipe_in("a".repeat(1025))
|
||||
.succeeds()
|
||||
.stdout_is("a".repeat(1024));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_x_multiplier() {
|
||||
// "2x3" means 2 * 3, which is 6.
|
||||
new_ucmd!()
|
||||
.args(&["bs=2x3", "count=1"])
|
||||
.pipe_in("abcdefghi")
|
||||
.succeeds()
|
||||
.stdout_is("abcdef");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero_multiplier_warning() {
|
||||
for arg in ["count", "seek", "skip"] {
|
||||
new_ucmd!()
|
||||
.args(&[format!("{}=00x1", arg).as_str(), "status=none"])
|
||||
.pipe_in("")
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.no_stderr();
|
||||
|
||||
new_ucmd!()
|
||||
.args(&[format!("{}=0x1", arg).as_str(), "status=none"])
|
||||
.pipe_in("")
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.stderr_contains("warning: '0x' is a zero multiplier; use '00x' if that is intended");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&[format!("{}=0x0x1", arg).as_str(), "status=none"])
|
||||
.pipe_in("")
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.stderr_is("dd: warning: '0x' is a zero multiplier; use '00x' if that is intended\ndd: warning: '0x' is a zero multiplier; use '00x' if that is intended\n");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&[format!("{}=1x0x1", arg).as_str(), "status=none"])
|
||||
.pipe_in("")
|
||||
.succeeds()
|
||||
.no_stdout()
|
||||
.stderr_contains("warning: '0x' is a zero multiplier; use '00x' if that is intended");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_final_stats_noxfer() {
|
||||
new_ucmd!()
|
||||
|
|
|
@ -179,15 +179,15 @@ fn test_du_hard_link() {
|
|||
|
||||
#[cfg(target_vendor = "apple")]
|
||||
fn _du_hard_link(s: &str) {
|
||||
assert_eq!(s, "12\tsubdir/links\n")
|
||||
assert_eq!(s, "12\tsubdir/links\n");
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
fn _du_hard_link(s: &str) {
|
||||
assert_eq!(s, "8\tsubdir/links\n")
|
||||
assert_eq!(s, "8\tsubdir/links\n");
|
||||
}
|
||||
#[cfg(target_os = "freebsd")]
|
||||
fn _du_hard_link(s: &str) {
|
||||
assert_eq!(s, "16\tsubdir/links\n")
|
||||
assert_eq!(s, "16\tsubdir/links\n");
|
||||
}
|
||||
#[cfg(all(
|
||||
not(target_vendor = "apple"),
|
||||
|
|
|
@ -138,11 +138,19 @@ fn test_escape_short_octal() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_no_octal() {
|
||||
fn test_escape_nul() {
|
||||
new_ucmd!()
|
||||
.args(&["-e", "foo\\0 bar"])
|
||||
.succeeds()
|
||||
.stdout_only("foo\\0 bar\n");
|
||||
.stdout_only("foo\0 bar\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_octal_invalid_digit() {
|
||||
new_ucmd!()
|
||||
.args(&["-e", "foo\\08 bar"])
|
||||
.succeeds()
|
||||
.stdout_only("foo\u{0}8 bar\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -219,7 +219,7 @@ fn test_change_directory() {
|
|||
.args(&pwd)
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
assert_eq!(out.trim(), temporary_path.as_os_str())
|
||||
assert_eq!(out.trim(), temporary_path.as_os_str());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1,6 +1,53 @@
|
|||
use crate::common::util::*;
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
|
||||
use std::fs::OpenOptions;
|
||||
|
||||
#[test]
|
||||
fn test_exit_code() {
|
||||
new_ucmd!().fails();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_version() {
|
||||
new_ucmd!()
|
||||
.args(&["--version"])
|
||||
.fails()
|
||||
.stdout_contains("false");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_help() {
|
||||
new_ucmd!()
|
||||
.args(&["--help"])
|
||||
.fails()
|
||||
.stdout_contains("false");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_short_options() {
|
||||
for option in ["-h", "-V"] {
|
||||
new_ucmd!().arg(option).fails().stdout_is("");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conflict() {
|
||||
new_ucmd!()
|
||||
.args(&["--help", "--version"])
|
||||
.fails()
|
||||
.stdout_is("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
|
||||
fn test_full() {
|
||||
for option in ["--version", "--help"] {
|
||||
let dev_full = OpenOptions::new().write(true).open("/dev/full").unwrap();
|
||||
|
||||
new_ucmd!()
|
||||
.arg(option)
|
||||
.set_stdout(dev_full)
|
||||
.fails()
|
||||
.stderr_contains("No space left on device");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -306,6 +306,10 @@ fn test_head_invalid_num() {
|
|||
));
|
||||
}
|
||||
}
|
||||
new_ucmd!()
|
||||
.args(&["-c", "-³"])
|
||||
.fails()
|
||||
.stderr_is("head: invalid number of bytes: '³'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -815,6 +815,31 @@ fn test_install_backup_short_custom_suffix() {
|
|||
assert!(at.file_exists(&format!("{}{}", file_b, suffix)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_install_backup_short_custom_suffix_hyphen_value() {
|
||||
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 = "-v";
|
||||
|
||||
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!());
|
||||
|
|
|
@ -180,6 +180,33 @@ fn test_symlink_custom_backup_suffix() {
|
|||
assert_eq!(at.resolve_link(backup), file);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_custom_backup_suffix_hyphen_value() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file = "test_symlink_custom_backup_suffix";
|
||||
let link = "test_symlink_custom_backup_suffix_link";
|
||||
let suffix = "-v";
|
||||
|
||||
at.touch(file);
|
||||
at.symlink_file(file, link);
|
||||
assert!(at.file_exists(file));
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
|
||||
let arg = &format!("--suffix={}", suffix);
|
||||
ucmd.args(&["-b", arg, "-s", file, link])
|
||||
.succeeds()
|
||||
.no_stderr();
|
||||
assert!(at.file_exists(file));
|
||||
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
|
||||
let backup = &format!("{}{}", link, suffix);
|
||||
assert!(at.is_symlink(backup));
|
||||
assert_eq!(at.resolve_link(backup), file);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_backup_numbering() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
|
@ -1327,17 +1327,14 @@ fn test_ls_order_time() {
|
|||
// So the order should be 2 3 4 1
|
||||
for arg in &["-u", "--time=atime", "--time=access", "--time=use"] {
|
||||
let result = scene.ucmd().arg("-t").arg(arg).succeeds();
|
||||
let file3_access = at.open("test-3").metadata().unwrap().accessed().unwrap();
|
||||
let file4_access = at.open("test-4").metadata().unwrap().accessed().unwrap();
|
||||
at.open("test-3").metadata().unwrap().accessed().unwrap();
|
||||
at.open("test-4").metadata().unwrap().accessed().unwrap();
|
||||
|
||||
// It seems to be dependent on the platform whether the access time is actually set
|
||||
if file3_access > file4_access {
|
||||
result.stdout_only("test-3\ntest-4\ntest-2\ntest-1\n");
|
||||
} else {
|
||||
// Access time does not seem to be set on Windows and some other
|
||||
// systems so the order is 4 3 2 1
|
||||
result.stdout_only("test-4\ntest-3\ntest-2\ntest-1\n");
|
||||
}
|
||||
#[cfg(unix)]
|
||||
result.stdout_only("test-3\ntest-4\ntest-2\ntest-1\n");
|
||||
#[cfg(windows)]
|
||||
result.stdout_only("test-4\ntest-3\ntest-2\ntest-1\n");
|
||||
}
|
||||
|
||||
// test-2 had the last ctime change when the permissions were set
|
||||
|
|
|
@ -340,6 +340,27 @@ fn test_mv_custom_backup_suffix() {
|
|||
assert!(at.file_exists(&format!("{}{}", file_b, suffix)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_custom_backup_suffix_hyphen_value() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file_a = "test_mv_custom_backup_suffix_file_a";
|
||||
let file_b = "test_mv_custom_backup_suffix_file_b";
|
||||
let suffix = "-v";
|
||||
|
||||
at.touch(file_a);
|
||||
at.touch(file_b);
|
||||
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_mv_custom_backup_suffix_via_env() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
|
@ -429,3 +429,19 @@ fn sub_any_specifiers_after_second_param() {
|
|||
.succeeds()
|
||||
.stdout_only("3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stop_after_additional_escape() {
|
||||
new_ucmd!()
|
||||
.args(&["A%sC\\cD%sF", "B", "E"]) //spell-checker:disable-line
|
||||
.succeeds()
|
||||
.stdout_only("ABC");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sub_float_leading_zeroes() {
|
||||
new_ucmd!()
|
||||
.args(&["%010f", "1"])
|
||||
.succeeds()
|
||||
.stdout_only("001.000000");
|
||||
}
|
||||
|
|
|
@ -1066,10 +1066,13 @@ fn test_separator_null() {
|
|||
#[test]
|
||||
fn test_output_is_input() {
|
||||
let input = "a\nb\nc\n";
|
||||
let (at, mut cmd) = at_and_ucmd!();
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
at.touch("file");
|
||||
at.append("file", input);
|
||||
cmd.args(&["-m", "-u", "-o", "file", "file", "file", "file"])
|
||||
scene
|
||||
.ucmd_keepenv()
|
||||
.args(&["-m", "-u", "-o", "file", "file", "file", "file"])
|
||||
.succeeds();
|
||||
assert_eq!(at.read("file"), input);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,12 @@ fn test_group_num() {
|
|||
assert_eq!("", group_num(""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_group_num_panic_if_invalid_numeric_characters() {
|
||||
group_num("³³³³³");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_generate_tokens {
|
||||
use super::*;
|
||||
|
|
|
@ -491,6 +491,10 @@ fn test_tail_invalid_num() {
|
|||
));
|
||||
}
|
||||
}
|
||||
new_ucmd!()
|
||||
.args(&["-c", "-³"])
|
||||
.fails()
|
||||
.stderr_is("tail: invalid number of bytes: '³'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -530,3 +530,12 @@ fn test_touch_permission_denied_error_msg() {
|
|||
&full_path
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_touch_no_args() {
|
||||
let mut ucmd = new_ucmd!();
|
||||
ucmd.fails().stderr_only(
|
||||
r##"touch: missing file operand
|
||||
Try 'touch --help' for more information."##,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,53 @@
|
|||
use crate::common::util::*;
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
|
||||
use std::fs::OpenOptions;
|
||||
|
||||
#[test]
|
||||
fn test_exit_code() {
|
||||
new_ucmd!().succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_version() {
|
||||
new_ucmd!()
|
||||
.args(&["--version"])
|
||||
.succeeds()
|
||||
.stdout_contains("true");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_help() {
|
||||
new_ucmd!()
|
||||
.args(&["--help"])
|
||||
.succeeds()
|
||||
.stdout_contains("true");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_short_options() {
|
||||
for option in ["-h", "-V"] {
|
||||
new_ucmd!().arg(option).succeeds().stdout_is("");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conflict() {
|
||||
new_ucmd!()
|
||||
.args(&["--help", "--version"])
|
||||
.succeeds()
|
||||
.stdout_is("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
|
||||
fn test_full() {
|
||||
for option in ["--version", "--help"] {
|
||||
let dev_full = OpenOptions::new().write(true).open("/dev/full").unwrap();
|
||||
|
||||
new_ucmd!()
|
||||
.arg(option)
|
||||
.set_stdout(dev_full)
|
||||
.fails()
|
||||
.stderr_contains("No space left on device");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -250,11 +250,24 @@ fn test_size_and_reference() {
|
|||
#[test]
|
||||
fn test_error_filename_only() {
|
||||
// truncate: you must specify either '--size' or '--reference'
|
||||
new_ucmd!().args(&["file"]).fails().stderr_contains(
|
||||
"error: The following required arguments were not provided:
|
||||
new_ucmd!()
|
||||
.args(&["file"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.stderr_contains(
|
||||
"error: The following required arguments were not provided:
|
||||
--reference <RFILE>
|
||||
--size <SIZE>",
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_option() {
|
||||
// truncate: cli parsing error returns 1
|
||||
new_ucmd!()
|
||||
.args(&["--this-arg-does-not-exist"])
|
||||
.fails()
|
||||
.code_is(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue