2
# test splitting into newline delineated chunks (-n l/...)
4
# Copyright (C) 2010-2011 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 <http://www.gnu.org/licenses/>.
19
. "${srcdir=.}/init.sh"; path_prepend_ ../src
22
# invalid number of chunks
23
echo 'split: 1o: invalid number of chunks' > exp
24
split -n l/1o 2>err && fail=1
25
compare err exp || fail=1
27
echo "split: \`-': cannot determine file size" > exp
28
echo | split -n l/1 2>err && fail=1
29
compare err exp || fail=1
31
# N can be greater than the file size
32
# in which case no data is extracted, or empty files are written
33
split -n l/10 /dev/null || fail=1
34
test "$(stat -c %s x* | uniq -c | sed 's/^ *//; s/ /x/')" = "10x0" || fail=1
37
# Ensure the correct number of files written
38
# even if there is more data than the reported file size
39
split -n l/2 /dev/zero
40
test "$(stat -c %s x* | wc -l)" = '2' || fail=1
43
# Ensure --elide-empty-files is honored
44
split -e -n l/10 /dev/null || fail=1
45
stat x?? 2>/dev/null && fail=1
47
# 80 bytes. ~ transformed to \n below
49
12345~1~12345~1~12345~1~12345~1~12345~~~12345~1~12345~1~12345~1~12345~1~12345~1~
51
printf "%s" "$lines" | tr '~' '\n' > in || framework_failure_
53
echo 'split: 16: invalid chunk number' > exp
54
split -n l/16/15 in 2>err && fail=1
55
compare err exp || fail=1
59
14 08 08 10 14 08 08 10
60
06 08 08 02 06 08 08 02 06 08 08 10
61
06 08 02 06 08 00 08 02 06 08 02 06 08 00 10
62
06 00 08 00 02 06 00 02 06 00 08 00 01 07 00 02 06 00 08 00 02 16
63
" > exp || framework_failure_
65
sed 's/00 *//g' exp > exp.elide_empty || framework_failure_
68
test "$DEBUGGING" && test "$VERBOSE" && set +x
69
for ELIDE_EMPTY in '' '-e'; do
70
for IO_BLKSIZE in 1 2 5 10 80 100; do
72
test "$DEBUGGING" && printf "\n---io-blk-size=$IO_BLKSIZE $ELIDE_EMPTY\n"
73
for N in 6 8 12 15 22; do
76
if test -z "$ELIDE_EMPTY"; then
77
split ---io-blksize=$IO_BLKSIZE -n l/2/$N in > chunk.k
78
stat x* 2>/dev/null && fail=1
81
split ---io-blksize=$IO_BLKSIZE $ELIDE_EMPTY -n l/$N in
82
echo $(stat -c "%02s" x*) >> out
84
if test -z "$ELIDE_EMPTY"; then
85
compare chunk.k xab || fail=1
88
if test "$DEBUGGING"; then
89
# Output partition pattern
90
size=$(printf "%s" "$lines" | wc -c)
91
chunk_size=$(($size/$N))
92
end_size=$(($chunk_size + ($size % $N)))
94
yes "$(printf %${chunk_size}s ])" | head -n$(($N-1))
95
printf %${end_size}s ]
96
} | tr -d '\n' | sed "s/\\(^.\\{1,$size\\}\\).*/\\1/"
99
# Output pattern generated for comparison
100
for s in $(stat -c "%s" x*); do
101
#s=0 transitions are not shown
102
test "$m" = "_" && m=- || m=_
103
printf "%${s}s" '' | tr ' ' $m
107
# Output lines for reference
111
test -z "$ELIDE_EMPTY" && EXP=exp || EXP=exp.elide_empty
112
compare out $EXP || fail=1
115
test "$DEBUGGING" && test "$VERBOSE" && set -x
118
# Check extraction of particular chunks
120
printf '1\n12345\n' > exp
121
split -n l/13/15 in > out
122
compare out exp || fail=1
125
split -n l/14/15 in > out
126
compare out exp || fail=1
128
printf '1\n12345\n1\n' > exp
129
split -n l/15/15 in > out
130
compare out exp || fail=1
132
# test input with no \n at end
133
printf '12\n34\n5' > in
135
split -n l/7/7 in > out
136
compare out exp || fail=1