summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2018-03-31 15:52:32 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2018-03-31 15:52:32 +0000
commitc3e7989bb55713e30611fece68737ce4a1a3d80d (patch)
treeb239eeef14ce24f3f2251a39c67108ba2adddb32 /regress
parent7a43edf671659bda761f1be86f3780d71cfeb170 (diff)
a few more edge case tests, aiming for complete coverage
Diffstat (limited to 'regress')
-rwxr-xr-xregress/bin/expr/expr.sh22
1 files changed, 21 insertions, 1 deletions
diff --git a/regress/bin/expr/expr.sh b/regress/bin/expr/expr.sh
index da8bf0f1367..c0a665df860 100755
--- a/regress/bin/expr/expr.sh
+++ b/regress/bin/expr/expr.sh
@@ -1,5 +1,5 @@
#!/bin/ksh
-# $OpenBSD: expr.sh,v 1.1 2018/03/31 14:50:56 tobias Exp $
+# $OpenBSD: expr.sh,v 1.2 2018/03/31 15:52:31 schwarze Exp $
: ${EXPR=expr}
@@ -18,8 +18,12 @@ function test_expr {
# Test overflow cases
test_expr '4611686018427387904 + 4611686018427387903' '9223372036854775807'
test_expr '4611686018427387904 + 4611686018427387904' "expr: overflow"
+test_expr '-4611686018427387904 + -4611686018427387904' '-9223372036854775808'
+test_expr '-4611686018427387904 + -4611686018427387905' 'expr: overflow'
+test_expr '4611686018427387904 - -4611686018427387903' '9223372036854775807'
test_expr '4611686018427387904 - -4611686018427387904' "expr: overflow"
test_expr '-4611686018427387904 - 4611686018427387903' '-9223372036854775807'
+test_expr '-4611686018427387904 - 4611686018427387904' '-9223372036854775808'
test_expr '-4611686018427387904 - 4611686018427387905' "expr: overflow"
test_expr '-4611686018427387904 \* 1' '-4611686018427387904'
test_expr '-4611686018427387904 \* -1' '4611686018427387904'
@@ -29,6 +33,11 @@ test_expr '-4611686018427387904 \* -2' "expr: overflow"
test_expr '4611686018427387904 \* 1' '4611686018427387904'
test_expr '4611686018427387904 \* 2' "expr: overflow"
test_expr '4611686018427387904 \* 3' "expr: overflow"
+test_expr '4611686018427387903 \* 2' '9223372036854775806'
+test_expr '-4611686018427387905 \* 2' 'expr: overflow'
+test_expr '4611686018427387904 / 0' 'expr: division by zero'
+test_expr '-9223372036854775808 / -1' 'expr: overflow'
+test_expr '-9223372036854775808 % -1' '0'
# Test from gtk-- configure that cause problems on old expr
test_expr '3 \> 3 \| 3 = 3 \& 4 \> 4 \| 3 = 3 \& 4 = 4 \& 5 \>= 5' '1'
@@ -97,6 +106,13 @@ test_expr 'X1/2/3 : X\\\(.\*[^/]\\\)//\*[^/][^/]\*/\*$ \| . : \\\(.\\\)' '1/2'
test_expr '1/2 : .\*/\\\(.\*\\\)' '2'
# Test integer edge cases
+test_expr '9223372036854775806 + 0' '9223372036854775806'
+test_expr '9223372036854775806 + 1' '9223372036854775807'
+test_expr '9223372036854775807 + 0' '9223372036854775807'
+test_expr '9223372036854775806 + 2' 'expr: overflow'
+test_expr '9223372036854775807 + 1' 'expr: overflow'
+test_expr '9223372036854775808 + 0' \
+ 'expr: number "9223372036854775808" is too large'
test_expr '-9223372036854775807 + 0' '-9223372036854775807'
test_expr '-9223372036854775807 - 1' '-9223372036854775808'
test_expr '-9223372036854775808 + 0' '-9223372036854775808'
@@ -104,6 +120,10 @@ test_expr '-9223372036854775807 - 2' 'expr: overflow'
test_expr '-9223372036854775808 - 1' 'expr: overflow'
test_expr '-9223372036854775809 + 0' \
'expr: number "-9223372036854775809" is too small'
+test_expr '0 - -9223372036854775807' '9223372036854775807'
+test_expr '1 - -9223372036854775806' '9223372036854775807'
+test_expr '0 - -9223372036854775808' 'expr: overflow'
+test_expr '1 - -9223372036854775807' 'expr: overflow'
test_expr '-36854775808 - \( -9223372036854775807 - 1 \)' '9223372000000000000'
exit 0