f6dba8ee31d3e100f88a4dda87fe174af617b529
[platform/upstream/coreutils.git] / tests / touch / fail-diag
1 #!/bin/sh
2 # make sure touch gives reasonable diagnostics
3
4 if test "$VERBOSE" = yes; then
5   set -x
6   touch --version
7 fi
8
9 . $srcdir/../envvar-check
10 . $srcdir/../lang-default
11 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
12
13 pwd=`pwd`
14 tmp=fail-diag.$$
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
22 d1=no-$$
23 dir=/$d1/such-dir
24 # Ensure that $d1 doesn't already exist.
25 ls -d $d1 2> /dev/null && framework_failure=1
26
27 if test $framework_failure = 1; then
28   echo 'failure in testing framework' 1>&2
29   (exit 1); exit 1
30 fi
31
32 fail=0
33
34 touch $dir > out 2>&1 && fail=1
35 cat <<EOF > exp
36 touch: cannot touch \`$dir': No such file or directory
37 EOF
38
39 cmp out exp || fail=1
40 test $fail = 1 && diff out exp 2> /dev/null
41
42 (exit $fail); exit $fail