2 # Basic tests for "expr".
4 # Copyright (C) 2001, 2003-2008 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 <http://www.gnu.org/licenses/>.
21 (my $program_name = $0) =~ s
|.*/||;
24 # Turn off localization of executable's output.
25 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x
3;
29 ['a', '5 + 6', {OUT
=> '11'}],
30 ['b', '5 - 6', {OUT
=> '-1'}],
31 ['c', '5 \* 6', {OUT
=> '30'}],
32 ['d', '100 / 6', {OUT
=> '16'}],
33 ['e', '100 % 6', {OUT
=> '4'}],
34 ['f', '3 + -2', {OUT
=> '1'}],
35 ['g', '-2 + -2', {OUT
=> '-4'}],
37 ['paren1', '\( 100 % 6 \)', {OUT
=> '4'}],
38 ['paren2', '\( 100 % 6 \) - 8', {OUT
=> '-4'}],
39 ['paren3', '9 / \( 100 % 6 \) - 8', {OUT
=> '-6'}],
40 ['paren4', '9 / \( \( 100 % 6 \) - 8 \)', {OUT
=> '-2'}],
41 ['paren5', '9 + \( 100 % 6 \)', {OUT
=> '13'}],
43 # Before 2.0.12, this would output `1'.
44 ['0bang', '00 \< 0!', {OUT
=> '0'}, {EXIT
=> 1}],
46 # In 5.1.3 and earlier, these would exit with status 0.
47 ['00', '00', {OUT
=> '00'}, {EXIT
=> 1}],
48 ['minus0', '-0', {OUT
=> '-0'}, {EXIT
=> 1}],
50 # In 5.1.3 and earlier, these would report errors.
51 ['andand', '0 \& 1 / 0', {OUT
=> '0'}, {EXIT
=> 1}],
52 ['oror', '1 \| 1 / 0', {OUT
=> '1'}, {EXIT
=> 0}],
54 # In 5.1.3 and earlier, this would output the empty string.
55 ['orempty', '"" \| ""', {OUT
=> '0'}, {EXIT
=> 1}],
57 # This evoked a syntax error diagnostic before 2.0.12.
58 ['minus2', '-- 2 + 2', {OUT
=> '4'}],
60 # This erroneously succeeded and output `3' before 2.0.12.
61 ['fail-a', '3 + -', {ERR
=> "$prog: non-numeric argument\n"},
64 # This erroneously succeeded before 5.3.1.
65 ['bigcmp', '-- -2417851639229258349412352 \< 2417851639229258349412352',
66 {OUT
=> '1'}, {EXIT
=> 0}],
68 # In 5.94 and earlier, anchors incorrectly matched newlines.
69 ['anchor', "'a\nb' : 'a\$'", {OUT
=> '0'}, {EXIT
=> 1}],
71 # These tests are taken from grep/tests/bre.tests.
72 ['bre1', '"abc" : "a\\(b\\)c"', {OUT
=> 'b'}],
73 ['bre2', '"a(" : "a("', {OUT
=> '2'}],
74 ['bre3', '_ : "a\\("',
75 {ERR
=> "$prog: Unmatched ( or \\(\n"}, {EXIT
=> 2}],
76 ['bre4', '_ : "a\\(b"',
77 {ERR
=> "$prog: Unmatched ( or \\(\n"}, {EXIT
=> 2}],
78 ['bre5', '"a(b" : "a(b"', {OUT
=> '3'}],
79 ['bre6', '"a)" : "a)"', {OUT
=> '2'}],
80 ['bre7', '_ : "a\\)"',
81 {ERR
=> "$prog: Unmatched ) or \\)\n"}, {EXIT
=> 2}],
83 {ERR
=> "$prog: Unmatched ) or \\)\n"}, {EXIT
=> 2}],
84 ['bre9', '"ab" : "a\\(\\)b"', {OUT
=> ''}, {EXIT
=> 1}],
85 ['bre10', '"a^b" : "a^b"', {OUT
=> '3'}],
86 ['bre11', '"a\$b" : "a\$b"', {OUT
=> '3'}],
87 ['bre12', '"" : "\\($\\)\\(^\\)"', {OUT
=> ''}, {EXIT
=> 1}],
88 ['bre13', '"b" : "a*\\(^b\$\\)c*"', {OUT
=> 'b'}],
89 ['bre14', '"X|" : "X\\(|\\)" : "(" "X|" : "X\\(|\\)" ")"', {OUT
=> '1'}],
90 ['bre15', '"X*" : "X\\(*\\)" : "(" "X*" : "X\\(*\\)" ")"', {OUT
=> '1'}],
91 ['bre16', '"abc" : "\\(\\)"', {OUT
=> ''}, {EXIT
=> 1}],
92 ['bre17', '"{1}a" : "\\(\\{1\\}a\\)"', {OUT
=> '{1}a'}],
93 ['bre18', '"X*" : "X\\(*\\)" : "^*"', {OUT
=> '1'}],
94 ['bre19', '"{1}" : "^\\{1\\}"', {OUT
=> '3'}],
95 ['bre20', '"{" : "{"', {OUT
=> '1'}],
96 ['bre21', '"abbcbd" : "a\\(b*\\)c\\1d"', {OUT
=> ''}, {EXIT
=> 1}],
97 ['bre22', '"abbcbbbd" : "a\\(b*\\)c\\1d"', {OUT
=> ''}, {EXIT
=> 1}],
98 ['bre23', '"abc" : "\\(.\\)\\1"', {OUT
=> ''}, {EXIT
=> 1}],
99 ['bre24', '"abbccd" : "a\\(\\([bc]\\)\\2\\)*d"', {OUT
=> 'cc'}],
100 ['bre25', '"abbcbd" : "a\\(\\([bc]\\)\\2\\)*d"',
101 {OUT
=> ''}, {EXIT
=> 1}],
102 ['bre26', '"abbbd" : "a\\(\\(b\\)*\\2\\)*d"', {OUT
=> 'bbb'}],
103 ['bre27', '"aabcd" : "\\(a\\)\\1bcd"', {OUT
=> 'a'}],
104 ['bre28', '"aabcd" : "\\(a\\)\\1bc*d"', {OUT
=> 'a'}],
105 ['bre29', '"aabd" : "\\(a\\)\\1bc*d"', {OUT
=> 'a'}],
106 ['bre30', '"aabcccd" : "\\(a\\)\\1bc*d"', {OUT
=> 'a'}],
107 ['bre31', '"aabcccd" : "\\(a\\)\\1bc*[ce]d"', {OUT
=> 'a'}],
108 ['bre32', '"aabcccd" : "\\(a\\)\\1b\\(c\\)*cd\$"', {OUT
=> 'a'}],
109 ['bre33', '"a*b" : "a\\(*\\)b"', {OUT
=> '*'}],
110 ['bre34', '"ab" : "a\\(**\\)b"', {OUT
=> ''}, {EXIT
=> 1}],
111 ['bre35', '"ab" : "a\\(***\\)b"', {OUT
=> ''}, {EXIT
=> 1}],
112 ['bre36', '"*a" : "*a"', {OUT
=> '2'}],
113 ['bre37', '"a" : "**a"', {OUT
=> '1'}],
114 ['bre38', '"a" : "***a"', {OUT
=> '1'}],
115 ['bre39', '"ab" : "a\\{1\\}b"', {OUT
=> '2'}],
116 ['bre40', '"ab" : "a\\{1,\\}b"', {OUT
=> '2'}],
117 ['bre41', '"aab" : "a\\{1,2\\}b"', {OUT
=> '3'}],
118 ['bre42', '_ : "a\\{1"',
119 {ERR
=> "$prog: Unmatched \\{\n"}, {EXIT
=> 2}],
120 ['bre43', '_ : "a\\{1a"',
121 {ERR
=> "$prog: Unmatched \\{\n"}, {EXIT
=> 2}],
122 ['bre44', '_ : "a\\{1a\\}"',
123 {ERR
=> "$prog: Invalid content of \\{\\}\n"}, {EXIT
=> 2}],
124 ['bre45', '"a" : "a\\{,2\\}"', {OUT
=> '1'}],
125 ['bre46', '"a" : "a\\{,\\}"', {OUT
=> '1'}],
126 ['bre47', '_ : "a\\{1,x\\}"',
127 {ERR
=> "$prog: Invalid content of \\{\\}\n"}, {EXIT
=> 2}],
128 ['bre48', '_ : "a\\{1,x"',
129 {ERR
=> "$prog: Unmatched \\{\n"}, {EXIT
=> 2}],
130 ['bre49', '_ : "a\\{32768\\}"',
131 {ERR
=> "$prog: Invalid content of \\{\\}\n"}, {EXIT
=> 2}],
132 ['bre50', '_ : "a\\{1,0\\}"',
133 {ERR
=> "$prog: Invalid content of \\{\\}\n"}, {EXIT
=> 2}],
134 ['bre51', '"acabc" : ".*ab\\{0,0\\}c"', {OUT
=> '2'}],
135 ['bre52', '"abcac" : "ab\\{0,1\\}c"', {OUT
=> '3'}],
136 ['bre53', '"abbcac" : "ab\\{0,3\\}c"', {OUT
=> '4'}],
137 ['bre54', '"abcac" : ".*ab\\{1,1\\}c"', {OUT
=> '3'}],
138 ['bre55', '"abcac" : ".*ab\\{1,3\\}c"', {OUT
=> '3'}],
139 ['bre56', '"abbcabc" : ".*ab\{2,2\}c"', {OUT
=> '4'}],
140 ['bre57', '"abbcabc" : ".*ab\{2,4\}c"', {OUT
=> '4'}],
141 ['bre58', '"aa" : "a\\{1\\}\\{1\\}"', {OUT
=> '1'}],
142 ['bre59', '"aa" : "a*\\{1\\}"', {OUT
=> '2'}],
143 ['bre60', '"aa" : "a\\{1\\}*"', {OUT
=> '2'}],
144 ['bre61', '"acd" : "a\\(b\\)?c\\1d"', {OUT
=> ''}, {EXIT
=> 1}],
145 ['bre62', '-- "-5" : "-\\{0,1\\}[0-9]*\$"', {OUT
=> '2'}],
147 ['fail-b', '9 9', {ERR
=> "$prog: syntax error\n"},
149 ['fail-c', {ERR
=> "$prog: missing operand\n"
150 . "Try `$prog --help' for more information.\n"},
154 # Append a newline to end of each expected `OUT' string.
163 if ref $e eq 'HASH' and exists $e->{OUT
};
167 my $save_temps = $ENV{SAVE_TEMPS
};
168 my $verbose = $ENV{VERBOSE
};
170 my $fail = run_tests
($program_name, $prog, \
@Tests, $save_temps, $verbose);