From af86aee6b86a99736ca304ff656d0e4c6d547333 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 8 Sep 2024 00:30:47 +0200 Subject: [PATCH] cp: look for specific error messages in tests --- tests/by-util/test_cp.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 290c49f3b..f0d9b1763 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -170,12 +170,17 @@ fn test_cp_multiple_files() { #[test] 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!(); ucmd.arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_NONEXISTENT_FILE) .arg(TEST_HOW_ARE_YOU_SOURCE) .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_HOW_ARE_YOU_DEST), "How are you?\n"); @@ -183,12 +188,17 @@ fn test_cp_multiple_files_with_nonexistent_file() { #[test] 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!(); ucmd.arg(TEST_HELLO_WORLD_SOURCE) .arg("") .arg(TEST_HOW_ARE_YOU_SOURCE) .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_HOW_ARE_YOU_DEST), "How are you?\n");