From 6894816c653adef54f3a85becbf75a865d6d39d6 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Tue, 16 Dec 2014 12:36:39 +0000 Subject: diagnose too-large numbers better Following on from commit v8.23-82-gaddae94, consistently diagnose numbers that are too large, so as to distinguish from other errors, and make the limits obvious. * gl/modules/xdectoint: A new module implementing xdecto[iu]max(), which handles the common case of parsing a bounded integer and exiting with a diagnostic on error. * gl/lib/xdectoimax.c: The signed variant. * gl/lib/xdectoint.c: The parameterized implementation. * gl/lib/xdectoint.h: The interface. * gl/lib/xdectoumax.c: The unsigned variant. * bootstrap.conf: Reference the new module. * cfg.mk (exclude_file_name_regexp--sc_require_config_h_first): Exclude the parameterized templates. * src/csplit.c: Output EOVERFLOW or ERANGE errors if appropriate. * src/fmt.c: Likewise. * src/fold.c: Likewise. * src/head.c: Likewise. * src/ls.c: Likewise. * src/nl.c: Likewise. * src/nproc.c: Likewise. * src/shred.c: Likewise. * src/shuf.c: Likewise. * src/stdbuf.c: Likewise. * src/stty.c: Likewise. * src/tail.c: Likewise. * src/truncate.c: Likewise. * src/split.c: Likewise. * src/pr.c: Likewise. * tests/pr/pr-tests.pl: Adjust to avoid matching errno diagnostic. * tests/fmt/base.pl: Likewise. * tests/split/l-chunk.sh: Likewise. * tests/misc/shred-negative.sh: Likewise. * tests/misc/tail.pl: Likewise. Also remove the redundant existing ERR_SUBST from test err-6. * tests/ls/hex-option.sh: Check HEX/OCT options. * tests/misc/shred-size.sh: Likewise. * tests/misc/stty-row-col.sh: Likewise. --- tests/fmt/base.pl | 6 ++++-- tests/local.mk | 3 ++- tests/ls/hex-option.sh | 24 ++++++++++++++++++++++++ tests/misc/shred-negative.sh | 28 ---------------------------- tests/misc/shred-size.sh | 34 ++++++++++++++++++++++++++++++++++ tests/misc/stty-row-col.sh | 2 ++ tests/misc/tail.pl | 12 ++++++------ tests/pr/pr-tests.pl | 10 ++++++---- tests/split/l-chunk.sh | 7 ++++--- 9 files changed, 82 insertions(+), 44 deletions(-) create mode 100755 tests/ls/hex-option.sh delete mode 100755 tests/misc/shred-negative.sh create mode 100755 tests/misc/shred-size.sh (limited to 'tests') diff --git a/tests/fmt/base.pl b/tests/fmt/base.pl index c6b978785..8751119f1 100755 --- a/tests/fmt/base.pl +++ b/tests/fmt/base.pl @@ -26,9 +26,11 @@ my @Tests = {IN=> "ça\nçb\n"}, {OUT=>"ça b\n"}], ['wide-1', '-w 32768', - {ERR => "fmt: invalid width: '32768'\n"}, {EXIT => 1}], + {ERR => "fmt: invalid width: '32768'"}, {EXIT => 1}, + {ERR_SUBST => 's/:[^:]*$//'}], ['wide-2', '-w 2147483647', - {ERR => "fmt: invalid width: '2147483647'\n"}, {EXIT => 1}], + {ERR => "fmt: invalid width: '2147483647'"}, {EXIT => 1}, + {ERR_SUBST => 's/:[^:]*$//'}], ['bad-suffix', '-72x', {IN=> ''}, {ERR => "fmt: invalid width: '72x'\n"}, {EXIT => 1}], ['no-file', 'no-such-file', diff --git a/tests/local.mk b/tests/local.mk index 349e322b0..6aec69b0a 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -320,9 +320,9 @@ all_tests = \ tests/misc/sha384sum.pl \ tests/misc/sha512sum.pl \ tests/misc/shred-exact.sh \ - tests/misc/shred-negative.sh \ tests/misc/shred-passes.sh \ tests/misc/shred-remove.sh \ + tests/misc/shred-size.sh \ tests/misc/shuf.sh \ tests/misc/shuf-reservoir.sh \ tests/misc/sort.pl \ @@ -557,6 +557,7 @@ all_tests = \ tests/ls/file-type.sh \ tests/ls/follow-slink.sh \ tests/ls/getxattr-speedup.sh \ + tests/ls/hex-option.sh \ tests/ls/infloop.sh \ tests/ls/inode.sh \ tests/ls/m-option.sh \ diff --git a/tests/ls/hex-option.sh b/tests/ls/hex-option.sh new file mode 100755 index 000000000..0a684b06e --- /dev/null +++ b/tests/ls/hex-option.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# accept hex/oct numbers to -w and -T + +# Copyright (C) 2014 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 . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ ls + +ls -x -T0x10 -w010 || fail=1 + +Exit $fail diff --git a/tests/misc/shred-negative.sh b/tests/misc/shred-negative.sh deleted file mode 100755 index 86cbf3e02..000000000 --- a/tests/misc/shred-negative.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -# Exercise shred -s-3 FILE - -# Copyright (C) 2014 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 . - -. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src -print_ver_ shred - -echo 'shred: -2: invalid file size' > exp || framework_failure_ -echo 1234 > f || framework_failure_ - -shred -s-2 f 2>err && fail=1 -compare exp err || fail=1 - -Exit $fail diff --git a/tests/misc/shred-size.sh b/tests/misc/shred-size.sh new file mode 100755 index 000000000..9eabf606c --- /dev/null +++ b/tests/misc/shred-size.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Exercise shred --size + +# Copyright (C) 2014 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 . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ shred + +# Negative size +echo "shred: invalid file size: '-2'" > exp || framework_failure_ +echo 1234 > f || framework_failure_ +shred -s-2 f 2>err && fail=1 +compare exp err || fail=1 + +# Octal/Hex +shred -s010 f || fail=1 +test $(stat --printf=%s f) = 8 || fail=1 +shred -s0x10 f || fail=1 +test $(stat --printf=%s f) = 16 || fail=1 + +Exit $fail diff --git a/tests/misc/stty-row-col.sh b/tests/misc/stty-row-col.sh index 729d6f913..1c7af1da0 100755 --- a/tests/misc/stty-row-col.sh +++ b/tests/misc/stty-row-col.sh @@ -47,6 +47,8 @@ tests=' 7 rows_1 1_1 8 columns_80 1_80 9 rows_30 30_80 +10 rows_0x1E 30_80 +11 rows_036 30_80 NA LAST NA ' set $tests diff --git a/tests/misc/tail.pl b/tests/misc/tail.pl index 6798eb05d..adeff6857 100755 --- a/tests/misc/tail.pl +++ b/tests/misc/tail.pl @@ -19,7 +19,7 @@ use strict; my $prog = 'tail'; -my $normalize_filename = {ERR_SUBST => 's/^$prog: .*?:/$prog: -:/'}; +my $normalize_strerror = 's/:[^:]*$//'; # Turn off localization of executable's output. @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; @@ -59,7 +59,7 @@ my @tv = ( "$prog: cannot open '+cl' for reading: No such file or directory\n"], ['err-2', '-cl', '', '', 1, - "$prog: l: invalid number of bytes\n"], + "$prog: invalid number of bytes: 'l'\n"], ['err-3', '+2cz', '', '', 1, "$prog: cannot open '+2cz' for reading: No such file or directory\n"], @@ -72,9 +72,9 @@ my @tv = ( # the diagnostic: 'tail: 99999999999999999999: invalid number of bytes' # on all systems... probably, for now, maybe. ['err-5', '-c99999999999999999999', '', '', 1, - "$prog: 99999999999999999999: invalid number of bytes\n"], + "$prog: invalid number of bytes: '99999999999999999999'", $normalize_strerror], ['err-6', '-c --', '', '', 1, - "$prog: -: invalid number of bytes\n", $normalize_filename], + "$prog: invalid number of bytes: '-'\n"], # Same as -n 10 ['minus-1', '-', '', '', 0], @@ -106,10 +106,10 @@ my @Tests; foreach my $t (@tv) { - my ($test_name, $flags, $in, $exp, $ret, $err_msg) = @$t; + my ($test_name, $flags, $in, $exp, $ret, $err_msg, $err_sub) = @$t; my $e = [$test_name, $flags, {IN=>$in}, {OUT=>$exp}]; $ret - and push @$e, {EXIT=>$ret}, {ERR=>$err_msg}; + and push @$e, {EXIT=>$ret}, {ERR=>$err_msg}, {ERR_SUBST=>$err_sub}; $test_name =~ /^(obs-plus-|minus-)/ and push @$e, {ENV=>'_POSIX2_VERSION=199209'}; diff --git a/tests/pr/pr-tests.pl b/tests/pr/pr-tests.pl index 10947ac95..cc2ef38c4 100755 --- a/tests/pr/pr-tests.pl +++ b/tests/pr/pr-tests.pl @@ -385,9 +385,11 @@ my @tv = ( ['col-long', '-W3 -t -1 --columns=2', "a\nb\nc\n", "a c\nb\n", 0], # Make sure these fail. ['col-0', '-0', '', '', 1, - "$prog: invalid number of columns: '0'\n"], + "$prog: invalid number of columns: '0'", + 's/:[^:]*$//'], ['col-inval', '-'.'9'x100, '', '', 1, - "$prog: invalid number of columns: '". ('9'x100) ."'\n"], + "$prog: invalid number of columns: '". ('9'x100) ."'", + 's/:[^:]*$//'], # Before coreutils-5.3.1, --pages=1:-1 would be treated like # --pages=1:18446744073709551615. @@ -427,7 +429,7 @@ my $common_option_prefix = '--date-format="-- Date/Time --" -h x'; my @Tests; foreach my $t (@tv) { - my ($test_name, $flags, $in, $exp, $ret, $err_msg) = @$t; + my ($test_name, $flags, $in, $exp, $ret, $err_msg, $err_sub) = @$t; my $new_ent = [$test_name, $common_option_prefix, $flags]; if (!ref $in) { @@ -454,7 +456,7 @@ foreach my $t (@tv) } } $ret - and push @$new_ent, {EXIT=>$ret}, {ERR=>$err_msg}; + and push @$new_ent, {EXIT=>$ret}, {ERR=>$err_msg}, {ERR_SUBST=>$err_sub}; push @Tests, $new_ent; } diff --git a/tests/split/l-chunk.sh b/tests/split/l-chunk.sh index 792c55691..39ee4dc03 100755 --- a/tests/split/l-chunk.sh +++ b/tests/split/l-chunk.sh @@ -20,7 +20,7 @@ print_ver_ split # invalid number of chunks -echo 'split: 1o: invalid number of chunks' > exp +echo "split: invalid number of chunks: '1o'" > exp split -n l/1o 2>err && fail=1 compare exp err || fail=1 @@ -53,8 +53,9 @@ lines=\ printf "%s" "$lines" | tr '~' '\n' > in || framework_failure_ -echo 'split: 16: invalid chunk number' > exp -split -n l/16/15 in 2>err && fail=1 +echo "split: invalid chunk number: '16'" > exp +split -n l/16/15 in 2>err.t && fail=1 +sed 's/:[^:]*$//' < err.t > err || framework_failure_ compare exp err || fail=1 printf '%s' "\ -- cgit v1.2.3-70-g09d2