1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

cp: look for specific error messages in tests

This commit is contained in:
Samuel Tardieu 2024-09-08 00:30:47 +02:00 committed by Ben Wiederhake
parent dd9e7ad363
commit af86aee6b8

View file

@ -170,12 +170,17 @@ fn test_cp_multiple_files() {
#[test] #[test]
fn test_cp_multiple_files_with_nonexistent_file() { fn test_cp_multiple_files_with_nonexistent_file() {
#[cfg(windows)]
let error_msg = "The system cannot find the file specified";
#[cfg(not(windows))]
let error_msg = format!("'{TEST_NONEXISTENT_FILE}': No such file or directory");
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
ucmd.arg(TEST_HELLO_WORLD_SOURCE) ucmd.arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_NONEXISTENT_FILE) .arg(TEST_NONEXISTENT_FILE)
.arg(TEST_HOW_ARE_YOU_SOURCE) .arg(TEST_HOW_ARE_YOU_SOURCE)
.arg(TEST_COPY_TO_FOLDER) .arg(TEST_COPY_TO_FOLDER)
.fails(); .fails()
.stderr_contains(error_msg);
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n"); 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"); assert_eq!(at.read(TEST_HOW_ARE_YOU_DEST), "How are you?\n");
@ -183,12 +188,17 @@ fn test_cp_multiple_files_with_nonexistent_file() {
#[test] #[test]
fn test_cp_multiple_files_with_empty_file_name() { fn test_cp_multiple_files_with_empty_file_name() {
#[cfg(windows)]
let error_msg = "The system cannot find the path specified";
#[cfg(not(windows))]
let error_msg = "'': No such file or directory";
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
ucmd.arg(TEST_HELLO_WORLD_SOURCE) ucmd.arg(TEST_HELLO_WORLD_SOURCE)
.arg("") .arg("")
.arg(TEST_HOW_ARE_YOU_SOURCE) .arg(TEST_HOW_ARE_YOU_SOURCE)
.arg(TEST_COPY_TO_FOLDER) .arg(TEST_COPY_TO_FOLDER)
.fails(); .fails()
.stderr_contains(error_msg);
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n"); 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"); assert_eq!(at.read(TEST_HOW_ARE_YOU_DEST), "How are you?\n");