1#!/bin/sh 2# test split with custom record separators 3 4# Copyright (C) 2015-2023 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 <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ split 21 22NL=' 23' 24 25for sep in "$NL" '\0' ':'; do 26 27 test "$sep" = "$NL" && tr='\n' || tr="$sep" 28 29 for mode in '--lines=2' '--line-bytes=4' '--number=l/3' '--number=r/3'; do 30 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 37 38 rm -f x?? 39 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 43 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 49 50done 51 52 53# 54# Test usage edge cases 55# 56 57# Should fail: '-t' requires an argument 58returns_ 1 split -t </dev/null || 59 { warn_ "-t without argument did not trigger an error" ; fail=1 ; } 60 61# should fail: multi-character separator 62returns_ 1 split -txx </dev/null || 63 { warn_ "-txx did not trigger an error" ; fail=1 ; } 64 65# should fail: different separators used 66returns_ 1 split -ta -tb </dev/null || 67 { warn_ "-ta -tb did not trigger an error" ; fail=1 ; } 68 69# should fail: different separators used, including default 70returns_ 1 split -t"$NL" -tb </dev/null || 71 { warn_ "-t\$NL -tb did not trigger an error" ; fail=1 ; } 72 73# should not fail: same separator used multiple times 74split -t: -t: </dev/null || 75 { warn_ "-t: -t: triggered an error" ; fail=1 ; } 76 77 78Exit $fail 79