summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2023-03-04 11:41:03 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2023-03-04 14:49:45 -0800
commitfb6fc7f3ce6b0b70a5df7f605e71c4f8541e256b (patch)
tree24bfc3384bd255f4048f3a9c25487d770eb51c99 /tests
parent0d997e18b99e87fa2f2ca96f3611ada87758c020 (diff)
downloadcoreutils-fb6fc7f3ce6b0b70a5df7f605e71c4f8541e256b.tar.gz
split: split more evenly with -n
* src/split.c (bytes_split): New arg REM_BYTES. Use this to split more evenly. All callers changed. (lines_chunk_split, bytes_chunk_extract): Be consistent with new byte_split. * tests/split/b-chunk.sh, tests/split/l-chunk.sh: Test new behavior.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/split/b-chunk.sh24
-rwxr-xr-xtests/split/l-chunk.sh24
2 files changed, 31 insertions, 17 deletions
diff --git a/tests/split/b-chunk.sh b/tests/split/b-chunk.sh
index b3195000f..1e9a6f6e9 100755
--- a/tests/split/b-chunk.sh
+++ b/tests/split/b-chunk.sh
@@ -25,6 +25,24 @@ split -n 10 /dev/null || fail=1
test "$(stat -c %s x* | uniq -c | sed 's/^ *//; s/ /x/')" = "10x0" || fail=1
rm -f x??
+printf 'abc' > abc || framework_failure_
+printf 'a' > exp-a || framework_failure_
+printf 'b' > exp-b || framework_failure_
+printf 'c' > exp-c || framework_failure_
+printf 'ab' > exp-ab || framework_failure_
+split -n 4 abc || fail=1
+compare exp-a xaa || fail=1
+compare exp-b xab || fail=1
+compare exp-c xac || fail=1
+compare /dev/null xad || fail=1
+test ! -f xae || fail=1
+rm -f x??
+split -n 2 abc || fail=1
+compare exp-ab xaa || fail=1
+compare exp-c xab || fail=1
+test ! -f xac || fail=1
+rm -f x??
+
# When extracting K of N where N > file size
# no data is extracted, and no files are written
split -n 2/3 /dev/null || fail=1
@@ -35,9 +53,9 @@ split -e -n 10 /dev/null || fail=1
returns_ 1 stat x?? 2>/dev/null || fail=1
printf '1\n2\n3\n4\n5\n' > input || framework_failure_
-printf '1\n2' > exp-1 || framework_failure_
-printf '\n3\n' > exp-2 || framework_failure_
-printf '4\n5\n' > exp-3 || framework_failure_
+printf '1\n2\n' > exp-1 || framework_failure_
+printf '3\n4' > exp-2 || framework_failure_
+printf '\n5\n' > exp-3 || framework_failure_
for file in input /proc/version /sys/kernel/profiling; do
test -f $file || continue
diff --git a/tests/split/l-chunk.sh b/tests/split/l-chunk.sh
index 73cd729a4..cdb201746 100755
--- a/tests/split/l-chunk.sh
+++ b/tests/split/l-chunk.sh
@@ -59,11 +59,11 @@ sed "s/': .*/'/" < err.t > err || framework_failure_
compare exp err || fail=1
printf '%s' "\
-14 16 09 15 16 10
+14 16 16 08 16 10
14 08 08 10 14 08 08 10
-06 08 08 02 06 08 08 02 06 08 08 10
-06 08 02 06 08 00 08 02 06 08 02 06 08 00 10
-06 00 08 00 02 06 00 02 06 00 08 00 01 07 00 02 06 00 08 00 02 16
+08 06 08 08 08 08 08 02 06 08 08 02
+06 08 08 02 06 08 02 06 08 02 06 08 00 08 02
+06 02 06 02 06 02 06 02 06 02 06 02 06 02 06 00 08 00 02 06 00 02
" > exp || framework_failure_
sed 's/00 *//g' exp > exp.elide_empty || framework_failure_
@@ -120,17 +120,13 @@ test "$DEBUGGING" && test "$VERBOSE" && set -x
# Check extraction of particular chunks
-> out
-printf '1\n12345\n' > exp
-split -n l/13/15 in > out
+split -n l/13/15 in > out &&
+compare /dev/null out || fail=1
+printf '1\n12345\n' > exp || framework_failure_
+split -n l/14/15 in > out &&
compare exp out || fail=1
-> out
-printf '' > exp
-split -n l/14/15 in > out
-compare exp out || fail=1
-> out
-printf '1\n12345\n1\n' > exp
-split -n l/15/15 in > out
+printf '1\n' > exp || framework_failure_
+split -n l/15/15 in > out &&
compare exp out || fail=1
# test input with no \n at end