split: new -t option to select record separator
[coreutils.git] / tests / split / record-sep.sh
blobf41215a45796bf950142d1658eb5f681aff02c51
1 #!/bin/sh
2 # test split with custom record separators
4 # Copyright (C) 2015 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=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ split
22 NL='
25 for sep in "$NL" '\0' ':'; do
27 test "$sep" = "$NL" && tr='\n' || tr="$sep"
29 for mode in '--lines=2' '--line-bytes=4' '--number=l/3' '--number=r/3'; do
31 # Generate in default mode for comparison
32 printf '1\n2\n3\n4\n5\n' > in || framework_failure_
33 split $mode in || fail=1
34 tr '\n' "$tr" < xaa > exp1
35 tr '\n' "$tr" < xab > exp2
36 tr '\n' "$tr" < xac > exp3
38 rm -f x??
40 # Generate output with specified --separator
41 printf '1\n2\n3\n4\n5\n' | tr '\n' "$tr" > in || framework_failure_
42 split $mode -t "$sep" in || fail=1
44 compare exp1 xaa || fail=1
45 compare exp2 xab || fail=1
46 compare exp3 xac || fail=1
47 test -f xad && fail=1
48 done
50 done
54 # Test usage edge cases
57 # Should fail: '-t' requires an argument
58 { split -t </dev/null >/dev/null 2>/dev/null || test $? -ne 1; } &&
59 { warn_ "-t without argument did not trigger an error" ; fail=1 ; }
61 # should fail: multi-character separator
62 { split -txx </dev/null >/dev/null 2>&1 || test $? -ne 1; } &&
63 { warn_ "-txx did not trigger an error" ; fail=1 ; }
65 # should fail: different separators used
66 { split -ta -tb </dev/null >/dev/null 2>&1 || test $? -ne 1; } &&
67 { warn_ "-ta -tb did not trigger an error" ; fail=1 ; }
69 # should fail: different separators used, including default
70 { split -t"$NL" -tb </dev/null >/dev/null 2>&1 || test $? -ne 1; } &&
71 { warn_ "-t\$NL -tb did not trigger an error" ; fail=1 ; }
73 # should not fail: same separator used multiple times
74 split -t: -t: </dev/null >/dev/null 2>&1 ||
75 { warn_ "-t: -t: triggered an error" ; fail=1 ; }
78 Exit $fail