Add a test for this fix.
[platform/upstream/coreutils.git] / tests / mv / into-self-2
1 #!/bin/sh
2 # Force mv to use the copying code.
3 # Consider the case where SRC and DEST are on different
4 # partitions and DEST is a symlink to SRC.
5
6 if test "$VERBOSE" = yes; then
7   set -x
8   mv --version
9 fi
10
11 . $srcdir/setup
12
13 if test -z "$other_partition_tmpdir"; then
14   exit 77
15 fi
16
17 file="$other_partition_tmpdir/file"
18 symlink=symlink
19
20 framework_failure=0
21 rm -f $file $symlink || framework_failure=1
22 echo whatever > $file || framework_failure=1
23 ln -s $file $symlink || framework_failure=1
24
25 if test $framework_failure = 1; then
26   echo 'failure in testing framework'
27   exit 1
28 fi
29
30 # Make sure we get English translations.
31 LANGUAGE=C
32 export LANGUAGE
33 LC_ALL=C
34 export LC_ALL
35 LANG=C
36 export LANG
37
38 # This mv command should exit nonzero.
39 mv $symlink $file > out 2>&1 && fail=1
40
41 # And so should this one.
42 mv $file $symlink >> out 2>&1 && fail=1
43
44 sed \
45    -e "s,mv:,XXX:," \
46    -e "s,$file,YYY," \
47    -e "s,$symlink,ZZZ," \
48   out > out2
49
50 cat > exp <<\EOF
51 XXX: `ZZZ' and `YYY' are the same file
52 XXX: `YYY' and `ZZZ' are the same file
53 EOF
54 #'
55
56 cmp out2 exp || fail=1
57
58 rm -fr out out2 exp $file $symlink $other_partition_tmpdir
59
60 exit $fail