79bda949b027882c4372253e7bade183e58310b5
[platform/upstream/coreutils.git] / tests / misc / split-fail
1 #!/bin/sh
2 # split must fail when given length/count of zero.
3
4 if test "$VERBOSE" = yes; then
5   set -x
6   split --version
7 fi
8
9 . $srcdir/../lang-default
10
11 pwd=`pwd`
12 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
13 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
14 trap '(exit $?); exit $?' 1 2 13 15
15
16 framework_failure=0
17 mkdir -p $tmp || framework_failure=1
18 cd $tmp || framework_failure=1
19 touch in || framework_failure=1
20
21 if test $framework_failure = 1; then
22   echo "$0: failure in testing framework" 1>&2
23   (exit 1); exit 1
24 fi
25
26 fail=0
27
28 split -a 0 in 2> /dev/null || fail=1
29 split -b 0 in 2> /dev/null && fail=1
30 split -C 0 in 2> /dev/null && fail=1
31 split -l 0 in 2> /dev/null && fail=1
32
33 # Make sure that the obsolete -N notation still works
34 split -1 in 2> /dev/null || fail=1
35
36 # Then make sure that -0 evokes a failure.
37 split -0 in 2> /dev/null && fail=1
38
39 # Ensure that split --lines=N and --bytes=N work for N=2^32,
40 # assuming our host supports integers that wide.
41 if _4gb=`expr 4294967296 + 0 2>/dev/null`; then
42   split --lines=$_4gb in || fail=1
43   split --bytes=$_4gb in || fail=1
44 fi
45
46 # Currently (coreutils-5.0.1) split --line-bytes=M fails
47 # with `invalid number of bytes' for M=2^32 or larger.  Actually,
48 # the limit is SIZE_MAX, which is 2^32 on 32-bit systems.
49 # On 64-bit systems, there's no problem with a count of 2^32,
50 # So disable this test in order to avoid the `failure' on 64-bit systems.
51 #split --line-bytes=$_4gb 2> /dev/null in && fail=1
52
53 # Make sure that a huge obsolete option evokes the right failure.
54 split -99999999999999999991 2> out && fail=1
55
56 # On losing systems (x86 Solaris 5.9 c89), we get a message like this:
57 #   split: line count option -9999999999... is too large
58 # while on most, we get this:
59 #   split: line count option -99999999999999999991... is too large
60 # so map them both to -99*.
61 sed 's/99[19]*/99*/' out > out-t
62 mv -f out-t out
63
64 cat <<\EOF > exp
65 split: line count option -99*... is too large
66 EOF
67 cmp out exp || fail=1
68 test $fail = 1 && diff out exp 2> /dev/null
69
70
71 (exit $fail); exit $fail