Move some module tests into all.test
This commit is contained in:
1 parent
ae7f8d6ab9
commit
86bc662bd2
4 files changed
+43
-63
No files matched your search
@@ -9,7 +9,7 @@ static void jv_test();
|
|||||||
static void run_jq_tests();
|
static void run_jq_tests();
|
||||||
|
|
||||||
|
|
||||||
int jq_testsuite(int argc, char* argv[]) {
|
int jq_testsuite(jv libdirs, int argc, char* argv[]) {
|
||||||
FILE *testdata = stdin;
|
FILE *testdata = stdin;
|
||||||
jv_test();
|
jv_test();
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
@@ -19,7 +19,7 @@ int jq_testsuite(int argc, char* argv[]) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
run_jq_tests(testdata);
|
run_jq_tests(libdirs, testdata);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ static void test_err_cb(void *data, jv e) {
|
|||||||
jv_free(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 prog[4096];
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
struct err_data err_msg;
|
struct err_data err_msg;
|
||||||
@@ -60,6 +60,9 @@ static void run_jq_tests(FILE *testdata) {
|
|||||||
|
|
||||||
jq = jq_init();
|
jq = jq_init();
|
||||||
assert(jq);
|
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) {
|
while (1) {
|
||||||
if (!fgets(prog, sizeof(prog), testdata)) break;
|
if (!fgets(prog, sizeof(prog), testdata)) break;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "version.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;
|
static const char* progname;
|
||||||
|
|
||||||
@@ -93,8 +93,9 @@ enum {
|
|||||||
EXIT_STATUS = 4096,
|
EXIT_STATUS = 4096,
|
||||||
IN_PLACE = 8192,
|
IN_PLACE = 8192,
|
||||||
SEQ = 16384,
|
SEQ = 16384,
|
||||||
|
RUN_TESTS = 32768,
|
||||||
/* debugging only */
|
/* debugging only */
|
||||||
DUMP_DISASM = 32768,
|
DUMP_DISASM = 65536,
|
||||||
};
|
};
|
||||||
static int options = 0;
|
static int options = 0;
|
||||||
|
|
||||||
@@ -236,10 +237,6 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
if (argc) progname = argv[0];
|
if (argc) progname = argv[0];
|
||||||
|
|
||||||
if (argc > 1 && !strcmp(argv[1], "--run-tests")) {
|
|
||||||
return jq_testsuite(argc, argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
jq = jq_init();
|
jq = jq_init();
|
||||||
if (jq == NULL) {
|
if (jq == NULL) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
@@ -421,6 +418,10 @@ int main(int argc, char* argv[]) {
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
goto out;
|
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
|
// check for unknown options... if this argument was a short option
|
||||||
if (strlen(argv[i]) != short_opts + 1) {
|
if (strlen(argv[i]) != short_opts + 1) {
|
||||||
|
|||||||
@@ -1124,3 +1124,28 @@ bsearch(4)
|
|||||||
[1,2,3]
|
[1,2,3]
|
||||||
-4
|
-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
|
||||||
|
|
||||||
@@ -10,12 +10,12 @@ else
|
|||||||
Q=
|
Q=
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat $@ | $VALGRIND $Q ./jq --run-tests
|
mods=$PWD/tests/modules
|
||||||
|
|
||||||
|
cat $@ | $VALGRIND $Q ./jq -L "$mods" --run-tests
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
mods=$PWD/tests/modules
|
|
||||||
|
|
||||||
clean=true
|
clean=true
|
||||||
d=
|
d=
|
||||||
clean () {
|
clean () {
|
||||||
@@ -190,6 +190,8 @@ clean=true
|
|||||||
|
|
||||||
## Test library/module system
|
## 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
|
if [ "`HOME="$mods" $VALGRIND $Q ./jq -nr fg`" != foobar ]; then
|
||||||
echo "Bug #479 appears to be back" 1>&2
|
echo "Bug #479 appears to be back" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
@@ -200,55 +202,4 @@ if [ `HOME="$mods" $VALGRIND $Q ./jq --debug-dump-disasm -n fg | grep '^[a-z]' |
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
exit 0
|
||||||
Reference in new issue
Block a user