While looking at some of the 'ln' backup code, I noticed these tests
seemed a bit outdated. Specifically, the 'sed' invocation to replace
the program name seemed strange. Looking at the git history, it seems
it was written so that CP and MV could be replaced in the environment.
Nowadays, you can just point PATH to the location with a 'cp' command
you want to run.

Also, checking that the files aren't overwritten seemed like a nice
improvement.

-- 8< --

* tests/cp/backup-is-src.sh: Use returns_ 1 to check the return value.
Make sure the contents of the files do not change. Don't use sed to
replace the program name or file names in messages.
* tests/mv/backup-is-src.sh: Likewise.
---
 tests/cp/backup-is-src.sh | 23 ++++++++++++-----------
 tests/mv/backup-is-src.sh | 28 ++++++++++++----------------
 2 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/tests/cp/backup-is-src.sh b/tests/cp/backup-is-src.sh
index 6fc7b45cd..e677690e4 100755
--- a/tests/cp/backup-is-src.sh
+++ b/tests/cp/backup-is-src.sh
@@ -19,18 +19,19 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ cp
 
-echo a > a || framework_failure_
-echo a-tilde > a~ || framework_failure_
-
-# This cp command should exit nonzero.
-cp --b=simple a~ a > out 2>&1 && fail=1
-
-sed "s,cp:,XXX:," out > out2
-
-cat > exp <<\EOF
-XXX: backing up 'a' might destroy source;  'a~' not copied
+echo a >exp-a &&
+echo a-tilde >exp-a-tilde &&
+cp exp-a a &&
+cp exp-a-tilde a~ &&
+cat > exp <<\EOF || framework_failure_
+cp: backing up 'a' might destroy source;  'a~' not copied
 EOF
 
-compare exp out2 || fail=1
+# This cp command should exit nonzero.
+returns_ 1 cp --b=simple a~ a >out 2>err || fail=1
+compare /dev/null out || fail=1
+compare exp err || fail=1
+compare exp-a a || fail=1
+compare exp-a-tilde a~ || fail=1
 
 Exit $fail
diff --git a/tests/mv/backup-is-src.sh b/tests/mv/backup-is-src.sh
index 672dbb8dd..48e5fc2e8 100755
--- a/tests/mv/backup-is-src.sh
+++ b/tests/mv/backup-is-src.sh
@@ -24,23 +24,19 @@ cleanup_() { rm -rf "$other_partition_tmpdir"; }
 a="$other_partition_tmpdir/a"
 a2="$other_partition_tmpdir/a~"
 
-rm -f "$a" "$a2" || framework_failure_
-echo a > "$a" || framework_failure_
-echo a2 > "$a2" || framework_failure_
-
-# This mv command should exit nonzero.
-mv --b=simple "$a2" "$a" > out 2>&1 && fail=1
-
-sed \
-   -e "s,mv:,XXX:," \
-   -e "s,$a,YYY," \
-   -e "s,$a2,ZZZ," \
-  out > out2
-
-cat > exp <<\EOF
-XXX: backing up 'YYY' might destroy source;  'ZZZ' not moved
+echo a >exp-a &&
+echo a2 >exp-a2 &&
+cp exp-a "$a" &&
+cp exp-a2 "$a2" &&
+cat >exp <<EOF || framework_failure_
+mv: backing up '$a' might destroy source;  '$a2' not moved
 EOF
 
-compare exp out2 || fail=1
+# This mv command should exit nonzero.
+returns_ 1 mv --b=simple "$a2" "$a" >out 2>err || fail=1
+compare /dev/null out || fail=1
+compare exp err || fail=1
+compare exp-a "$a" || fail=1
+compare exp-a2 "$a2" || fail=1
 
 Exit $fail
-- 
2.56.1


Reply via email to