1#!/bin/sh
2# Test the suffix auto width functionality
3
4# Copyright (C) 2012-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
22
23# ensure auto widening is off when start number specified
24truncate -s12 file.in || framework_failure_
25returns_ 1 split file.in -b1 --numeric=89 || fail=1
26test "$(ls -1 x* | wc -l)" = 11 || fail=1
27rm -f x*
28
29# ensure auto widening works when no start num specified
30truncate -s91 file.in || framework_failure_
31for prefix in 'x' 'xx' ''; do
32    for add_suffix in '.txt' ''; do
33      split file.in "$prefix" -b1 --numeric --additional-suffix="$add_suffix" \
34        || fail=1
35      test "$(ls -1 $prefix*[0-9]*$add_suffix | wc -l)" = 91 || fail=1
36      test -e "${prefix}89$add_suffix" || fail=1
37      test -e "${prefix}9000$add_suffix" || fail=1
38      rm -f $prefix*[0-9]*$add_suffix
39    done
40done
41
42# ensure auto width with --number and start num < number of files
43# That's the single run use case which is valid to adjust suffix len
44truncate -s100 file.in || framework_failure_
45split --numeric-suffixes=1 --number=r/100 file.in || fail=1
46rm -f x*
47
48# ensure no auto width with --number and start num >= number of files
49# That's the multi run use case which is invalid to adjust suffix len
50# as that would result in an incorrect order for the total output file set
51returns_ 1 split --numeric-suffixes=100 --number=r/100 file.in || fail=1
52
53# coreutils v8.24 - v8.31 inclusive would incorrectly auto calculate
54# a suffix length that was too small, when the number of files was
55# evenly divisible by the suffix base (10,16,26).
56truncate -s0 file.in || framework_failure_
57split --numeric-suffixes --number=110 file.in || fail=1
58
59Exit $fail
60