diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 16:58:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 16:58:41 +0000 |
commit | e1908ae95dd4c9d19ee4dfabfc8bf8a7f85943fe (patch) | |
tree | f5cc731bedcac0fb7fe14d952e4581e749f8bb87 /tests/wc | |
parent | Initial commit. (diff) | |
download | coreutils-e1908ae95dd4c9d19ee4dfabfc8bf8a7f85943fe.tar.xz coreutils-e1908ae95dd4c9d19ee4dfabfc8bf8a7f85943fe.zip |
Adding upstream version 9.4.upstream/9.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/wc')
-rwxr-xr-x | tests/wc/wc-files0-from.pl | 93 | ||||
-rwxr-xr-x | tests/wc/wc-files0.sh | 62 | ||||
-rwxr-xr-x | tests/wc/wc-nbsp.sh | 52 | ||||
-rwxr-xr-x | tests/wc/wc-parallel.sh | 36 | ||||
-rwxr-xr-x | tests/wc/wc-proc.sh | 64 | ||||
-rwxr-xr-x | tests/wc/wc-total.sh | 60 | ||||
-rwxr-xr-x | tests/wc/wc.pl | 50 |
7 files changed, 417 insertions, 0 deletions
diff --git a/tests/wc/wc-files0-from.pl b/tests/wc/wc-files0-from.pl new file mode 100755 index 0000000..84da780 --- /dev/null +++ b/tests/wc/wc-files0-from.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl +# Exercise wc's --files0-from option. +# FIXME: keep this file in sync with tests/du/files0-from. + +# Copyright (C) 2006-2023 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 <https://www.gnu.org/licenses/>. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +my $prog = 'wc'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + # invalid extra command line argument + ['f-extra-arg', '--files0-from=- no-such', {IN=>"a"}, {EXIT=>1}, + {ERR => "$prog: extra operand 'no-such'\n" + . "file operands cannot be combined with --files0-from\n" + . "Try '$prog --help' for more information.\n"} + ], + + # missing input file + ['missing', '--files0-from=missing', {EXIT=>1}, + {ERR => "$prog: cannot open 'missing' for reading: " + . "No such file or directory\n"}], + + # input file name of '-' + ['minus-in-stdin', '--files0-from=-', '<', {IN=>{f=>'-'}}, {EXIT=>1}, + {ERR => "$prog: when reading file names from stdin, no file name of" + . " '-' allowed\n"}], + + # empty input, regular file + ['empty', '--files0-from=@AUX@', {AUX=>''}], + + # empty input, from non-regular file + ['empty-nonreg', '--files0-from=/dev/null'], + + # one NUL + ['nul-1', '--files0-from=-', '<', {IN=>"\0"}, {EXIT=>1}, + {ERR => "$prog: -:1: invalid zero-length file name\n"}], + + # two NULs + ['nul-2', '--files0-from=-', '<', {IN=>"\0\0"}, {EXIT=>1}, + {OUT=>"0 0 0 total\n"}, + {ERR => "$prog: -:1: invalid zero-length file name\n" + . "$prog: -:2: invalid zero-length file name\n"}], + + # one file name, no NUL + ['1', '--files0-from=-', '<', + {IN=>{f=>"g"}}, {AUX=>{g=>''}}, {OUT=>"0 0 0 g\n"} ], + + # one file name, with NUL + ['1a', '--files0-from=-', '<', + {IN=>{f=>"g\0"}}, {AUX=>{g=>''}}, {OUT=>"0 0 0 g\n"} ], + + # two file names, no final NUL + ['2', '--files0-from=-', '<', + {IN=>{f=>"g\0g"}}, {AUX=>{g=>''}}, + {OUT=>"0 0 0 g\n0 0 0 g\n0 0 0 total\n"} ], + + # two file names, with final NUL + ['2a', '--files0-from=-', '<', + {IN=>{f=>"g\0g\0"}}, {AUX=>{g=>''}}, + {OUT=>"0 0 0 g\n0 0 0 g\n0 0 0 total\n"} ], + + # Ensure that $prog processes FILEs following a zero-length name. + ['zero-len', '--files0-from=-', '<', + {IN=>{f=>"\0g\0"}}, {AUX=>{g=>''}}, + {OUT=>"0 0 0 g\n0 0 0 total\n"}, + {ERR => "$prog: -:1: invalid zero-length file name\n"}, {EXIT=>1} ], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/wc/wc-files0.sh b/tests/wc/wc-files0.sh new file mode 100755 index 0000000..1752305 --- /dev/null +++ b/tests/wc/wc-files0.sh @@ -0,0 +1,62 @@ +#!/bin/sh +# Show that wc's new --files0-from option works. + +# Copyright (C) 2006-2023 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ wc + +echo 2 > 2b || framework_failure_ +echo 2 words > 2w || framework_failure_ +printf '2b\n2w\n' |tr '\n' '\0' > names || framework_failure_ + + +wc --files0-from=names > out || fail=1 +cat <<\EOF > exp || framework_failure_ + 1 1 2 2b + 1 2 8 2w + 2 3 10 total +EOF + +compare exp out || fail=1 + +if ! test "$fail" = 1; then + # Repeat the above test, but read the file name list from stdin. + rm -f out + wc --files0-from=- < names > out || fail=1 + compare exp out || fail=1 +fi + +# Ensure file name containing new lines are output on a single line +nlname='1 +2' +touch "$nlname" || framework_failure_ +printf '%s\0' "$nlname" | wc --files0-from=- > out || fail=1 +printf '%s\n' "0 0 0 '1'\$'\\n''2'" > exp || framework_failure_ +compare exp out || fail=1 + +# Ensure correct byte counts, which fails between v8.24 and v8.26 inclusive +truncate -s1G wc.big || framework_failure_ +touch wc.small || framework_failure_ +printf '%s\0' wc.big wc.small | wc -c --files0-from=- >out || fail=1 +cat <<\EOF > exp || framework_failure_ +1073741824 wc.big +0 wc.small +1073741824 total +EOF +compare exp out || fail=1 + +Exit $fail diff --git a/tests/wc/wc-nbsp.sh b/tests/wc/wc-nbsp.sh new file mode 100755 index 0000000..584a8f7 --- /dev/null +++ b/tests/wc/wc-nbsp.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# Test non breaking space handling + +# Copyright (C) 2019-2023 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ wc printf + +# Before coreutils 8.31 nbsp was treated as part of a word, +# rather than a word delimiter + +check_word_sep() { + char="$1" + # Use -L to determine whether NBSP is printable. + # FreeBSD 11 and OS X treat NBSP as non printable ? + if test "$(env printf "=$char=" | wc -L)" = 3; then + test $(env printf "=$char=" | wc -w) = 2 || fail=1 + fi +} + +export LC_ALL=en_US.iso8859-1 # only lowercase form works on macOS 10.15.7 +if test "$(locale charmap 2>/dev/null | sed 's/iso/ISO-/')" = ISO-8859-1; then + check_word_sep '\xA0' +fi + +export LC_ALL=en_US.UTF-8 +if test "$(locale charmap 2>/dev/null)" = UTF-8; then + check_word_sep '\u00A0' + check_word_sep '\u2007' + check_word_sep '\u202F' + check_word_sep '\u2060' +fi + +export LC_ALL=ru_RU.KOI8-R +if test "$(locale charmap 2>/dev/null)" = KOI8-R; then + check_word_sep '\x9A' +fi + +Exit $fail diff --git a/tests/wc/wc-parallel.sh b/tests/wc/wc-parallel.sh new file mode 100755 index 0000000..0319f6e --- /dev/null +++ b/tests/wc/wc-parallel.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# Ensure that wc prints counts atomically +# so that concurrent processes don't intersperse their output + +# Copyright (C) 2009-2023 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ wc + +xargs -P2 </dev/null >/dev/null 2>&1 \ + || skip_ 'xargs -P is required' + +(mkdir tmp && cd tmp && seq 2000 | xargs touch) + +# This will output at least 16KiB per process +# and start 3 processes, with 2 running concurrently, +# which triggers often on Fedora 11 at least. +(find tmp tmp tmp -type f | xargs -n2000 -P2 wc 2>err) | +sed -n '/0 0 0 /!p' | +grep . > /dev/null && fail=1 +compare /dev/null err || fail=1 + +Exit $fail diff --git a/tests/wc/wc-proc.sh b/tests/wc/wc-proc.sh new file mode 100755 index 0000000..2307f2c --- /dev/null +++ b/tests/wc/wc-proc.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# Test wc on /proc and /sys files. + +# Copyright 2014-2023 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ wc + +# Ensure we read() /proc files to determine content length +for file in /proc/version /sys/kernel/profiling; do + if test -r $file; then + cp -f $file copy && + wc -c < copy > exp1 || framework_failure_ + + wc -c < $file > out1 || fail=1 + compare exp1 out1 || fail=1 + fi +done + +# Ensure we handle cases where we don't read() +truncate -s 2 no_read || framework_failure_ +# read() used when multiple of page size +truncate -s 1048576 do_read || framework_failure_ +wc -c no_read do_read > out || fail=1 +cat <<\EOF > exp + 2 no_read +1048576 do_read +1048578 total +EOF +compare exp out || fail=1 + +# Ensure we update the offset even when not reading, +# which wasn't the case from coreutils-8.27 to coreutils-9.2 +{ wc -c; wc -c; } < no_read > out || fail=1 +{ wc -c; wc -c; } < do_read >> out || fail=1 +cat <<\EOF > exp +2 +0 +1048576 +0 +EOF +compare exp out || fail=1 + +# Ensure we don't read too much when reading, +# as was the case on 32 bit systems +# from coreutils-8.24 to coreutils-9.1 +if timeout 10 truncate -s1T do_read; then + timeout 10 wc -c do_read || fail=1 +fi + +Exit $fail diff --git a/tests/wc/wc-total.sh b/tests/wc/wc-total.sh new file mode 100755 index 0000000..113b355 --- /dev/null +++ b/tests/wc/wc-total.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# Show that wc's --total option works. + +# Copyright (C) 2022-2023 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ wc +require_sparse_support_ # for 'truncate --size=$BIG' +getlimits_ + +printf '%s\n' '2' > 2b || framework_failure_ +printf '%s\n' '2 words' > 2w || framework_failure_ + +returns_ 1 wc --total 2b 2w > out || fail=1 + +wc --total=never 2b 2w > out || fail=1 +cat <<\EOF > exp || framework_failure_ + 1 1 2 2b + 1 2 8 2w +EOF +compare exp out || fail=1 + +wc --total=only 2b 2w > out || fail=1 +cat <<\EOF > exp || framework_failure_ +2 3 10 +EOF +compare exp out || fail=1 + +wc --total=always 2b > out || fail=1 +test "$(wc -l < out)" = 2 || fail=1 + +if truncate -s 2E big; then + if test "$UINTMAX_MAX" = '18446744073709551615'; then + # Ensure overflow is diagnosed + returns_ 1 wc --total=only -c big big big big big big big big \ + > out || fail=1 + + # Ensure total is saturated + printf '%s\n' "$UINTMAX_MAX" > exp || framework_failure_ + compare exp out || fail=1 + + # Ensure overflow is ignored if totals not shown + wc --total=never -c big big big big big big big big || fail=1 + fi +fi + +Exit $fail diff --git a/tests/wc/wc.pl b/tests/wc/wc.pl new file mode 100755 index 0000000..ed2bc43 --- /dev/null +++ b/tests/wc/wc.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl +# Basic tests for "wc". + +# Copyright (C) 1997-2023 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 <https://www.gnu.org/licenses/>. + +use strict; + +my $prog = 'wc'; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my @Tests = + ( + ['a0', '-c', {IN_PIPE=>''}, {OUT=>"0\n"}], + ['a1', '-l', {IN_PIPE=>''}, {OUT=>"0\n"}], + ['a2', '-w', {IN_PIPE=>''}, {OUT=>"0\n"}], + ['a3', '-c', {IN_PIPE=>'x'}, {OUT=>"1\n"}], + ['a4', '-w', {IN_PIPE=>'x'}, {OUT=>"1\n"}], + ['a5', '-w', {IN_PIPE=>"x y\n"}, {OUT=>"2\n"}], + ['a6', '-w', {IN_PIPE=>"x y\nz"}, {OUT=>"3\n"}], + # Remember, -l counts *newline* bytes, not logical lines. + ['a7', '-l', {IN_PIPE=>"x y"}, {OUT=>"0\n"}], + ['a8', '-l', {IN_PIPE=>"x y\n"}, {OUT=>"1\n"}], + ['a9', '-l', {IN_PIPE=>"x\ny\n"}, {OUT=>"2\n"}], + ['b0', '', {IN_PIPE=>""}, {OUT=>" 0 0 0\n"}], + ['b1', '', {IN_PIPE=>"a b\nc\n"}, {OUT=>" 2 3 6\n"}], + ['c0', '-L', {IN_PIPE=>"1\n12\n"}, {OUT=>"2\n"}], + ['c1', '-L', {IN_PIPE=>"1\n123\n1\n"}, {OUT=>"3\n"}], + ['c2', '-L', {IN_PIPE=>"\n123456"}, {OUT=>"6\n"}], + ); + +my $save_temps = $ENV{DEBUG}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose); +exit $fail; |