d6120aed763e64847ec8fe7e2222300cc338d73d
[platform/upstream/coreutils.git] / tests / mv / into-self
1 #! /bin/sh
2 # Demonstrate how mv fails when it tries to move a directory into itself.
3
4 if test "$VERBOSE" = yes; then
5   set -x
6   mv --version
7 fi
8
9 dir=toself-dir
10 file=toself-file
11
12 test_failure=0
13
14 rm -rf $dir $file || test_failure=1
15 mkdir -p $dir/a/b || test_failure=1
16 touch $file || test_failure=1
17
18 if test $test_failure = 1; then
19   echo 'failure in testing framework'
20   exit 1
21 fi
22
23 fail=0
24
25 # Make sure we get English translations.
26 . $srcdir/../lang-default
27
28 # This mv command should fail.
29 mv $dir $file $dir > out 2>&1 && fail=1
30
31 sed \
32    -e "s,mv:,XXX:," \
33    -e "s,$dir,SRC," \
34    -e "s,$dir/$dir,DEST," \
35   out > out2
36
37 cat > exp <<\EOF
38 XXX: cannot move `SRC' to a subdirectory of itself, `DEST'
39 EOF
40
41 cmp out2 exp || fail=1
42
43 # Make sure the file is gone.
44 test -f $file && fail=1
45 # Make sure the directory is *not* moved.
46 test -d $dir || fail=1
47 test -d $dir/$dir && fail=1
48 # Make sure the file has been moved to the right place.
49 test -f $dir/$file || fail=1
50 rm -rf $dir $file out out2 exp
51
52 exit $fail