ls: tune is_colored
[coreutils.git] / tests / split / b-chunk.sh
blobd386c86e3502cab62c4ad94cf9fc205c17c45c1d
1 #!/bin/sh
2 # test splitting into 3 chunks
4 # Copyright (C) 2010-2024 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 # N can be greater than the file size
23 # in which case no data is extracted, or empty files are written
24 split -n 10 /dev/null || fail=1
25 test "$(stat -c %s x* | uniq -c | sed 's/^ *//; s/ /x/')" = "10x0" || fail=1
26 rm -f x??
28 printf 'abc' > abc || framework_failure_
29 printf 'a' > exp-a || framework_failure_
30 printf 'b' > exp-b || framework_failure_
31 printf 'c' > exp-c || framework_failure_
32 printf 'ab' > exp-ab || framework_failure_
33 split -n 4 abc || fail=1
34 compare exp-a xaa || fail=1
35 compare exp-b xab || fail=1
36 compare exp-c xac || fail=1
37 compare /dev/null xad || fail=1
38 test ! -f xae || fail=1
39 rm -f x??
40 split -n 2 abc || fail=1
41 compare exp-ab xaa || fail=1
42 compare exp-c xab || fail=1
43 test ! -f xac || fail=1
44 rm -f x??
46 # When extracting K of N where N > file size
47 # no data is extracted, and no files are written
48 split -n 2/3 /dev/null || fail=1
49 returns_ 1 stat x?? 2>/dev/null || fail=1
51 # Ensure --elide-empty-files is honored
52 split -e -n 10 /dev/null || fail=1
53 returns_ 1 stat x?? 2>/dev/null || fail=1
55 printf '1\n2\n3\n4\n5\n' > input || framework_failure_
56 printf '1\n2\n' > exp-1 || framework_failure_
57 printf '3\n4' > exp-2 || framework_failure_
58 printf '\n5\n' > exp-3 || framework_failure_
60 for file in input /proc/version /sys/kernel/profiling; do
61 test -f $file || continue
63 for blksize in 1 2 4096; do
64 if ! test "$file" = 'input'; then
65 # For /proc like files we must be able to read all
66 # into the internal buffer to be able to determine size.
67 test "$blksize" = 4096 || continue
70 split -n 3 ---io-blksize=$blksize $file > out || fail=1
71 split -n 1/3 ---io-blksize=$blksize $file > b1 || fail=1
72 split -n 2/3 ---io-blksize=$blksize $file > b2 || fail=1
73 split -n 3/3 ---io-blksize=$blksize $file > b3 || fail=1
75 case $file in
76 input)
77 compare exp-1 xaa || fail=1
78 compare exp-2 xab || fail=1
79 compare exp-3 xac || fail=1
81 esac
83 compare xaa b1 || fail=1
84 compare xab b2 || fail=1
85 compare xac b3 || fail=1
86 cat xaa xab xac | compare - $file || fail=1
87 test -f xad && fail=1
88 done
89 done
91 Exit $fail