tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / tail-2 / wait
1 #!/bin/sh
2 # Make sure that `tail -f' returns immediately if a file doesn't exist
3 # while `tail -F' waits for it to appear.
4
5 # Copyright (C) 2003, 2006-2009 Free Software Foundation, Inc.
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 if test "$VERBOSE" = yes; then
21   set -x
22   tail --version
23 fi
24
25 . $srcdir/test-lib.sh
26
27 touch here || framework_failure
28 touch k || framework_failure
29 { touch unreadable && chmod a-r unreadable; } || framework_failure
30
31
32 for inotify in ---disable-inotify ''; do
33   timeout 1 tail -s0.1 -f $inotify not_here
34   test $? = 124 && fail=1
35
36   if test ! -r unreadable; then # can't test this when root
37     timeout 1 tail -s0.1 -f $inotify unreadable
38     test $? = 124 && fail=1
39   fi
40
41   timeout 1 tail -s0.1 -f $inotify here 2>tail.err
42   test $? = 124 || fail=1
43
44   # `tail -F' must wait in any case.
45
46   timeout 1 tail -s0.1 -F $inotify here 2>>tail.err
47   test $? = 124 || fail=1
48
49   if test ! -r unreadable; then # can't test this when root
50     timeout 1 tail -s0.1 -F $inotify unreadable
51     test $? = 124 || fail=1
52   fi
53
54   timeout 1 tail -s0.1 -F $inotify not_here
55   test $? = 124 || fail=1
56
57
58   test -s tail.err && fail=1
59   :>tail.err
60
61
62   tail -s.1 --max-unchanged-stats=2 -F $inotify k > tail.out &
63   pid=$!
64   sleep .5
65   mv k l
66   sleep .5
67   touch k
68   mv k l
69   sleep .5
70   echo NO >> l
71   sleep .5
72   kill $pid
73   test -s tail.out && fail=1
74 done
75
76 Exit $fail