summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRyoichi KATO <ryo1kato@gmail.com>2018-07-29 12:50:28 -0700
committerNico Williams <nico@cryptonector.com>2018-12-18 14:17:47 -0600
commit6d3d2750ec1e076cd86189b8fcfe1b760e2207c7 (patch)
tree41a6bbe62ae66aeeaa51804b32e870d12173d328 /tests
parent712330940b82eb6ee5afa5ed72df3a73fdf2a7b4 (diff)
fix --exit-code issues #1142 and #1139
* Set default error code to -4 in main(), Fixes #1142 * fix --exit-code with more than one object in input, Fixes #1139 - Return code 1 or 4 based on last output, not last input.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/shtest25
1 files changed, 23 insertions, 2 deletions
diff --git a/tests/shtest b/tests/shtest
index 86fec33e..fc2ef152 100755
--- a/tests/shtest
+++ b/tests/shtest
@@ -96,14 +96,20 @@ cmp $d/out $d/expected
cat > $d/expected <<EOF
ignoring parse error: Unfinished abandoned text at EOF at line 1, column 4
EOF
-printf '"foo' | $JQ -ce --seq . > $d/out 2>&1
+printf '"foo' | $JQ -c --seq . > $d/out 2>&1
+cmp $d/out $d/expected
+
+# with -e option should give 4 here as there's no valid output after
+# ignoring parse errors with --seq.
+printf '"foo' | $JQ -ce --seq . > $d/out 2>&1 || ret=$?
+[ $ret -eq 4 ]
cmp $d/out $d/expected
# Numeric values truncated by EOF are ignored
cat > $d/expected <<EOF
ignoring parse error: Unfinished abandoned text at EOF at line 1, column 1
EOF
-printf '1' | $JQ -ce --seq . > $d/out 2>&1
+printf '1' | $JQ -c --seq . > $d/out 2>&1
cmp $d/out $d/expected
cat > $d/expected <<EOF
@@ -115,6 +121,21 @@ if printf '1\n' | $JQ -cen --seq '[inputs] == []' >/dev/null 2> $d/out; then
fi
cmp $d/out $d/expected
+
+## Test --exit-status
+data='{"i": 1}\n{"i": 2}\n{"i": 3}\n'
+echo "$data" | $JQ --exit-status 'select(.i==1)' > /dev/null 2>&1
+echo "$data" | $JQ --exit-status 'select(.i==2)' > /dev/null 2>&1
+echo "$data" | $JQ --exit-status 'select(.i==3)' > /dev/null 2>&1
+ret=0
+echo "$data" | $JQ --exit-status 'select(.i==4)' > /dev/null 2>&1 || ret=$?
+[ $ret -eq 4 ]
+ret=0
+echo "$data" | $JQ --exit-status 'select(.i==2) | false' > /dev/null 2>&1 || ret=$?
+[ $ret -eq 1 ]
+echo "$data" | $JQ --exit-status 'select(.i==2) | true' > /dev/null 2>&1
+
+
# Regression test for #951
printf '"a\n' > $d/input
if $VALGRIND $Q $JQ -e . $d/input; then