Move some module tests into all.test
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Nicolas Williams · committed by Nicolas Williams · parent ae7f8d6 · Browse files · 4 files·+43 added−63 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+43 added−63 removed
- tests:+30 added−54 removed
- other:+13 added−9 removed
Provenance
- Commit
86bc662- Tree
bf27c6c- Author
Nicolas Williams <nico@cryptonector.com>- Committer
Nicolas Williams <nico@cryptonector.com>- Parent
ae7f8d6
4 files changed+43 added−63 removed
modified:tests/all.test+25 added
1122 unmodified lines1123 bsearch(4)1124 [1,2,3]1125 -41126 1127+# module system1128+import "a" as foo; import "b" as bar; def fooa: foo::a; [fooa, bar::a, bar::b, foo::a]1129+null1130+["a","b","c","a"]1131+1132+import "c" as foo; [foo::a, foo::c]1133+null1134+[0,"acmehbah"]1135+1136+modulemeta1137+"c"1138+{"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"}]}1139+1140+%%FAIL1141+import "syntaxerror" as e; .1142+jq: error: syntax error, unexpected ';', expecting $end (Unix shell quoting issues?)1143+1144+%%FAIL1145+%::wat1146+jq: error: syntax error, unexpected '%', expecting $end (Unix shell quoting issues?)1147+1148+import "test_bind_order" as check; check::check1149+null1150+true1151+modified:tests/run+5 added-54 removed
8 unmodified lines9 VALGRIND=10 Q=11 fi12 13-cat $@ | $VALGRIND $Q ./jq --run-tests13+mods=$PWD/tests/modules14 15+cat $@ | $VALGRIND $Q ./jq -L "$mods" --run-tests16+17 set -x18 17-mods=$PWD/tests/modules18-19 clean=true20 d=21 clean () {22 if ! $clean; then166 unmodified lines189 clean=true190 191 ## Test library/module system192 193+# Check handling of ~/.jq; these can't move into jq_test.c yet because194+# they depend on $HOME195 if [ "`HOME="$mods" $VALGRIND $Q ./jq -nr fg`" != foobar ]; then196 echo "Bug #479 appears to be back" 1>&2197 exit 1198 fi2 unmodified lines201 echo "Binding too many defs into program" 1>&2202 exit 1203 fi204 203-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; then204- echo "Module system appears to be broken" 1>&2205- exit 1206-fi207-208-if ! $VALGRIND $Q ./jq -ner -L "$mods" 'import "c" as foo; [foo::a, foo::c] | . == [0,"acmehbah"]' > /dev/null; then209- echo "Module system appears to be broken" 1>&2210- exit 1211-fi212-213-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"}]}' ]; then214- echo "modulemeta builtin appears to be broken" 1>&2215- exit 1216-fi217- 218-if $VALGRIND ./jq -ner -L "$mods" 'import "syntaxerror" as e; .' > $d/out 2>&1; then219- echo "Module system appears to be broken" 1>&2220- exit 1221-fi222-if [ -n "$VALGRIND" ] && ! grep 'ERROR SUMMARY: 0 errors from 0 contexts' $d/out > /dev/null; then223- echo "Module system has memory errors when modules have syntax errors" 1>&2224- cat $d/out225- exit 1226-fi227-if ! grep '^jq: error: syntax error,' $d/out > /dev/null; then228- echo "Module system not detecting syntax errors in modules correctly" 1>&2229- exit 1230-fi231-232-if $VALGRIND ./jq -ner -L "$mods" '%::wat' > $d/out 2>&1 ||233- ! grep '^jq: error: syntax error,' $d/out > /dev/null; then234- echo "Syntax errors not detected?" 1>&2235- exit 1236-fi237-if [ -n "$VALGRIND" ] && ! grep 'ERROR SUMMARY: 0 errors from 0 contexts' $d/out > /dev/null; then238- echo "Memory errors when programs have syntax errors" 1>&2239- cat $d/out240- exit 1241-fi242-243-if ! $VALGRIND ./jq -ner -L "$mods" -f "$mods/test_bind_order.jq" > $d/out 2>&1; then244- echo "Import bind order is broken" 1>&2245- exit 1246-fi247-248-if [ -n "$VALGRIND" ] && ! grep 'ERROR SUMMARY: 0 errors from 0 contexts' $d/out > /dev/null; then249- echo "Memory errors when programs have syntax errors" 1>&2250- cat $d/out251- exit 1252-fi253-205 exit 0modified:jq_test.c+6 added-3 removed
7 unmodified lines8 static void jv_test();9 static void run_jq_tests();10 11 12-int jq_testsuite(int argc, char* argv[]) {12+int jq_testsuite(jv libdirs, int argc, char* argv[]) {13 FILE *testdata = stdin;14 jv_test();15 if (argc > 2) {16 testdata = fopen(argv[2], "r");1 unmodified line18 perror("fopen");19 exit(1);20 }21 }22- run_jq_tests(testdata);22+ run_jq_tests(libdirs, testdata);23 return 0;24 }25 26 static int skipline(const char* buf) {21 unmodified lines48 *(strchr(err_data->buf, '\n')) = '\0';49 jv_free(e);50 }51 52-static void run_jq_tests(FILE *testdata) {52+static void run_jq_tests(jv lib_dirs, FILE *testdata) {53 char prog[4096];54 char buf[4096];55 struct err_data err_msg;56 int tests = 0, passed = 0, invalid = 0;2 unmodified lines59 jq_state *jq = NULL;60 61 jq = jq_init();62 assert(jq);63+ if (jv_get_kind(lib_dirs) == JV_KIND_NULL)64+ lib_dirs = jv_array();65+ jq_set_attr(jq, jv_string("JQ_LIBRARY_PATH"), lib_dirs);66 67 while (1) {68 if (!fgets(prog, sizeof(prog), testdata)) break;69 lineno++;265 unmodified linesmodified:main.c+7 added-6 removed
11 unmodified lines12 #include "jv_alloc.h"13 #include "util.h"14 #include "version.h"15 16-int jq_testsuite(int argc, char* argv[]);16+int jq_testsuite(jv lib_dirs, int argc, char* argv[]);17 18 static const char* progname;19 20 /*71 unmodified lines92 UNBUFFERED_OUTPUT = 2048,93 EXIT_STATUS = 4096,94 IN_PLACE = 8192,95 SEQ = 16384,96+ RUN_TESTS = 32768,97 /* debugging only */97- DUMP_DISASM = 32768,98+ DUMP_DISASM = 65536,99 };100 static int options = 0;101 102 static int process(jq_state *jq, jv value, int flags, int dumpopts) {133 unmodified lines236 char *t = NULL;237 238 if (argc) progname = argv[0];239 239- if (argc > 1 && !strcmp(argv[1], "--run-tests")) {240- return jq_testsuite(argc, argv);241- }242-240 jq = jq_init();241 if (jq == NULL) {242 perror("malloc");243 ret = 2;173 unmodified lines417 printf("jq-%s\n", JQ_VERSION);418 ret = 0;419 goto out;420 }421+ if (isoption(argv[i], 0, "run-tests", &short_opts)) {422+ ret = jq_testsuite(lib_search_paths, argc - i, argv + i + 1);423+ goto out;424+ }425 426 // check for unknown options... if this argument was a short option427 if (strlen(argv[i]) != short_opts + 1) {428 fprintf(stderr, "%s: Unknown option %s\n", progname, argv[i]);187 unmodified lines