mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
feature(cp) implement -P/--no-deference
This commit is contained in:
parent
4b4d11b61a
commit
280fafed8a
2 changed files with 74 additions and 8 deletions
|
@ -2,8 +2,15 @@ use crate::common::util::*;
|
|||
#[cfg(not(windows))]
|
||||
use std::fs::set_permissions;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
use std::os::unix::fs;
|
||||
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::fs::symlink_file;
|
||||
|
||||
static TEST_EXISTING_FILE: &str = "existing_file.txt";
|
||||
static TEST_HELLO_WORLD_SOURCE: &str = "hello_world.txt";
|
||||
static TEST_HELLO_WORLD_SOURCE_SYMLINK: &str = "hello_world.txt.link";
|
||||
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";
|
||||
|
@ -328,3 +335,47 @@ fn test_cp_arg_suffix() {
|
|||
"How are you?\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_no_deref() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
let _r = fs::symlink(
|
||||
TEST_HELLO_WORLD_SOURCE,
|
||||
at.subdir.join(TEST_HELLO_WORLD_SOURCE_SYMLINK),
|
||||
);
|
||||
#[cfg(windows)]
|
||||
let _r = symlink_file(
|
||||
TEST_HELLO_WORLD_SOURCE,
|
||||
at.subdir.join(TEST_HELLO_WORLD_SOURCE_SYMLINK),
|
||||
);
|
||||
//using -t option
|
||||
let result = scene
|
||||
.ucmd()
|
||||
.arg("-P")
|
||||
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_HELLO_WORLD_SOURCE_SYMLINK)
|
||||
.arg(TEST_COPY_TO_FOLDER)
|
||||
.run();
|
||||
|
||||
// Check that the exit code represents a successful copy.
|
||||
let exit_success = result.success;
|
||||
assert!(exit_success);
|
||||
let path_to_new_symlink = at
|
||||
.subdir
|
||||
.join(TEST_COPY_TO_FOLDER)
|
||||
.join(TEST_HELLO_WORLD_SOURCE_SYMLINK);
|
||||
assert!(at.is_symlink(
|
||||
&path_to_new_symlink
|
||||
.clone()
|
||||
.into_os_string()
|
||||
.into_string()
|
||||
.unwrap()
|
||||
));
|
||||
// Check the content of the destination file that was copied.
|
||||
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
||||
let path_to_check = path_to_new_symlink.to_str().unwrap();
|
||||
assert_eq!(at.read(&path_to_check), "Hello, World!\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue