1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-02-16 04:12:26 +02:00
Files
coreutils/tests/expr/basic

92 lines
2.5 KiB
Plaintext
Raw Normal View History

2001-08-18 16:13:16 +00:00
#!/bin/sh
# -*-perl-*-
: ${PERL=perl}
: ${srcdir=.}
$PERL -e 1 > /dev/null 2>&1 || {
echo 1>&2 "$0: configure didn't find a usable version of Perl," \
"so can't run this test"
exit 77
}
2001-08-18 16:13:16 +00:00
d=$srcdir/..
2005-04-20 07:54:54 +00:00
exec $PERL -w -I$d -MCoreutils -- - << \EOF
2001-08-18 16:13:16 +00:00
require 5.003;
use strict;
(my $program_name = $0) =~ s|.*/||;
# Turn off localisation of executable's ouput.
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
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
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 evoked a syntax error diagnostic before 2.0.12.
['minus2', '-- 2 + 2', {OUT => '4'}],
# 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 => 3}],
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}],
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"
2003-07-18 07:29:01 +00:00
. "Try `$prog --help' for more information.\n"},
{EXIT => 2}],
2001-08-18 16:13:16 +00:00
);
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)
{
2001-08-18 16:27:46 +00:00
$e->{OUT} .= "\n"
2001-08-18 16:13:16 +00:00
if ref $e eq 'HASH' and exists $e->{OUT};
}
}
my $save_temps = $ENV{SAVE_TEMPS};
my $verbose = $ENV{VERBOSE};
my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);
exit $fail;
EOF