2013-05-08 02:30:08 +01:00
#!/bin/sh
2014-07-13 19:00:37 -05:00
set -e
2013-12-13 01:07:26 +00:00
if which valgrind > /dev/null; then
2014-07-09 00:55:20 -04:00
VALGRIND='valgrind --error-exitcode=1 --leak-check=full --suppressions=tests/onig.supp'
2014-07-27 17:41:40 -05:00
Q=-q
2013-12-13 01:07:26 +00:00
else
VALGRIND=
2014-07-27 17:41:40 -05:00
Q=
2013-12-13 01:07:26 +00:00
fi
2014-07-27 17:41:40 -05:00
cat $@ | $VALGRIND $Q ./jq --run-tests
2014-07-13 19:00:37 -05:00
d=
trap '[ -n "$d" ] && rm -rf "$d"' EXIT
d=`mktemp -d -t || true`
if [ -z "$d" ]; then
echo "Your OS does not support mktemp(1) -d" 1>&2
exit 0
fi
cat > "$d/.jq" <<EOF
def foo: "baz";
def f: "wat";
def f: "foo";
def g: "bar";
def fg: f+g;
EOF
2014-07-09 00:55:20 -04:00
cat > "$d/a.jq" <<EOF
def a: "a";
EOF
cat > "$d/b.jq" <<EOF
def a: "b";
def b: "c";
EOF
cat > "$d/c.jq" <<EOF
import a as foo;
def a: 0;
def c: foo::a + "c";
EOF
cat > "$d/syntaxerror.jq" <<EOF
wat;
EOF
2014-07-27 17:41:40 -05:00
if [ "`HOME=$d $VALGRIND $Q ./jq -nr fg`" != foobar ]; then
2014-07-13 19:00:37 -05:00
echo "Bug #479 appears to be back" 1>&2
exit 1
fi
2014-07-27 17:41:40 -05:00
if [ `HOME=$d $VALGRIND $Q ./jq --debug-dump-disasm -n fg | grep '^[a-z]' | wc -l` -gt 3 ]; then
2014-07-13 19:00:37 -05:00
echo "Binding too many defs into program" 1>&2
exit 1
fi
2014-07-27 17:41:40 -05:00
if ! $VALGRIND $Q ./jq -ner -L $d 'import a as foo; import b as bar; import a as foobar; def fooa: foo::a; [fooa, bar::a, bar::b, foo::a, foobar::a] | . == ["a","b","c","a","a"]' > /dev/null; then
2014-07-09 00:55:20 -04:00
echo "Module system appears to be broken" 1>&2
exit 1
fi
2014-07-27 17:41:40 -05:00
if ! $VALGRIND $Q ./jq -ner -L $d 'import c as foo; [foo::a, foo::c] | . == [0,"ac"]' > /dev/null; then
2014-07-09 00:55:20 -04:00
echo "Module system appears to be broken" 1>&2
exit 1
fi
if $VALGRIND ./jq -ner -L $d 'import syntaxerror; .' > $d/out 2>&1; then
echo "Module system appears to be broken" 1>&2
exit 1
fi
2014-07-27 17:41:40 -05:00
if [ -n "$VALGRIND" ] && ! grep 'ERROR SUMMARY: 0 errors from 0 contexts' $d/out > /dev/null; then
2014-07-09 00:55:20 -04:00
echo "Module system has memory errors when modules have syntax errors" 1>&2
cat $d/out
exit 1
fi
if ! grep '^error: syntax error,' $d/out > /dev/null; then
echo "Module system not detecting syntax errors in modules correctly" 1>&2
exit 1
fi
if $VALGRIND ./jq -ner -L $d '%::wat' > $d/out 2>&1 ||
! grep '^error: syntax error,' $d/out > /dev/null; then
echo "Syntax errors not detected?" 1>&2
exit 1
fi
2014-07-27 17:41:40 -05:00
if [ -n "$VALGRIND" ] && ! grep 'ERROR SUMMARY: 0 errors from 0 contexts' $d/out > /dev/null; then
2014-07-09 00:55:20 -04:00
echo "Memory errors when programs have syntax errors" 1>&2
cat $d/out
exit 1
fi