tests: provide more info on DEBUG=yes
[coreutils.git] / tests / split / l-chunk.sh
blobbc9ad122ccf52f46f4052497ae0673bb6dbac0a5
1 #!/bin/sh
2 # test splitting into newline delineated chunks (-n l/...)
4 # Copyright (C) 2010-2023 Free Software Foundation, Inc.
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.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ split
22 # invalid number of chunks
23 echo "split: invalid number of chunks: '1o'" > exp
24 returns_ 1 split -n l/1o 2>err || fail=1
25 compare exp err || fail=1
27 rm -f x* || fail=1
28 : | split -n l/1 || fail=1
29 compare /dev/null xaa || fail=1
30 test ! -f xab || fail=1
32 # N can be greater than the file size
33 # in which case no data is extracted, or empty files are written
34 split -n l/10 /dev/null || fail=1
35 test "$(stat -c %s x* | uniq -c | sed 's/^ *//; s/ /x/')" = "10x0" || fail=1
36 rm x??
38 # 'split' should reject any attempt to create an infinitely
39 # long output file.
40 # This test is very expensive as it runs out of /tmp space.
41 if test "${RUN_VERY_EXPENSIVE_TESTS+set}" = set; then
42 returns_ 1 split -n l/2 /dev/zero || fail=1
43 rm x??
45 # Repeat the above, but with 1/2, not l/2:
46 returns_ 1 split -n 1/2 /dev/zero || fail=1
47 rm x??
50 # Ensure --elide-empty-files is honored
51 split -e -n l/10 /dev/null || fail=1
52 returns_ 1 stat x?? 2>/dev/null || fail=1
54 # 80 bytes. ~ transformed to \n below
55 lines=\
56 12345~1~12345~1~12345~1~12345~1~12345~~~12345~1~12345~1~12345~1~12345~1~12345~1~
58 printf "%s" "$lines" | tr '~' '\n' > in || framework_failure_
60 echo "split: invalid chunk number: '16'" > exp
61 returns_ 1 split -n l/16/15 in 2>err.t || fail=1
62 sed "s/': .*/'/" < err.t > err || framework_failure_
63 compare exp err || fail=1
65 printf '%s' "\
66 14 16 16 08 16 10
67 14 08 08 10 14 08 08 10
68 08 06 08 08 08 08 08 02 06 08 08 02
69 06 08 08 02 06 08 02 06 08 02 06 08 00 08 02
70 06 02 06 02 06 02 06 02 06 02 06 02 06 02 06 00 08 00 02 06 00 02
71 " > exp || framework_failure_
73 sed 's/00 *//g' exp > exp.elide_empty || framework_failure_
75 test "$DEBUG" && test "$VERBOSE" && set +x
76 for ELIDE_EMPTY in '' '-e'; do
77 for IO_BLKSIZE in 1 2 5 10 80 100; do
78 > out
79 test "$DEBUG" && printf "\n---io-blk-size=$IO_BLKSIZE $ELIDE_EMPTY\n"
80 for N in 6 8 12 15 22; do
81 rm -f x*
83 if test -z "$ELIDE_EMPTY"; then
84 split ---io-blksize=$IO_BLKSIZE -n l/2/$N in > chunk.k
85 returns_ 1 stat x* 2>/dev/null || fail=1
88 split ---io-blksize=$IO_BLKSIZE $ELIDE_EMPTY -n l/$N in
89 echo $(stat -c "%02s" x*) >> out
91 if test -z "$ELIDE_EMPTY"; then
92 compare chunk.k xab || fail=1
95 if test "$DEBUG"; then
96 # Output partition pattern
97 size=$(printf "%s" "$lines" | wc -c)
98 chunk_size=$(($size/$N))
99 end_size=$(($chunk_size + ($size % $N)))
101 yes "$(printf %${chunk_size}s ])" | head -n$(($N-1))
102 printf %${end_size}s ]
103 } | tr -d '\n' | sed "s/\\(^.\\{1,$size\\}\\).*/\\1/"
104 echo
106 # Output pattern generated for comparison
107 for s in $(stat -c "%s" x*); do
108 #s=0 transitions are not shown
109 test "$m" = "_" && m=- || m=_
110 printf "%${s}s" '' | tr ' ' $m
111 done
112 echo
114 # Output lines for reference
115 echo "$lines"
117 done
118 test -z "$ELIDE_EMPTY" && EXP=exp || EXP=exp.elide_empty
119 compare out $EXP || fail=1
120 done
121 done
122 test "$DEBUG" && test "$VERBOSE" && set -x
125 # Check extraction of particular chunks
126 split -n l/13/15 in > out &&
127 compare /dev/null out || fail=1
128 printf '1\n12345\n' > exp || framework_failure_
129 split -n l/14/15 in > out &&
130 compare exp out || fail=1
131 printf '1\n' > exp || framework_failure_
132 split -n l/15/15 in > out &&
133 compare exp out || fail=1
135 # test input with no \n at end
136 printf '12\n34\n5' > in
137 printf '5' > exp
138 split -n l/7/7 in > out
139 compare exp out || fail=1
141 Exit $fail