2 # Show that wc's --total option works.
4 # Copyright (C) 2022-2024 Free Software Foundation, Inc.
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.
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.
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/>.
19 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
21 require_sparse_support_
# for 'truncate --size=$BIG'
24 printf '%s\n' '2' > 2b || framework_failure_
25 printf '%s\n' '2 words' > 2w || framework_failure_
27 returns_
1 wc --total 2b
2w
> out || fail
=1
29 wc --total=never
2b
2w
> out || fail
=1
30 cat <<\EOF
> exp || framework_failure_
34 compare exp out || fail
=1
36 wc --total=only
2b
2w
> out || fail
=1
37 cat <<\EOF
> exp || framework_failure_
40 compare exp out || fail
=1
42 wc --total=always
2b
> out || fail
=1
43 test "$(wc -l < out)" = 2 || fail
=1
45 if 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 \
51 # Ensure total is saturated
52 printf '%s\n' "$UINTMAX_MAX" > exp || framework_failure_
53 compare exp out || fail
=1
55 # Ensure overflow is ignored if totals not shown
56 wc --total=never
-c big big big big big big big big || fail
=1