summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Williams <nico@cryptonector.com>2014-12-31 19:21:45 -0600
committerNicolas Williams <nico@cryptonector.com>2014-12-31 20:09:53 -0600
commit86bc662bd2b89f66e0ce60b0ab3df5de43701f50 (patch)
treebf27c6c10aea40e1b7764f5d6ac5d89eb60ab8c1
parentae7f8d6ab9d29bd72f462fdafa4d7a9270706d3b (diff)
Move some module tests into all.test
-rw-r--r--jq_test.c9
-rw-r--r--main.c13
-rw-r--r--tests/all.test25
-rwxr-xr-xtests/run59
4 files changed, 43 insertions, 63 deletions
diff --git a/jq_test.c b/jq_test.c
index bfdbec95..8b9588af 100644
--- a/jq_test.c
+++ b/jq_test.c
@@ -9,7 +9,7 @@ static void jv_test();
static void run_jq_tests();
-int jq_testsuite(int argc, char* argv[]) {
+int jq_testsuite(jv libdirs, int argc, char* argv[]) {
FILE *testdata = stdin;
jv_test();
if (argc > 2) {
@@ -19,7 +19,7 @@ int jq_testsuite(int argc, char* argv[]) {
exit(1);
}
}
- run_jq_tests(testdata);
+ run_jq_tests(libdirs, testdata);
return 0;
}
@@ -49,7 +49,7 @@ static void test_err_cb(void *data, jv e) {
jv_free(e);
}
-static void run_jq_tests(FILE *testdata) {
+static void run_jq_tests(jv lib_dirs, FILE *testdata) {
char prog[4096];
char buf[4096];
struct err_data err_msg;
@@ -60,6 +60,9 @@ static void run_jq_tests(FILE *testdata) {
jq = jq_init();
assert(jq);
+ if (jv_get_kind(lib_dirs) == JV_KIND_NULL)
+ lib_dirs = jv_array();
+ jq_set_attr(jq, jv_string("JQ_LIBRARY_PATH"), lib_dirs);
while (1) {
if (!fgets(prog, sizeof(prog), testdata)) break;
diff --git a/main.c b/main.c
index 65c4ced4..8a974b5a 100644
--- a/main.c
+++ b/main.c
@@ -13,7 +13,7 @@
#include "util.h"
#include "version.h"
-int jq_testsuite(int argc, char* argv[]);
+int jq_testsuite(jv lib_dirs, int argc, char* argv[]);
static const char* progname;
@@ -93,8 +93,9 @@ enum {
EXIT_STATUS = 4096,
IN_PLACE = 8192,
SEQ = 16384,
+ RUN_TESTS = 32768,
/* debugging only */
- DUMP_DISASM = 32768,
+ DUMP_DISASM = 65536,
};
static int options = 0;
@@ -236,10 +237,6 @@ int main(int argc, char* argv[]) {
if (argc) progname = argv[0];
- if (argc > 1 && !strcmp(argv[1], "--run-tests")) {
- return jq_testsuite(argc, argv);
- }
-
jq = jq_init();
if (jq == NULL) {
perror("malloc");
@@ -421,6 +418,10 @@ int main(int argc, char* argv[]) {
ret = 0;
goto out;
}
+ if (isoption(argv[i], 0, "run-tests", &short_opts)) {
+ ret = jq_testsuite(lib_search_paths, argc - i, argv + i + 1);
+ goto out;
+ }
// check for unknown options... if this argument was a short option
if (strlen(argv[i]) != short_opts + 1) {
diff --git a/tests/all.test b/tests/all.test
index 67b80763..cdb34d63 100644
--- a/tests/all.test
+++ b/tests/all.test
@@ -1124,3 +1124,28 @@ bsearch(4)
[1,2,3]
-4
+# module system
+import "a" as foo; import "b" as bar; def fooa: foo::a; [fooa, bar::a, bar::b, foo::a]
+null
+["a","b","c","a"]
+
+import "c" as foo; [foo::a, foo::c]
+null
+[0,"acmehbah"]
+
+modulemeta
+"c"
+{"whatever":null,"deps":[{"as":"foo","is_data":false,"relpath":"a"},{"search":"./","as":"d","is_data":false,"relpath":"d"},{"search":"./","as":"d2","is_data":false,"relpath":"d"},{"search":"./../lib/jq","as":"e","is_data":false,"relpath":"e"},{"search":"./../lib/jq","as":"f","is_data":false,"relpath":"f"},{"as":"d","is_data":true,"relpath":"data"}]}
+
+%%FAIL
+import "syntaxerror" as e; .
+jq: error: syntax error, unexpected ';', expecting $end (Unix shell quoting issues?)
+
+%%FAIL
+%::wat
+jq: error: syntax error, unexpected '%', expecting $end (Unix shell quoting issues?)
+
+import "test_bind_order" as check; check::check
+null
+true
+
diff --git a/tests/run b/tests/run
index bd227059..ae63baea 100755
--- a/tests/run
+++ b/tests/run
@@ -10,11 +10,11 @@ else
Q=
fi
-cat $@ | $VALGRIND $Q ./jq --run-tests
+mods=$PWD/tests/modules
-set -x
+cat $@ | $VALGRIND $Q ./jq -L "$mods" --run-tests
-mods=$PWD/tests/modules
+set -x
clean=true
d=
@@ -190,6 +190,8 @@ clean=true
## Test library/module system
+# Check handling of ~/.jq; these can't move into jq_test.c yet because
+# they depend on $HOME
if [ "`HOME="$mods" $VALGRIND $Q ./jq -nr fg`" != foobar ]; then
echo "Bug #479 appears to be back" 1>&2
exit 1
@@ -200,55 +202,4 @@ if [ `HOME="$mods" $VALGRIND $Q ./jq --debug-dump-disasm -n fg | grep '^[a-z]' |
exit 1
fi
-if ! $VALGRIND $Q ./jq -ner -L "$mods" 'import "a" as foo; import "b" as bar; def fooa: foo::a; [fooa, bar::a, bar::b, foo::a] | . == ["a","b","c","a"]' > /dev/null; then
- echo "Module system appears to be broken" 1>&2
- exit 1
-fi
-
-if ! $VALGRIND $Q ./jq -ner -L "$mods" 'import "c" as foo; [foo::a, foo::c] | . == [0,"acmehbah"]' > /dev/null; then
- echo "Module system appears to be broken" 1>&2
- exit 1
-fi
-
-if [ "`$VALGRIND $Q ./jq -cner -L "$mods" '\"c\" | modulemeta'`" != '{"whatever":null,"deps":[{"as":"foo","is_data":false,"relpath":"a"},{"search":"./","as":"d","is_data":false,"relpath":"d"},{"search":"./","as":"d2","is_data":false,"relpath":"d"},{"search":"./../lib/jq","as":"e","is_data":false,"relpath":"e"},{"search":"./../lib/jq","as":"f","is_data":false,"relpath":"f"},{"as":"d","is_data":true,"relpath":"data"}]}' ]; then
- echo "modulemeta builtin appears to be broken" 1>&2
- exit 1
-fi
-
-if $VALGRIND ./jq -ner -L "$mods" 'import "syntaxerror" as e; .' > $d/out 2>&1; then
- echo "Module system appears to be broken" 1>&2
- exit 1
-fi
-if [ -n "$VALGRIND" ] && ! grep 'ERROR SUMMARY: 0 errors from 0 contexts' $d/out > /dev/null; then
- echo "Module system has memory errors when modules have syntax errors" 1>&2
- cat $d/out
- exit 1
-fi
-if ! grep '^jq: 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 "$mods" '%::wat' > $d/out 2>&1 ||
- ! grep '^jq: error: syntax error,' $d/out > /dev/null; then
- echo "Syntax errors not detected?" 1>&2
- exit 1
-fi
-if [ -n "$VALGRIND" ] && ! grep 'ERROR SUMMARY: 0 errors from 0 contexts' $d/out > /dev/null; then
- echo "Memory errors when programs have syntax errors" 1>&2
- cat $d/out
- exit 1
-fi
-
-if ! $VALGRIND ./jq -ner -L "$mods" -f "$mods/test_bind_order.jq" > $d/out 2>&1; then
- echo "Import bind order is broken" 1>&2
- exit 1
-fi
-
-if [ -n "$VALGRIND" ] && ! grep 'ERROR SUMMARY: 0 errors from 0 contexts' $d/out > /dev/null; then
- echo "Memory errors when programs have syntax errors" 1>&2
- cat $d/out
- exit 1
-fi
-
exit 0