tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / misc / csplit
1 #!/bin/sh
2 # various csplit tests
3
4 # Copyright (C) 2001-2009 Free Software Foundation, Inc.
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 if test "$VERBOSE" = yes; then
20   set -x
21   csplit --version
22 fi
23
24 . $srcdir/test-lib.sh
25
26
27 # csplit could get a failed assertion to 2.0.17
28 (echo a; echo; echo) > in
29 csplit in '/^$/' 2 > out || fail=1
30 cat <<EOF > exp
31 2
32 0
33 2
34 EOF
35 compare out exp || fail=1
36 rm -f in out exp
37
38 # Ensure that xx02 contains just two newlines.
39 # This would fail due to reading from freed buffer with coreutils-5.0.91.
40 printf '\n\n' > exp
41 cp xx02 out || fail=1
42 compare out exp || fail=1
43 rm -f in out exp
44
45 # csplit would infloop
46 (echo; echo a) > in
47 csplit in '/a/-1' '{*}' > out || fail=1
48 cat <<EOF > exp
49 0
50 3
51 EOF
52 compare out exp || fail=1
53 rm -f in out exp
54
55 # `echo |csplit - 1 1' used to abort.
56 echo > in
57 csplit in 1 1 > out 2> err || fail=1
58 cat <<EOF > exp
59 0
60 0
61 1
62 EOF
63 compare out exp || fail=1
64 cat <<\EOF > experr
65 csplit: warning: line number `1' is the same as preceding line number
66 EOF
67 compare err experr || fail=1
68 rm -f in out exp err experr
69
70 # make sure `csplit FILE 0' fails.
71 echo > in
72 csplit in 0 > out 2> err && fail=1
73 csplit in 2 1 > out 2>> err && fail=1
74 csplit in 3 3 > out 2>> err && fail=1
75 cat <<\EOF > experr
76 csplit: 0: line number must be greater than zero
77 csplit: line number `1' is smaller than preceding line number, 2
78 csplit: warning: line number `3' is the same as preceding line number
79 csplit: `3': line number out of range
80 EOF
81 compare err experr || fail=1
82
83 # Ensure that lines longer than the initial buffer length don't cause
84 # trouble (e.g. reading from freed memory, resulting in corrupt output).
85 # This test failed at least in coreutils-5.2.1 and 5.3.0, and was fixed
86 # in 5.3.1.
87 rm -f in out exp err experr xx??
88 printf 'x%8199s\nx\n%8199s\nx\n' x x > in
89 csplit in '/x\{1\}/' '{*}' > /dev/null || fail=1
90 cat xx?? | compare - in || fail=1
91
92 Exit $fail