2 # test split with custom record separators
4 # Copyright (C) 2015-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
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
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
54 # Test usage edge cases
57 # Should fail: '-t' requires an argument
58 returns_
1 split -t </dev
/null ||
59 { warn_
"-t without argument did not trigger an error" ; fail
=1 ; }
61 # should fail: multi-character separator
62 returns_
1 split -txx </dev
/null ||
63 { warn_
"-txx did not trigger an error" ; fail
=1 ; }
65 # should fail: different separators used
66 returns_
1 split -ta -tb </dev
/null ||
67 { warn_
"-ta -tb did not trigger an error" ; fail
=1 ; }
69 # should fail: different separators used, including default
70 returns_
1 split -t"$NL" -tb </dev
/null ||
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 ||
75 { warn_
"-t: -t: triggered an error" ; fail
=1 ; }