d9c5ff9b4ca0576a57b2e068bfc09dcc7a4c497f
[platform/upstream/coreutils.git] / tests / mv / no-target-dir
1 #!/bin/sh
2 # ensure that --no-target-directory (-T) works when the destination is
3 # an empty directory.
4
5 if test "$VERBOSE" = yes; then
6   set -x
7   mv --version
8 fi
9
10 pwd=`pwd`
11 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
12 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
13 trap '(exit $?); exit $?' 1 2 13 15
14
15 framework_failure=0
16 mkdir -p $tmp || framework_failure=1
17 cd $tmp || framework_failure=1
18 mkdir -p d/sub empty src d2/sub e2 || framework_failure=1
19 touch f || framework_failure=1
20
21 if test $framework_failure = 1; then
22   echo "$0: failure in testing framework" 1>&2
23   (exit 1); exit 1
24 fi
25
26 fail=0
27
28 # This should succeed, since both src and dest are directories,
29 # and the dest dir is empty.
30 mv -fT d empty || fail=1
31
32 # Ensure that the source, d, is gone.
33 ls -d d > /dev/null 2>&1 && fail=1
34
35 # Ensure that the dest dir now has a subdirectory.
36 test -d empty/sub || fail=1
37
38
39 # rename must fail, since the dest is non-empty.
40 mv -fT src d2 2> /dev/null && fail=1
41
42 # rename must fail, since the src is not a directory.
43 mv -fT f e2 2> /dev/null && fail=1
44
45 (exit $fail); exit $fail