ba6f8276cbcc9b30f9e54086eff9b14d2339fd16
[platform/upstream/coreutils.git] / tests / mv / update
1 #!/bin/sh
2 # make sure --update works as advertised
3
4 if test "$VERBOSE" = yes; then
5   set -x
6   cp --version
7   mv --version
8 fi
9
10 . $srcdir/../envvar-check
11 . $srcdir/../lang-default
12
13 pwd=`pwd`
14 tmp=mv-update.$$
15 trap 'status=$?; cd $pwd; rm -rf $tmp && exit $status' 0
16 trap '(exit $?); exit' 1 2 13 15
17
18 framework_failure=0
19 mkdir $tmp || framework_failure=1
20 cd $tmp || framework_failure=1
21 echo old > old || framework_failure=1
22 touch -d yesterday old || framework_failure=1
23 echo new > new || framework_failure=1
24
25 if test $framework_failure = 1; then
26   echo 'failure in testing framework' 1>&2
27   (exit 1); exit 1
28 fi
29
30 fail=0
31
32 for cp_or_mv in cp mv; do
33   # This is a no-op.
34   $cp_or_mv --update old new || fail=1
35   case "`cat new`" in new) ;; *) fail=1 ;; esac
36   case "`cat old`" in old) ;; *) fail=1 ;; esac
37 done
38
39 # This will actually perform the rename.
40 mv --update new old || fail=1
41 test -f new && fail=1
42 case "`cat old`" in new) ;; *) fail=1 ;; esac
43
44 # Restore initial conditions.
45 echo old > old || fail=1
46 touch -d yesterday old || fail=1
47 echo new > new || fail=1
48
49 # This will actually perform the copy.
50 cp --update new old || fail=1
51 case "`cat old`" in new) ;; *) fail=1 ;; esac
52 case "`cat new`" in new) ;; *) fail=1 ;; esac
53
54 (exit $fail); exit $fail