summaryrefslogtreecommitdiff
path: root/tests/split/record-sep.sh
blob: 66b403e63869b446af674ef040465de4299a93bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
# test split with custom record separators

# Copyright (C) 2015-2016 Free Software Foundation, Inc.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ split

NL='
'

for sep in "$NL" '\0' ':'; do

  test "$sep" = "$NL" && tr='\n' || tr="$sep"

  for mode in '--lines=2' '--line-bytes=4' '--number=l/3' '--number=r/3'; do

    # Generate in default mode for comparison
    printf '1\n2\n3\n4\n5\n' > in || framework_failure_
    split $mode in || fail=1
    tr '\n' "$tr" < xaa > exp1
    tr '\n' "$tr" < xab > exp2
    tr '\n' "$tr" < xac > exp3

    rm -f x??

    # Generate output with specified --separator
    printf '1\n2\n3\n4\n5\n' | tr '\n' "$tr" > in || framework_failure_
    split $mode -t "$sep" in || fail=1

    compare exp1 xaa || fail=1
    compare exp2 xab || fail=1
    compare exp3 xac || fail=1
    test -f xad && fail=1
  done

done


#
# Test usage edge cases
#

# Should fail: '-t' requires an argument
returns_ 1 split -t </dev/null ||
  { warn_ "-t without argument did not trigger an error" ; fail=1 ; }

# should fail: multi-character separator
returns_ 1 split -txx </dev/null ||
  { warn_ "-txx did not trigger an error" ; fail=1 ; }

# should fail: different separators used
returns_ 1 split -ta -tb </dev/null ||
  { warn_ "-ta -tb did not trigger an error" ; fail=1 ; }

# should fail: different separators used, including default
returns_ 1 split -t"$NL" -tb </dev/null ||
  { warn_ "-t\$NL -tb did not trigger an error" ; fail=1 ; }

# should not fail: same separator used multiple times
split -t: -t: </dev/null ||
  { warn_ "-t: -t: triggered an error" ; fail=1 ; }


Exit $fail