0614841ed983141a8a881ca8be743882f1efc485
[platform/upstream/coreutils.git] / tests / split / filter
1 #!/bin/sh
2 # Exercise split's new --filter option.
3
4 # Copyright (C) 2011 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 . "${srcdir=.}/init.sh"; path_prepend_ ../src
20 print_ver_ split
21 xz --version || skip_test_ "xz (better than gzip/bzip2) required"
22
23 for total_n_lines in 5 3000 20000; do
24   seq $total_n_lines > in || framework_failure_
25   for i in 2 51 598; do
26
27     # Don't create too many files/processes.
28     # Starting 10k (or even "only" 1500) processes would take a long time,
29     # and would provide little added benefit.
30     case $i:$total_n_lines in 2:5);; *) continue;; esac
31
32     split -l$i --filter='xz > $FILE.xz' in out- || fail=1
33     xz -dc out-* > out || fail=1
34     compare in out || fail=1
35     rm -f out*
36   done
37   rm -f in
38 done
39
40 # Show how --elide-empty-files works with --filter:
41 # split does not run the command (and effectively elides the file)
42 # only when the output to that command would have been empty.
43 split -e -n 10 --filter='xz > $FILE.xz' /dev/null || fail=1
44 stat x?? 2>/dev/null && fail=1
45
46 # Ensure SIGPIPEs sent by the children don't propagate back
47 # where they would result in a non zero exit from split.
48 yes | head -n200K | split -b1G --filter='head -c1 >/dev/null' || fail=1
49
50 Exit $fail