Add module directive, modulemeta builtin

Fix #425.
This commit is contained in:
Nicolas Williams committed 2014-08-14 03:26:26 -05:00
1 parent d654724fef
commit 1ba8c2cfa6
12 files changed
+265 -97

No files matched your search

+29 -9
View File
@@ -71,6 +71,12 @@ if [ $n -ne 5 ]; then
exit 1
fi
v=`scripts/version`
case "$v" in
*-*) v=next;;
*) true;;
esac
## Test library/module system
cat > "$d/.jq" <<EOF
@@ -81,22 +87,31 @@ def g: "bar";
def fg: f+g;
EOF
cat > "$d/a.jq" <<EOF
mkdir -p "$d/$v/b" "$d/any/c" "$d/any/syntaxerror"
cat > "$d/$v/a.jq" <<EOF
module a {version:1.7};
def a: "a";
EOF
cat > "$d/b.jq" <<EOF
cat > "$d/$v/b/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";
cat > "$d/any/c/d.jq" <<EOF
def meh: "meh";
EOF
cat > "$d/syntaxerror.jq" <<EOF
cat > "$d/any/c/c.jq" <<"EOF"
module c {whatever:null};
import a as foo;
import d as d {search:"$ORIGIN/"};
def a: 0;
def c: foo::a + "c" + d::meh;
EOF
cat > "$d/any/syntaxerror/syntaxerror.jq" <<EOF
wat;
EOF
@@ -110,16 +125,21 @@ if [ `HOME=$d $VALGRIND $Q ./jq --debug-dump-disasm -n fg | grep '^[a-z]' | wc -
exit 1
fi
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
if ! $VALGRIND $Q ./jq -ner -L $d 'import a as foo; import b as bar; import a; def fooa: foo::a; [fooa, bar::a, bar::b, foo::a, a] | . == ["a","b","c","a","a"]' > /dev/null; then
echo "Module system appears to be broken" 1>&2
exit 1
fi
if ! $VALGRIND $Q ./jq -ner -L $d 'import c as foo; [foo::a, foo::c] | . == [0,"ac"]' > /dev/null; then
if ! $VALGRIND $Q ./jq -ner -L $d 'import c as foo; [foo::a, foo::c] | . == [0,"acmeh"]' > /dev/null; then
echo "Module system appears to be broken" 1>&2
exit 1
fi
if [ "`$VALGRIND $Q ./jq -cner -L $d '\"c\" | modulemeta'`" != '{"whatever":null,"name":"c","deps":[{"as":"foo","name":"a"},{"search":"$ORIGIN/","as":"d","name":"d"}]}' ]; then
echo "modulemeta builtin 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