summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorNicolas Williams <nico@cryptonector.com>2017-02-22 23:01:56 -0600
committerNicolas Williams <nico@cryptonector.com>2017-02-26 16:34:56 -0600
commit8ea21a54adfa9e518f4855d2dc06ae3c0456d69c (patch)
tree1a4636dd292d73d5ac31827ffe9d63d7c0a5e0f2 /tests
parent6bac4ed059966007a6bc0e4a3639aca7d59f3b10 (diff)
Add `halt`, `halt_error` builtins (fix #386)
Diffstat (limited to 'tests')
-rwxr-xr-xtests/setup2
-rwxr-xr-xtests/shtest33
2 files changed, 35 insertions, 0 deletions
diff --git a/tests/setup b/tests/setup
index 94bcf1eb..9ce382ba 100755
--- a/tests/setup
+++ b/tests/setup
@@ -15,9 +15,11 @@ JQ=$JQBASEDIR/jq
if [ -z "${NO_VALGRIND-}" ] && which valgrind > /dev/null; then
VALGRIND="valgrind --error-exitcode=1 --leak-check=full \
--suppressions=$JQTESTDIR/onig.supp"
+ VG_EXIT0=--error-exitcode=0
Q=-q
else
VALGRIND=
+ VG_EXIT0=
Q=
fi
diff --git a/tests/shtest b/tests/shtest
index 9a17aea4..cec1fc59 100755
--- a/tests/shtest
+++ b/tests/shtest
@@ -211,4 +211,37 @@ if ! $VALGRIND $Q $JQ -L tests/modules -ne 'import "test_bind_order" as check; c
exit 1
fi
+## Halt
+
+if ! $VALGRIND $Q $JQ -n halt; then
+ echo "jq halt didn't work as expected" 1>&2
+ exit 1
+fi
+if $VALGRIND $Q $VG_EXIT0 $JQ -n 'halt_error(1)'; then
+ echo "jq halt_error(1) didn't work as expected" 1>&2
+ exit 1
+elif [ $? -ne 1 ]; then
+ echo "jq halt_error(1) had wrong error code" 1>&2
+ exit 1
+fi
+if $VALGRIND $Q $VG_EXIT0 $JQ -n 'halt_error(11)'; then
+ echo "jq halt_error(11) didn't work as expected" 1>&2
+ exit 1
+elif [ $? -ne 11 ]; then
+ echo "jq halt_error(11) had wrong error code" 1>&2
+ exit 1
+fi
+if [ -n "`$VALGRIND $Q $JQ -n 'halt_error(1)' 2>&1`" ]; then
+ echo "jq halt_error(1) had unexpected output" 1>&2
+ exit 1
+fi
+if [ -n "`$VALGRIND $Q $JQ -n '"xyz\n"|halt_error(1)' 2>/dev/null`" ]; then
+ echo "jq halt_error(1) had unexpected output on stdout" 1>&2
+ exit 1
+fi
+if [ "`$VALGRIND $Q $JQ -n '"xyz\n"|halt_error(1)' 2>&1`" != xyz ]; then
+ echo "jq halt_error(1) had unexpected output" 1>&2
+ exit 1
+fi
+
exit 0