tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / misc / split-a
1 #!/bin/sh
2 # Show that split -a works.
3
4 # Copyright (C) 2002-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   split --version
22 fi
23
24 . $srcdir/test-lib.sh
25
26 a_z='a b c d e f g h i j k l m n o p q r s t u v w x y z'
27
28 # Generate a 27-byte file
29 printf %s $a_z 0 |tr -d ' ' > in || framework_failure
30
31 files=
32 for i in $a_z; do
33   files="${files}xa$i "
34 done
35 files="${files}xba"
36
37 for f in $files; do
38   printf 'creating file `%s'\''\n' $f
39 done > exp || framework_failure
40
41 echo split: output file suffixes exhausted \
42   > exp-too-short || framework_failure
43
44
45 # This should fail.
46 split -b 1 -a 1 in 2> err && fail=1
47 test -f xa || fail=1
48 test -f xz || fail=1
49 test -f xaa && fail=1
50 test -f xaz && fail=1
51 rm -f x*
52 compare err exp-too-short || fail=1
53
54 # With a longer suffix, it must succeed.
55 split --verbose -b 1 -a 2 in > err || fail=1
56 compare err exp || fail=1
57
58 # Ensure that xbb is *not* created.
59 test -f xbb && fail=1
60
61 # Ensure that the 27 others files *were* created, and with expected contents.
62 n=1
63 for f in $files; do
64   expected_byte=$(cut -b $n in)
65   b=$(cat $f) || fail=1
66   test "$b" = "$expected_byte" || fail=1
67   n=$(expr $n + 1)
68 done
69
70 Exit $fail