diff options
Diffstat (limited to 'tests/split')
-rwxr-xr-x | tests/split/additional-suffix.sh | 4 | ||||
-rwxr-xr-x | tests/split/b-chunk.sh | 47 | ||||
-rwxr-xr-x | tests/split/fail.sh | 28 | ||||
-rwxr-xr-x | tests/split/filter.sh | 4 | ||||
-rwxr-xr-x | tests/split/guard-input.sh | 10 | ||||
-rwxr-xr-x | tests/split/l-chunk.sh | 9 | ||||
-rwxr-xr-x | tests/split/line-bytes.sh | 2 | ||||
-rwxr-xr-x | tests/split/lines.sh | 2 | ||||
-rwxr-xr-x | tests/split/numeric.sh | 8 | ||||
-rwxr-xr-x | tests/split/r-chunk.sh | 2 | ||||
-rwxr-xr-x | tests/split/record-sep.sh | 78 | ||||
-rwxr-xr-x | tests/split/suffix-auto-length.sh | 25 | ||||
-rwxr-xr-x | tests/split/suffix-length.sh | 4 |
13 files changed, 162 insertions, 61 deletions
diff --git a/tests/split/additional-suffix.sh b/tests/split/additional-suffix.sh index 7a4d2d7b..79a3f972 100755 --- a/tests/split/additional-suffix.sh +++ b/tests/split/additional-suffix.sh @@ -1,7 +1,7 @@ #!/bin/sh # show that 'split --additional-suffix=SUFFIX' works. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 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 @@ -39,6 +39,6 @@ compare exp-2 xab.txt || fail=1 compare exp-3 xac.txt || fail=1 # Additional suffix must not contain slash -split --lines=2 --additional-suffix=a/b in 2>/dev/null > out && fail=1 +returns_ 1 split --lines=2 --additional-suffix=a/b in 2>/dev/null >out || fail=1 Exit $fail diff --git a/tests/split/b-chunk.sh b/tests/split/b-chunk.sh index 86f95a05..d10fbb9d 100755 --- a/tests/split/b-chunk.sh +++ b/tests/split/b-chunk.sh @@ -1,7 +1,7 @@ #!/bin/sh # test splitting into 3 chunks -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 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 @@ -29,22 +29,33 @@ rm -f x?? split -e -n 10 /dev/null || fail=1 stat x?? 2>/dev/null && fail=1 -printf '1\n2\n3\n4\n5\n' > in || framework_failure_ - -split -n 3 in > out || fail=1 -split -n 1/3 in > b1 || fail=1 -split -n 2/3 in > b2 || fail=1 -split -n 3/3 in > b3 || fail=1 -printf '1\n2' > exp-1 -printf '\n3\n' > exp-2 -printf '4\n5\n' > exp-3 - -compare exp-1 xaa || fail=1 -compare exp-2 xab || fail=1 -compare exp-3 xac || fail=1 -compare exp-1 b1 || fail=1 -compare exp-2 b2 || fail=1 -compare exp-3 b3 || fail=1 -test -f xad && fail=1 +printf '1\n2\n3\n4\n5\n' > input || framework_failure_ + +for file in input /proc/version /sys/kernel/profiling; do + test -f $file || continue + + split -n 3 $file > out || fail=1 + split -n 1/3 $file > b1 || fail=1 + split -n 2/3 $file > b2 || fail=1 + split -n 3/3 $file > b3 || fail=1 + + case $file in + input) + printf '1\n2' > exp-1 + printf '\n3\n' > exp-2 + printf '4\n5\n' > exp-3 + + compare exp-1 xaa || fail=1 + compare exp-2 xab || fail=1 + compare exp-3 xac || fail=1 + ;; + esac + + compare xaa b1 || fail=1 + compare xab b2 || fail=1 + compare xac b3 || fail=1 + cat xaa xab xac | compare - $file || fail=1 + test -f xad && fail=1 +done Exit $fail diff --git a/tests/split/fail.sh b/tests/split/fail.sh index 33694129..e8f7bc3c 100755 --- a/tests/split/fail.sh +++ b/tests/split/fail.sh @@ -1,7 +1,7 @@ #!/bin/sh # split must fail when given length/count of zero. -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2015 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 @@ -24,13 +24,13 @@ touch in || framework_failure_ split -a 0 in 2> /dev/null || fail=1 -split -b 0 in 2> /dev/null && fail=1 -split -C 0 in 2> /dev/null && fail=1 -split -l 0 in 2> /dev/null && fail=1 -split -n 0 in 2> /dev/null && fail=1 -split -n 1/0 in 2> /dev/null && fail=1 -split -n 0/1 in 2> /dev/null && fail=1 -split -n 2/1 in 2> /dev/null && fail=1 +returns_ 1 split -b 0 in 2> /dev/null || fail=1 +returns_ 1 split -C 0 in 2> /dev/null || fail=1 +returns_ 1 split -l 0 in 2> /dev/null || fail=1 +returns_ 1 split -n 0 in 2> /dev/null || fail=1 +returns_ 1 split -n 1/0 in 2> /dev/null || fail=1 +returns_ 1 split -n 0/1 in 2> /dev/null || fail=1 +returns_ 1 split -n 2/1 in 2> /dev/null || fail=1 # Make sure -C doesn't create empty files. rm -f x?? || fail=1 @@ -42,21 +42,21 @@ test -f xac && fail=1 split -1 in 2> /dev/null || fail=1 # Then make sure that -0 evokes a failure. -split -0 in 2> /dev/null && fail=1 +returns_ 1 split -0 in 2> /dev/null || fail=1 split --lines=$UINTMAX_MAX in || fail=1 split --bytes=$OFF_T_MAX in || fail=1 -split --line-bytes=$OFF_T_OFLOW 2> /dev/null in && fail=1 -split --line-bytes=$SIZE_OFLOW 2> /dev/null in && fail=1 +returns_ 1 split --line-bytes=$OFF_T_OFLOW 2> /dev/null in || fail=1 +returns_ 1 split --line-bytes=$SIZE_OFLOW 2> /dev/null in || fail=1 if truncate -s$SIZE_OFLOW large; then # Ensure we can split chunks of a large file on 32 bit hosts split --number=$SIZE_OFLOW/$SIZE_OFLOW large >/dev/null || fail=1 fi split --number=r/$UINTMAX_MAX/$UINTMAX_MAX </dev/null >/dev/null || fail=1 -split --number=r/$UINTMAX_OFLOW </dev/null 2>/dev/null && fail=1 +returns_ 1 split --number=r/$UINTMAX_OFLOW </dev/null 2>/dev/null || fail=1 # Make sure that a huge obsolete option evokes the right failure. -split -99999999999999999991 2> out && fail=1 +split -99999999999999999991 2> out # On losing systems (x86 Solaris 5.9 c89), we get a message like this: # split: line count option -9999999999... is too large @@ -75,7 +75,7 @@ compare exp out || fail=1 # (the current directory in this case) if ! cat . >/dev/null; then # can't read() directories - split . && fail=1 + returns_ 1 split . || fail=1 fi Exit $fail diff --git a/tests/split/filter.sh b/tests/split/filter.sh index fed8c7a4..55610e41 100755 --- a/tests/split/filter.sh +++ b/tests/split/filter.sh @@ -1,7 +1,7 @@ #!/bin/sh # Exercise split's new --filter option. -# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# Copyright (C) 2011-2015 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 @@ -44,7 +44,7 @@ split -e -n 10 --filter='xz > $FILE.xz' /dev/null || fail=1 stat x?? 2>/dev/null && fail=1 # Ensure this invalid combination is flagged -split -n 1/2 --filter='true' /dev/null 2>/dev/null && fail=1 +returns_ 1 split -n 1/2 --filter='true' /dev/null 2>&1 || fail=1 # Ensure SIGPIPEs sent by the children don't propagate back # where they would result in a non zero exit from split. diff --git a/tests/split/guard-input.sh b/tests/split/guard-input.sh index 56b3158b..1213ab04 100755 --- a/tests/split/guard-input.sh +++ b/tests/split/guard-input.sh @@ -1,7 +1,7 @@ #!/bin/sh # ensure split doesn't overwrite input with output. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 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 @@ -23,10 +23,10 @@ seq 10 | tee exp-1 > xaa ln -s xaa in2 ln xaa in3 -split -C 6 xaa && fail=1 -split -C 6 in2 && fail=1 -split -C 6 in3 && fail=1 -split -C 6 - < xaa && fail=1 +returns_ 1 split -C 6 xaa || fail=1 +returns_ 1 split -C 6 in2 || fail=1 +returns_ 1 split -C 6 in3 || fail=1 +returns_ 1 split -C 6 - < xaa || fail=1 compare exp-1 xaa || fail=1 diff --git a/tests/split/l-chunk.sh b/tests/split/l-chunk.sh index 792c5569..c97b3b56 100755 --- a/tests/split/l-chunk.sh +++ b/tests/split/l-chunk.sh @@ -1,7 +1,7 @@ #!/bin/sh # test splitting into newline delineated chunks (-n l/...) -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 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 @@ -20,7 +20,7 @@ print_ver_ split # invalid number of chunks -echo 'split: 1o: invalid number of chunks' > exp +echo "split: invalid number of chunks: '1o'" > exp split -n l/1o 2>err && fail=1 compare exp err || fail=1 @@ -53,8 +53,9 @@ lines=\ printf "%s" "$lines" | tr '~' '\n' > in || framework_failure_ -echo 'split: 16: invalid chunk number' > exp -split -n l/16/15 in 2>err && fail=1 +echo "split: invalid chunk number: '16'" > exp +split -n l/16/15 in 2>err.t && fail=1 +sed "s/': .*/'/" < err.t > err || framework_failure_ compare exp err || fail=1 printf '%s' "\ diff --git a/tests/split/line-bytes.sh b/tests/split/line-bytes.sh index 5f6f505b..6e2f1376 100755 --- a/tests/split/line-bytes.sh +++ b/tests/split/line-bytes.sh @@ -1,7 +1,7 @@ #!/bin/sh # test -C, --lines-bytes -# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# Copyright (C) 2013-2015 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 diff --git a/tests/split/lines.sh b/tests/split/lines.sh index 09dc8c77..5363eb4d 100755 --- a/tests/split/lines.sh +++ b/tests/split/lines.sh @@ -1,7 +1,7 @@ #!/bin/sh # show that 'split --lines=2' works. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 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 diff --git a/tests/split/numeric.sh b/tests/split/numeric.sh index 6467cb7f..9c4e1c55 100755 --- a/tests/split/numeric.sh +++ b/tests/split/numeric.sh @@ -1,7 +1,7 @@ #!/bin/sh # Show that split --numeric-suffixes[=from] works. -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 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 @@ -56,10 +56,10 @@ compare exp-3 x03 || fail=1 # Check that split failed when suffix length is not large enough for # the numerical suffix start value -split -a 3 --numeric-suffixes=1000 in 2> /dev/null && fail=1 +returns_ 1 split -a 3 --numeric-suffixes=1000 in 2>/dev/null || fail=1 # check invalid --numeric-suffixes start values are flagged -split --numeric-suffixes=-1 in 2> /dev/null && fail=1 -split --numeric-suffixes=one in 2> /dev/null && fail=1 +returns_ 1 split --numeric-suffixes=-1 in 2> /dev/null || fail=1 +returns_ 1 split --numeric-suffixes=one in 2> /dev/null || fail=1 Exit $fail diff --git a/tests/split/r-chunk.sh b/tests/split/r-chunk.sh index 8a5f221e..b03defb4 100755 --- a/tests/split/r-chunk.sh +++ b/tests/split/r-chunk.sh @@ -1,7 +1,7 @@ #!/bin/sh # test splitting into round-robin chunks -# Copyright (C) 2010-2014 Free Software Foundation, Inc. +# Copyright (C) 2010-2015 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 diff --git a/tests/split/record-sep.sh b/tests/split/record-sep.sh new file mode 100755 index 00000000..69eb27fa --- /dev/null +++ b/tests/split/record-sep.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# test split with custom record separators + +# Copyright (C) 2015 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 diff --git a/tests/split/suffix-auto-length.sh b/tests/split/suffix-auto-length.sh index 40d95af9..6ef221a1 100755 --- a/tests/split/suffix-auto-length.sh +++ b/tests/split/suffix-auto-length.sh @@ -1,7 +1,7 @@ #!/bin/sh -# Test the suffix auto widening functionality +# Test the suffix auto width functionality -# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# Copyright (C) 2012-2015 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 @@ -20,14 +20,14 @@ print_ver_ split -# ensure this feature is off when start number specified -truncate -s12 file.in -split file.in -b1 --numeric=89 && fail=1 +# ensure auto widening is off when start number specified +truncate -s12 file.in || framework_failure_ +returns_ 1 split file.in -b1 --numeric=89 || fail=1 test "$(ls -1 x* | wc -l)" = 11 || fail=1 rm -f x* -# ensure this feature works when no start num specified -truncate -s91 file.in +# ensure auto widening works when no start num specified +truncate -s91 file.in || framework_failure_ for prefix in 'x' 'xx' ''; do for add_suffix in '.txt' ''; do split file.in "$prefix" -b1 --numeric --additional-suffix="$add_suffix" \ @@ -39,4 +39,15 @@ for prefix in 'x' 'xx' ''; do done done +# ensure auto width with --number and start num < number of files +# That's the single run use case which is valid to adjust suffix len +truncate -s100 file.in || framework_failure_ +split --numeric-suffixes=1 --number=r/100 file.in || fail=1 +rm -f x* + +# ensure no auto width with --number and start num >= number of files +# That's the multi run use case which is invalid to adjust suffix len +# as that would result in an incorrect order for the total output file set +returns_ 1 split --numeric-suffixes=100 --number=r/100 file.in || fail=1 + Exit $fail diff --git a/tests/split/suffix-length.sh b/tests/split/suffix-length.sh index af5e95ee..0be3e9bc 100755 --- a/tests/split/suffix-length.sh +++ b/tests/split/suffix-length.sh @@ -1,7 +1,7 @@ #!/bin/sh # Show that split -a works. -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2015 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 @@ -70,7 +70,7 @@ split -a2 -C1000 < /dev/null || fail=1 # Ensure that -a fails early with a -n that is too large rm -f x* -split -a2 -n1000 < /dev/null && fail=1 +returns_ 1 split -a2 -n1000 < /dev/null || fail=1 test -f xaa && fail=1 Exit $fail |