aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGavin Howard <yzena.tech@gmail.com>2019-02-20 10:41:08 -0700
committerGavin Howard <yzena.tech@gmail.com>2019-02-20 10:41:08 -0700
commit7c715d660a28f66d39343c0d5813ddf80013a153 (patch)
treea03e405c9c49395dfdd8dd43ce56ad51debbc0d3 /tests
parent57a240ed273066c18c81104f00fbb01e7cbd0e2a (diff)
downloadplatform_external_bc-7c715d660a28f66d39343c0d5813ddf80013a153.tar.gz
platform_external_bc-7c715d660a28f66d39343c0d5813ddf80013a153.tar.bz2
platform_external_bc-7c715d660a28f66d39343c0d5813ddf80013a153.zip
Add read tests
Diffstat (limited to 'tests')
-rwxr-xr-xtests/all.sh1
-rw-r--r--tests/bc/read.txt1
-rw-r--r--tests/bc/read_errors.txt2
-rw-r--r--tests/bc/read_results.txt1
-rw-r--r--tests/dc/read.txt1
-rw-r--r--tests/dc/read_errors.txt2
-rw-r--r--tests/dc/read_results.txt1
-rwxr-xr-xtests/errors.sh115
-rw-r--r--tests/functions.sh93
-rwxr-xr-xtests/read.sh105
10 files changed, 215 insertions, 107 deletions
diff --git a/tests/all.sh b/tests/all.sh
index 980ddad3..7eb15b0a 100755
--- a/tests/all.sh
+++ b/tests/all.sh
@@ -85,6 +85,7 @@ done < "$testdir/$d/all.txt"
sh "$testdir/stdin.sh" "$d" "$exe" "$@"
sh "$testdir/scripts.sh" "$d" "$refs" "$generate_tests" "$exe" "$@"
+sh "$testdir/read.sh" "$d" "$exe" "$@"
sh "$testdir/errors.sh" "$d" "$exe" "$@"
num=100000000000000000000000000000000000000000000000000000000000000000000000000000
diff --git a/tests/bc/read.txt b/tests/bc/read.txt
new file mode 100644
index 00000000..8d2f0971
--- /dev/null
+++ b/tests/bc/read.txt
@@ -0,0 +1 @@
+1 + 1
diff --git a/tests/bc/read_errors.txt b/tests/bc/read_errors.txt
new file mode 100644
index 00000000..1990eaee
--- /dev/null
+++ b/tests/bc/read_errors.txt
@@ -0,0 +1,2 @@
+5+5;
+read()
diff --git a/tests/bc/read_results.txt b/tests/bc/read_results.txt
new file mode 100644
index 00000000..0cfbf088
--- /dev/null
+++ b/tests/bc/read_results.txt
@@ -0,0 +1 @@
+2
diff --git a/tests/dc/read.txt b/tests/dc/read.txt
new file mode 100644
index 00000000..9204d0a3
--- /dev/null
+++ b/tests/dc/read.txt
@@ -0,0 +1 @@
+3 4^pR
diff --git a/tests/dc/read_errors.txt b/tests/dc/read_errors.txt
new file mode 100644
index 00000000..dd2f324e
--- /dev/null
+++ b/tests/dc/read_errors.txt
@@ -0,0 +1,2 @@
+
+?
diff --git a/tests/dc/read_results.txt b/tests/dc/read_results.txt
new file mode 100644
index 00000000..d88e3136
--- /dev/null
+++ b/tests/dc/read_results.txt
@@ -0,0 +1 @@
+81
diff --git a/tests/errors.sh b/tests/errors.sh
index 12127b72..1735d447 100755
--- a/tests/errors.sh
+++ b/tests/errors.sh
@@ -16,87 +16,11 @@
# WARNING: Test files cannot have empty lines!
-die() {
-
- local d="$1"
- shift
-
- local msg="$1"
- shift
-
- local name="$1"
- shift
-
- local err="$1"
- shift
-
- printf '\n'
- printf '%s %s on test:\n' "$d" "$msg"
- printf '\n'
- printf ' %s\n' "$name"
- printf '\n'
- printf 'exiting...\n'
- exit "$err"
-}
-
-checkcrash() {
-
- local error="$1"
- shift
-
- local name="$1"
- shift
-
- if [ "$error" -gt 127 ]; then
- die "$d" "crashed" "$name" "$error"
- fi
-}
-
-checktest()
-{
- local error="$1"
- shift
-
- local name="$1"
- shift
-
- local out="$1"
- shift
-
- local exebase="$1"
- shift
-
- checkcrash "$error" "$name"
-
- if [ "$error" -eq 0 ]; then
- die "$d" "returned no error" "$name" 127
- fi
-
- if [ "$error" -eq 100 ]; then
-
- output=$(cat "$out")
- fatal_error="Fatal error"
-
- if [ "${output##*$fatal_error*}" ]; then
- printf "%s\n" "$output"
- die "$d" "had memory errors on a non-fatal error" "$name" "$error"
- fi
- fi
-
- if [ ! -s "$out" ]; then
- die "$d" "produced no error message" "$name" "$error"
- fi
-
- # Display the error messages if not directly running exe.
- # This allows the script to print valgrind output.
- if [ "$exebase" != "bc" -a "$exebase" != "dc" ]; then
- cat "$out"
- fi
-}
-
script="$0"
testdir=$(dirname "$script")
+. "$testdir/functions.sh"
+
if [ "$#" -eq 0 ]; then
printf 'usage: %s dir [exec args...]\n' "$script"
exit 1
@@ -117,6 +41,7 @@ out="$testdir/../.log_${d}_test.txt"
exebase=$(basename "$exe")
posix="posix_errors"
+read_errors="read_errors"
if [ "$d" = "bc" ]; then
opts="-l"
@@ -126,39 +51,15 @@ if [ "$d" = "bc" ]; then
else
opts="-x"
halt="q"
- read_call="?"
- read_expr="${read_call}"
fi
-printf 'Running %s read error...\n' "$d"
-
-read_test=$(printf '%s\n' "$read_expr")
-
-printf '%s' "$read_test" | "$exe" "$@" "$opts" 2> "$out" > /dev/null
-err="$?"
-
-checktest "$err" "$read_test" "$out" "$exebase"
-
-printf 'Running %s empty read...\n' "$d"
-
-read_test=$(printf '%s\n' "$read_call")
-
-printf '%s\n' "$read_test" | "$exe" "$@" "$opts" 2> "$out" > /dev/null
-err="$?"
-
-checktest "$err" "$read_test" "$out" "$exebase"
-
-printf 'Running %s read EOF...\n' "$d"
-
-read_test=$(printf '%s' "$read_call")
-
-printf '%s' "$read_test" | "$exe" "$@" "$opts" 2> "$out" > /dev/null
-err="$?"
-
-checktest "$err" "$read_test" "$out" "$exebase"
-
for testfile in $testdir/$d/*errors.txt; do
+ if [ -z "${testfile##*$read_errors*}" ]; then
+ # We don't test read errors here. Skip.
+ continue
+ fi
+
if [ -z "${testfile##*$posix*}" ]; then
line="last"
diff --git a/tests/functions.sh b/tests/functions.sh
new file mode 100644
index 00000000..dc900fba
--- /dev/null
+++ b/tests/functions.sh
@@ -0,0 +1,93 @@
+#! /bin/sh
+#
+# Copyright 2018 Gavin D. Howard
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+#
+
+die() {
+
+ local d="$1"
+ shift
+
+ local msg="$1"
+ shift
+
+ local name="$1"
+ shift
+
+ local err="$1"
+ shift
+
+ printf '\n'
+ printf '%s %s on test:\n' "$d" "$msg"
+ printf '\n'
+ printf ' %s\n' "$name"
+ printf '\n'
+ printf 'exiting...\n'
+ exit "$err"
+}
+
+checkcrash() {
+
+ local error="$1"
+ shift
+
+ local name="$1"
+ shift
+
+ if [ "$error" -gt 127 ]; then
+ die "$d" "crashed" "$name" "$error"
+ fi
+}
+
+checktest()
+{
+ local error="$1"
+ shift
+
+ local name="$1"
+ shift
+
+ local out="$1"
+ shift
+
+ local exebase="$1"
+ shift
+
+ checkcrash "$error" "$name"
+
+ if [ "$error" -eq 0 ]; then
+ die "$d" "returned no error" "$name" 127
+ fi
+
+ if [ "$error" -eq 100 ]; then
+
+ output=$(cat "$out")
+ fatal_error="Fatal error"
+
+ if [ "${output##*$fatal_error*}" ]; then
+ printf "%s\n" "$output"
+ die "$d" "had memory errors on a non-fatal error" "$name" "$error"
+ fi
+ fi
+
+ if [ ! -s "$out" ]; then
+ die "$d" "produced no error message" "$name" "$error"
+ fi
+
+ # Display the error messages if not directly running exe.
+ # This allows the script to print valgrind output.
+ if [ "$exebase" != "bc" -a "$exebase" != "dc" ]; then
+ cat "$out"
+ fi
+}
diff --git a/tests/read.sh b/tests/read.sh
new file mode 100755
index 00000000..815329a2
--- /dev/null
+++ b/tests/read.sh
@@ -0,0 +1,105 @@
+#! /bin/sh
+#
+# Copyright 2018 Gavin D. Howard
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+#
+
+set -e
+
+script="$0"
+testdir=$(dirname "$script")
+
+. "$testdir/functions.sh"
+
+if [ "$#" -lt 1 ]; then
+ printf 'usage: %s dir [exe [args...]]\n' "$0"
+ printf 'valid dirs are:\n'
+ printf '\n'
+ cat "$testdir/all.txt"
+ printf '\n'
+ exit 1
+fi
+
+d="$1"
+shift
+
+if [ "$#" -gt 0 ]; then
+ exe="$1"
+ shift
+else
+ exe="$testdir/../bin/$d"
+fi
+
+name="$testdir/$d/read.txt"
+results="$testdir/$d/read_results.txt"
+errors="$testdir/$d/read_errors.txt"
+
+out="$testdir/../.log_${d}_test.txt"
+
+exebase=$(basename "$exe")
+
+if [ "$d" = "bc" ]; then
+ options="-lq"
+ halt="halt"
+else
+ options="-x"
+ halt="q"
+fi
+
+if [ "$d" = "bc" ]; then
+ read_call="read()"
+ read_expr="${read_call}\n5+5;"
+else
+ read_call="?"
+ read_expr="${read_call}"
+fi
+
+printf 'Running %s read...\n' "$d"
+
+while read line; do
+
+ printf '%s\n%s\n' "$read_call" "$line" | "$exe" "$options" "$@" > "$out"
+ diff "$results" "$out"
+
+done < "$name"
+
+set +e
+
+printf 'Running %s read errors...\n' "$d"
+
+while read line; do
+
+ printf '%s\n%s\n' "$read_call" "$line" | "$exe" "$options" "$@" 2> "$out" > /dev/null
+ err="$?"
+
+ checktest "$err" "$line" "$out" "$exebase"
+
+done < "$errors"
+
+printf 'Running %s empty read...\n' "$d"
+
+read_test=$(printf '%s\n' "$read_call")
+
+printf '%s\n' "$read_test" | "$exe" "$@" "$opts" 2> "$out" > /dev/null
+err="$?"
+
+checktest "$err" "$read_test" "$out" "$exebase"
+
+printf 'Running %s read EOF...\n' "$d"
+
+read_test=$(printf '%s' "$read_call")
+
+printf '%s' "$read_test" | "$exe" "$@" "$opts" 2> "$out" > /dev/null
+err="$?"
+
+checktest "$err" "$read_test" "$out" "$exebase"