1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-02-18 13:21:58 +02:00
Files
coreutils/tests/misc/expr

195 lines
8.1 KiB
Plaintext
Raw Permalink Normal View History

tests: remove ugly /bin/sh wrapper around each perl-based test script * tests/check.mk (TESTS_ENVIRONMENT): Save and restore TMPDIR around envvar-check, so that the few scripts that require $TMPDIR don't fail. This is also good to let a user's default TMPDIR setting be used e.g., in the search for an 'other-partition'. FIXME: this is pretty ugly. maybe undo it and find a better way. (TESTS_ENVIRONMENT): Invoke perl scripts with $(PERL), and use -T if the script requires that. Otherwise, use $(SHELL). * tests/misc/md5sum-newline: Create a file whose name contains a newline in Perl (resort to using "system", since open refuses). Fix old brokenness exposed by this change: * tests/du/files0-from: Correct test not to rely on stdin being attached to a non-tty. * tests/misc/sort (3g, 3h, 3i): Likewise: add explicit empty input file. Avoid warnings about using qw()-around-commas. * tests/rm/fail-eperm: Now that this test is run from a temporary subdirectory, adjust the full name of the "rm" program we're going to run. Change #!/bin/sh to #!/usr/bin/perl, and factor out the few lines of boilerplate code to invoke perl. Do not "require 5.00x"; a configure-time Perl test handles that * tests/dd/skip-seek: * tests/misc/base64: * tests/misc/basename: * tests/misc/cut: * tests/misc/date: * tests/misc/dircolors: * tests/misc/dirname: * tests/misc/expand: * tests/misc/expr: * tests/misc/factor: * tests/misc/fmt: * tests/misc/fold: * tests/misc/head: * tests/misc/head-elide-tail: * tests/misc/join: * tests/misc/ls-misc: * tests/misc/md5sum: * tests/misc/md5sum-newline: * tests/misc/mktemp: * tests/misc/od: * tests/misc/paste: * tests/misc/pr: * tests/misc/printf-cov: * tests/misc/seq: * tests/misc/sha1sum: * tests/misc/sha1sum-vec: * tests/misc/sha224sum: * tests/misc/sha256sum: * tests/misc/sha384sum: * tests/misc/sha512sum: * tests/misc/sort-merge: * tests/misc/stat-printf: * tests/misc/sum: * tests/misc/tac: * tests/misc/tail: * tests/misc/test: * tests/misc/test-diag: * tests/misc/tr: * tests/misc/tsort: * tests/misc/tty-eof: * tests/misc/unexpand: * tests/misc/uniq: * tests/misc/wc: * tests/misc/wc-files0-from: * tests/misc/xstrtol: * tests/mv/i-1: * tests/pr/pr-tests: * tests/rm/empty-name: * tests/rm/fail-eperm: * tests/rm/unreadable:
2008-05-14 09:37:02 +02:00
#!/usr/bin/perl
# Basic tests for "expr".
# Copyright (C) 2001, 2003-2009 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 <http://www.gnu.org/licenses/>.
2001-08-18 16:13:16 +00:00
use strict;
(my $program_name = $0) =~ s|.*/||;
my $prog = 'expr';
2001-08-18 16:13:16 +00:00
# Turn off localization of executable's output.
2001-08-18 16:13:16 +00:00
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
my $big = '98782897298723498732987928734';
my $big_p1 = '98782897298723498732987928735';
my $big_sum = '197565794597446997465975857469';
my $big_prod = '9758060798730154302876482828124348356960410232492450771490';
2001-08-18 16:13:16 +00:00
my @Tests =
(
['a', '5 + 6', {OUT => '11'}],
2001-08-18 16:27:46 +00:00
['b', '5 - 6', {OUT => '-1'}],
['c', '5 \* 6', {OUT => '30'}],
['d', '100 / 6', {OUT => '16'}],
['e', '100 % 6', {OUT => '4'}],
['f', '3 + -2', {OUT => '1'}],
['g', '-2 + -2', {OUT => '-4'}],
2001-08-18 16:27:46 +00:00
# Verify option processing.
# Added when option processing broke in the 7.0 beta release
['opt1', '-- -11 + 12', {OUT => '1'}],
['opt2', '-11 + 12', {OUT => '1'}],
['opt3', '-- -1 + 2', {OUT => '1'}],
['opt4', '-1 + 2', {OUT => '1'}],
# This evoked a syntax error diagnostic before 2.0.12.
['opt5', '-- 2 + 2', {OUT => '4'}],
2001-08-18 21:21:40 +00:00
['paren1', '\( 100 % 6 \)', {OUT => '4'}],
['paren2', '\( 100 % 6 \) - 8', {OUT => '-4'}],
['paren3', '9 / \( 100 % 6 \) - 8', {OUT => '-6'}],
['paren4', '9 / \( \( 100 % 6 \) - 8 \)', {OUT => '-2'}],
['paren5', '9 + \( 100 % 6 \)', {OUT => '13'}],
2001-08-18 20:47:57 +00:00
# Before 2.0.12, this would output `1'.
2004-02-22 14:57:20 +00:00
['0bang', '00 \< 0!', {OUT => '0'}, {EXIT => 1}],
# In 5.1.3 and earlier, these would exit with status 0.
['00', '00', {OUT => '00'}, {EXIT => 1}],
['minus0', '-0', {OUT => '-0'}, {EXIT => 1}],
# In 5.1.3 and earlier, these would report errors.
['andand', '0 \& 1 / 0', {OUT => '0'}, {EXIT => 1}],
['oror', '1 \| 1 / 0', {OUT => '1'}, {EXIT => 0}],
# In 5.1.3 and earlier, this would output the empty string.
['orempty', '"" \| ""', {OUT => '0'}, {EXIT => 1}],
2001-08-18 20:47:57 +00:00
2001-08-18 17:14:52 +00:00
# This erroneously succeeded and output `3' before 2.0.12.
2001-08-18 16:27:46 +00:00
['fail-a', '3 + -', {ERR => "$prog: non-numeric argument\n"},
{EXIT => 2}],
2003-07-18 07:29:01 +00:00
2005-05-27 20:32:28 +00:00
# This erroneously succeeded before 5.3.1.
['bigcmp', '-- -2417851639229258349412352 \< 2417851639229258349412352',
{OUT => '1'}, {EXIT => 0}],
# In 5.94 and earlier, anchors incorrectly matched newlines.
['anchor', "'a\nb' : 'a\$'", {OUT => '0'}, {EXIT => 1}],
# These tests are taken from grep/tests/bre.tests.
['bre1', '"abc" : "a\\(b\\)c"', {OUT => 'b'}],
['bre2', '"a(" : "a("', {OUT => '2'}],
['bre3', '_ : "a\\("',
{ERR => "$prog: Unmatched ( or \\(\n"}, {EXIT => 2}],
['bre4', '_ : "a\\(b"',
{ERR => "$prog: Unmatched ( or \\(\n"}, {EXIT => 2}],
['bre5', '"a(b" : "a(b"', {OUT => '3'}],
['bre6', '"a)" : "a)"', {OUT => '2'}],
['bre7', '_ : "a\\)"',
{ERR => "$prog: Unmatched ) or \\)\n"}, {EXIT => 2}],
['bre8', '_ : "\\)"',
{ERR => "$prog: Unmatched ) or \\)\n"}, {EXIT => 2}],
['bre9', '"ab" : "a\\(\\)b"', {OUT => ''}, {EXIT => 1}],
['bre10', '"a^b" : "a^b"', {OUT => '3'}],
['bre11', '"a\$b" : "a\$b"', {OUT => '3'}],
['bre12', '"" : "\\($\\)\\(^\\)"', {OUT => ''}, {EXIT => 1}],
['bre13', '"b" : "a*\\(^b\$\\)c*"', {OUT => 'b'}],
['bre14', '"X|" : "X\\(|\\)" : "(" "X|" : "X\\(|\\)" ")"', {OUT => '1'}],
['bre15', '"X*" : "X\\(*\\)" : "(" "X*" : "X\\(*\\)" ")"', {OUT => '1'}],
['bre16', '"abc" : "\\(\\)"', {OUT => ''}, {EXIT => 1}],
['bre17', '"{1}a" : "\\(\\{1\\}a\\)"', {OUT => '{1}a'}],
['bre18', '"X*" : "X\\(*\\)" : "^*"', {OUT => '1'}],
['bre19', '"{1}" : "^\\{1\\}"', {OUT => '3'}],
['bre20', '"{" : "{"', {OUT => '1'}],
['bre21', '"abbcbd" : "a\\(b*\\)c\\1d"', {OUT => ''}, {EXIT => 1}],
['bre22', '"abbcbbbd" : "a\\(b*\\)c\\1d"', {OUT => ''}, {EXIT => 1}],
['bre23', '"abc" : "\\(.\\)\\1"', {OUT => ''}, {EXIT => 1}],
['bre24', '"abbccd" : "a\\(\\([bc]\\)\\2\\)*d"', {OUT => 'cc'}],
['bre25', '"abbcbd" : "a\\(\\([bc]\\)\\2\\)*d"',
{OUT => ''}, {EXIT => 1}],
['bre26', '"abbbd" : "a\\(\\(b\\)*\\2\\)*d"', {OUT => 'bbb'}],
['bre27', '"aabcd" : "\\(a\\)\\1bcd"', {OUT => 'a'}],
['bre28', '"aabcd" : "\\(a\\)\\1bc*d"', {OUT => 'a'}],
['bre29', '"aabd" : "\\(a\\)\\1bc*d"', {OUT => 'a'}],
['bre30', '"aabcccd" : "\\(a\\)\\1bc*d"', {OUT => 'a'}],
['bre31', '"aabcccd" : "\\(a\\)\\1bc*[ce]d"', {OUT => 'a'}],
['bre32', '"aabcccd" : "\\(a\\)\\1b\\(c\\)*cd\$"', {OUT => 'a'}],
['bre33', '"a*b" : "a\\(*\\)b"', {OUT => '*'}],
['bre34', '"ab" : "a\\(**\\)b"', {OUT => ''}, {EXIT => 1}],
['bre35', '"ab" : "a\\(***\\)b"', {OUT => ''}, {EXIT => 1}],
['bre36', '"*a" : "*a"', {OUT => '2'}],
['bre37', '"a" : "**a"', {OUT => '1'}],
['bre38', '"a" : "***a"', {OUT => '1'}],
['bre39', '"ab" : "a\\{1\\}b"', {OUT => '2'}],
['bre40', '"ab" : "a\\{1,\\}b"', {OUT => '2'}],
['bre41', '"aab" : "a\\{1,2\\}b"', {OUT => '3'}],
['bre42', '_ : "a\\{1"',
{ERR => "$prog: Unmatched \\{\n"}, {EXIT => 2}],
['bre43', '_ : "a\\{1a"',
{ERR => "$prog: Unmatched \\{\n"}, {EXIT => 2}],
['bre44', '_ : "a\\{1a\\}"',
{ERR => "$prog: Invalid content of \\{\\}\n"}, {EXIT => 2}],
['bre45', '"a" : "a\\{,2\\}"', {OUT => '1'}],
['bre46', '"a" : "a\\{,\\}"', {OUT => '1'}],
['bre47', '_ : "a\\{1,x\\}"',
{ERR => "$prog: Invalid content of \\{\\}\n"}, {EXIT => 2}],
['bre48', '_ : "a\\{1,x"',
{ERR => "$prog: Unmatched \\{\n"}, {EXIT => 2}],
['bre49', '_ : "a\\{32768\\}"',
{ERR => "$prog: Invalid content of \\{\\}\n"}, {EXIT => 2}],
['bre50', '_ : "a\\{1,0\\}"',
{ERR => "$prog: Invalid content of \\{\\}\n"}, {EXIT => 2}],
['bre51', '"acabc" : ".*ab\\{0,0\\}c"', {OUT => '2'}],
['bre52', '"abcac" : "ab\\{0,1\\}c"', {OUT => '3'}],
['bre53', '"abbcac" : "ab\\{0,3\\}c"', {OUT => '4'}],
['bre54', '"abcac" : ".*ab\\{1,1\\}c"', {OUT => '3'}],
['bre55', '"abcac" : ".*ab\\{1,3\\}c"', {OUT => '3'}],
['bre56', '"abbcabc" : ".*ab\{2,2\}c"', {OUT => '4'}],
['bre57', '"abbcabc" : ".*ab\{2,4\}c"', {OUT => '4'}],
['bre58', '"aa" : "a\\{1\\}\\{1\\}"', {OUT => '1'}],
['bre59', '"aa" : "a*\\{1\\}"', {OUT => '2'}],
['bre60', '"aa" : "a\\{1\\}*"', {OUT => '2'}],
['bre61', '"acd" : "a\\(b\\)?c\\1d"', {OUT => ''}, {EXIT => 1}],
['bre62', '-- "-5" : "-\\{0,1\\}[0-9]*\$"', {OUT => '2'}],
2003-07-18 07:29:01 +00:00
['fail-b', '9 9', {ERR => "$prog: syntax error\n"},
{EXIT => 2}],
2004-06-21 15:04:54 +00:00
['fail-c', {ERR => "$prog: missing operand\n"
. "Try `$prog --help' for more information.\n"},
2003-07-18 07:29:01 +00:00
{EXIT => 2}],
['bignum-add', "$big + 1", {OUT => $big_p1}],
['bignum-add2', "$big + $big_p1", {OUT => $big_sum}],
['bignum-sub', "$big_p1 - 1", {OUT => $big}],
['bignum-sub2', "$big_sum - $big", {OUT => $big_p1}],
['bignum-mul', "$big_p1 '*' $big", {OUT => $big_prod}],
['bignum-div', "$big_prod / $big", {OUT => $big_p1}],
2001-08-18 16:13:16 +00:00
);
expr: remove --bignum and --no-bignum options * doc/coreutils.texi (expr invocation): Remove the --bignum and --no-bignum options. They weren't really needed, and they broke longstanding (albeit nonportable) scripts. * src/expr.c: Don't include <assert.h>. Include "inttostr.h", "long-options.h", "verify.h". Check at compile-time that size_t fits in unsigned long int, as the code assumes this in several places. (HAVE_GMP): Define to 0 if not defined, for convenience. (mpz_t, mpz_clear, mpz_init_set_ui, mpz_init_set_str, mpz_add): (mpz_sub, mpz_mul, mpz_tdiv_q, mpz_tdiv_r, mpz_get_str, mpz_sgn): (mpz_fits_ulong_p, mpz_get_ui, mpz_out_str): Supply substitutes when !HAVE_GMP, which work well enough for expr's purposes. (mp_integer): Remove. All integers are gmp, if gmp is available. (struct valinfo): Remove 'z' member; no longer needed. The 'i' member is always of type mpz_t. (enum arithmetic_mode, MP_NEVER, MP_ALWAYS, MP_AUTO, mode): Remove; no longer needed. (usage): Remove documentation of --bignum and --no-bignum. (integer_overflow): Abort if error misbehaves, to pacify GCC. Restore old message on arithmetic overflow, to be conservative. (die): Omit exit_status parameter; not needed (is always EXPR_FAILURE). (string_too_long, USE_BIGNUM, NO_USE_BIGNUM, long_options): Remove; no longer needed. (main): Don't use getopt_long; this breaks old nonportable scripts. (int_value): Arg is unsigned, in case we have strings whose length exceeds LONG_MAX (!). (int_value, freev, printv, null, tostring, toarith): (eval6, eval4, eval3): Always use mpz_ functions, to simplify the code. (substr_value): Remove; no longer needed. (getsize): Simplify the API: one arg rather than 3. Don't assume unsigned long int fits in size_t. (promote, domult, dodivide, doadd): Remove; no longer needed. * tests/misc/expr: Don't use --bignum to test for bignum support. Instead, use big numbers to test this.
2008-10-15 15:29:38 +02:00
# If using big numbers fails, remove all /^bignum-/ tests
`expr $big_prod '*' $big_prod '*' $big_prod`
or @Tests = grep {$_->[0] !~ /^bignum-/} @Tests;
2001-08-18 16:27:46 +00:00
# Append a newline to end of each expected `OUT' string.
2001-08-18 16:13:16 +00:00
my $t;
foreach $t (@Tests)
{
my $arg1 = $t->[1];
my $e;
foreach $e (@$t)
{
$e->{OUT} .= "\n"
if ref $e eq 'HASH' and exists $e->{OUT};
2001-08-18 16:13:16 +00:00
}
}
my $save_temps = $ENV{SAVE_TEMPS};
my $verbose = $ENV{VERBOSE};
my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
exit $fail;