mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge branch 'master' into expr-regex
This commit is contained in:
commit
1a28a48ca3
100 changed files with 2193 additions and 814 deletions
1
tests/fixtures/cp/existing_file.txt
vendored
Normal file
1
tests/fixtures/cp/existing_file.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
Cogito ergo sum.
|
1
tests/fixtures/cp/how_are_you.txt
vendored
Normal file
1
tests/fixtures/cp/how_are_you.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
How are you?
|
237
tests/test_cp.rs
237
tests/test_cp.rs
|
@ -1,10 +1,17 @@
|
|||
use common::util::*;
|
||||
use std::fs::set_permissions;
|
||||
|
||||
static TEST_HELLO_WORLD_SOURCE: &'static str = "hello_world.txt";
|
||||
static TEST_HELLO_WORLD_DEST: &'static str = "copy_of_hello_world.txt";
|
||||
static TEST_COPY_TO_FOLDER: &'static str = "hello_dir/";
|
||||
static TEST_COPY_TO_FOLDER_FILE: &'static str = "hello_dir/hello_world.txt";
|
||||
static TEST_COPY_FROM_FOLDER_FILE: &'static str = "hello_dir_with_file/hello_world.txt";
|
||||
static TEST_EXISTING_FILE: &str = "existing_file.txt";
|
||||
static TEST_HELLO_WORLD_SOURCE: &str = "hello_world.txt";
|
||||
static TEST_HELLO_WORLD_DEST: &str = "copy_of_hello_world.txt";
|
||||
static TEST_HOW_ARE_YOU_SOURCE: &str = "how_are_you.txt";
|
||||
static TEST_HOW_ARE_YOU_DEST: &str = "hello_dir/how_are_you.txt";
|
||||
static TEST_COPY_TO_FOLDER: &str = "hello_dir/";
|
||||
static TEST_COPY_TO_FOLDER_FILE: &str = "hello_dir/hello_world.txt";
|
||||
static TEST_COPY_FROM_FOLDER: &str = "hello_dir_with_file/";
|
||||
static TEST_COPY_FROM_FOLDER_FILE: &str = "hello_dir_with_file/hello_world.txt";
|
||||
static TEST_COPY_TO_FOLDER_NEW: &str = "hello_dir_new/";
|
||||
static TEST_COPY_TO_FOLDER_NEW_FILE: &str = "hello_dir_new/hello_world.txt";
|
||||
|
||||
#[test]
|
||||
fn test_cp_cp() {
|
||||
|
@ -22,6 +29,73 @@ fn test_cp_cp() {
|
|||
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_cp_duplicate_files() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_COPY_TO_FOLDER)
|
||||
.run();
|
||||
|
||||
assert!(result.success);
|
||||
assert!(result.stderr.contains("specified more than once"));
|
||||
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_cp_multiple_files_target_is_file() {
|
||||
let (_, mut ucmd) = at_and_ucmd!();
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_EXISTING_FILE)
|
||||
.run();
|
||||
|
||||
assert!(!result.success);
|
||||
assert!(result.stderr.contains("not a directory"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_directory_not_recursive() {
|
||||
let (_, mut ucmd) = at_and_ucmd!();
|
||||
let result = ucmd.arg(TEST_COPY_TO_FOLDER)
|
||||
.arg(TEST_HELLO_WORLD_DEST)
|
||||
.run();
|
||||
|
||||
assert!(!result.success);
|
||||
assert!(result.stderr.contains("omitting directory"));
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_cp_multiple_files() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||
.arg(TEST_COPY_TO_FOLDER)
|
||||
.run();
|
||||
|
||||
assert!(result.success);
|
||||
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_DEST), "How are you?\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_recurse() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let result = ucmd
|
||||
.arg("-r")
|
||||
.arg(TEST_COPY_FROM_FOLDER)
|
||||
.arg(TEST_COPY_TO_FOLDER_NEW)
|
||||
.run();
|
||||
|
||||
assert!(result.success);
|
||||
// Check the content of the destination file that was copied.
|
||||
assert_eq!(at.read(TEST_COPY_TO_FOLDER_NEW_FILE), "Hello, World!\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_with_dirs_t() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
@ -56,3 +130,156 @@ fn test_cp_with_dirs() {
|
|||
assert!(result_from_dir.success);
|
||||
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_target_directory() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg("-t")
|
||||
.arg(TEST_COPY_TO_FOLDER)
|
||||
.run();
|
||||
|
||||
assert!(result.success);
|
||||
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_no_target_directory() {
|
||||
let (_, mut ucmd) = at_and_ucmd!();
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg("-v")
|
||||
.arg("-T")
|
||||
.arg(TEST_COPY_TO_FOLDER)
|
||||
.run();
|
||||
|
||||
assert!(!result.success);
|
||||
assert!(result.stderr.contains("cannot overwrite directory"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_interactive() {
|
||||
let (_, mut ucmd) = at_and_ucmd!();
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||
.arg("-i")
|
||||
.pipe_in("N\n")
|
||||
.run();
|
||||
|
||||
assert!(result.success);
|
||||
assert!(result.stderr.contains("Not overwriting"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os="unix")]
|
||||
fn test_cp_arg_link() {
|
||||
use std::os::linux::fs::MetadataExt;
|
||||
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg("--link")
|
||||
.arg(TEST_HELLO_WORLD_DEST)
|
||||
.run();
|
||||
|
||||
assert!(result.success);
|
||||
assert_eq!(at.metadata(TEST_HELLO_WORLD_SOURCE).st_nlink(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_symlink() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg("--symbolic-link")
|
||||
.arg(TEST_HELLO_WORLD_DEST)
|
||||
.run();
|
||||
|
||||
assert!(result.success);
|
||||
assert!(at.is_symlink(TEST_HELLO_WORLD_DEST));
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_no_clobber() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg("--no-clobber")
|
||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||
.run();
|
||||
|
||||
assert!(result.success);
|
||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "How are you?\n");
|
||||
assert!(result.stderr.contains("Not overwriting"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn test_cp_arg_force() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
// create dest without write permissions
|
||||
let mut permissions = at.make_file(TEST_HELLO_WORLD_DEST).metadata().unwrap().permissions();
|
||||
permissions.set_readonly(true);
|
||||
set_permissions(at.plus(TEST_HELLO_WORLD_DEST), permissions).unwrap();
|
||||
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg("--force")
|
||||
.arg(TEST_HELLO_WORLD_DEST)
|
||||
.run();
|
||||
|
||||
println!("{:?}", result.stderr);
|
||||
println!("{:?}", result.stdout);
|
||||
|
||||
assert!(result.success);
|
||||
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
|
||||
}
|
||||
|
||||
/// TODO: write a better test that differentiates --remove-destination
|
||||
/// from --force. Also this test currently doesn't work on
|
||||
/// Windows. This test originally checked file timestamps, which
|
||||
/// proved to be unreliable per target / CI platform
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn test_cp_arg_remove_destination() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
// create dest without write permissions
|
||||
let mut permissions = at.make_file(TEST_HELLO_WORLD_DEST).metadata().unwrap().permissions();
|
||||
permissions.set_readonly(true);
|
||||
set_permissions(at.plus(TEST_HELLO_WORLD_DEST), permissions).unwrap();
|
||||
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg("--remove-destination")
|
||||
.arg(TEST_HELLO_WORLD_DEST)
|
||||
.run();
|
||||
|
||||
assert!(result.success);
|
||||
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_backup() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg("--backup")
|
||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||
.run();
|
||||
|
||||
assert!(result.success);
|
||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||
assert_eq!(at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)), "How are you?\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_suffix() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg("--suffix")
|
||||
.arg(".bak")
|
||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||
.run();
|
||||
|
||||
assert!(result.success);
|
||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||
assert_eq!(at.read(&*format!("{}.bak", TEST_HOW_ARE_YOU_SOURCE)), "How are you?\n");
|
||||
}
|
||||
|
|
|
@ -32,3 +32,28 @@ fn test_delete_complement() {
|
|||
new_ucmd!()
|
||||
.args(&["-d", "-c", "a-z"]).pipe_in("aBcD").run().stdout_is("ac");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_squeeze() {
|
||||
new_ucmd!()
|
||||
.args(&["-s", "a-z"]).pipe_in("aaBBcDcc").run().stdout_is("aBBcDc");
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_squeeze_complement() {
|
||||
new_ucmd!()
|
||||
.args(&["-sc", "a-z"]).pipe_in("aaBBcDcc").run().stdout_is("aaBcDcc");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_delete_and_squeeze() {
|
||||
new_ucmd!()
|
||||
.args(&["-ds", "a-z", "A-Z"]).pipe_in("abBcB").run().stdout_is("B");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_delete_and_squeeze_complement() {
|
||||
new_ucmd!()
|
||||
.args(&["-dsc", "a-z", "A-Z"]).pipe_in("abBcB").run().stdout_is("abc");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue