1#!/bin/sh 2# Show that wc's --total option works. 3 4# Copyright (C) 2022-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_ wc 21require_sparse_support_ # for 'truncate --size=$BIG' 22getlimits_ 23 24printf '%s\n' '2' > 2b || framework_failure_ 25printf '%s\n' '2 words' > 2w || framework_failure_ 26 27returns_ 1 wc --total 2b 2w > out || fail=1 28 29wc --total=never 2b 2w > out || fail=1 30cat <<\EOF > exp || framework_failure_ 31 1 1 2 2b 32 1 2 8 2w 33EOF 34compare exp out || fail=1 35 36wc --total=only 2b 2w > out || fail=1 37cat <<\EOF > exp || framework_failure_ 382 3 10 39EOF 40compare exp out || fail=1 41 42wc --total=always 2b > out || fail=1 43test "$(wc -l < out)" = 2 || fail=1 44 45if truncate -s 2E big; then 46 if test "$UINTMAX_MAX" = '18446744073709551615'; then 47 # Ensure overflow is diagnosed 48 returns_ 1 wc --total=only -c big big big big big big big big \ 49 > out || fail=1 50 51 # Ensure total is saturated 52 printf '%s\n' "$UINTMAX_MAX" > exp || framework_failure_ 53 compare exp out || fail=1 54 55 # Ensure overflow is ignored if totals not shown 56 wc --total=never -c big big big big big big big big || fail=1 57 fi 58fi 59 60Exit $fail 61