From a93bccb5b93d1fb1adb5e032f95d9c4c25c72155 Mon Sep 17 00:00:00 2001 From: John Shin Date: Thu, 27 Apr 2023 15:35:21 -0700 Subject: [PATCH] mv: add tests for --target --- tests/by-util/test_mv.rs | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 03423410716..3b5aa3ee3d4 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -55,6 +55,63 @@ fn test_mv_move_file_into_dir() { assert!(at.file_exists(format!("{dir}/{file}"))); } +#[test] +fn test_mv_move_file_into_dir_with_target_arg() { + let (at, mut ucmd) = at_and_ucmd!(); + let dir = "test_mv_move_file_into_dir_with_target_arg_dir"; + let file = "test_mv_move_file_into_dir_with_target_arg_file"; + + at.mkdir(dir); + at.touch(file); + + ucmd.arg("--target") + .arg(dir) + .arg(file) + .succeeds() + .no_stderr(); + + assert!(at.file_exists(format!("{dir}/{file}"))) +} + +#[test] +fn test_mv_move_file_into_file_with_target_arg() { + let (at, mut ucmd) = at_and_ucmd!(); + let file1 = "test_mv_move_file_into_file_with_target_arg_file1"; + let file2 = "test_mv_move_file_into_file_with_target_arg_file2"; + + at.touch(file1); + at.touch(file2); + + ucmd.arg("--target") + .arg(file1) + .arg(file2) + .fails() + .stderr_is(format!("mv: target directory '{file1}': Not a directory\n")); + + assert!(at.file_exists(file1)) +} + +#[test] +fn test_mv_move_multiple_files_into_file() { + let (at, mut ucmd) = at_and_ucmd!(); + let file1 = "test_mv_move_multiple_files_into_file1"; + let file2 = "test_mv_move_multiple_files_into_file2"; + let file3 = "test_mv_move_multiple_files_into_file3"; + + at.touch(file1); + at.touch(file2); + at.touch(file3); + + ucmd.arg(file1) + .arg(file2) + .arg(file3) + .fails() + .stderr_is(format!("mv: target '{file3}': Not a directory\n")); + + assert!(at.file_exists(file1)); + assert!(at.file_exists(file2)); +} + #[test] fn test_mv_move_file_between_dirs() { let (at, mut ucmd) = at_and_ucmd!();