Skip to content
Myr

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

4 files+43 added−63 removed

modified:tests/all.test+25 added
1122 unmodified lines
1123bsearch(4)1124[1,2,3]1125-411261127# module system1128import "a" as foo; import "b" as bar; def fooa: foo::a; [fooa, bar::a, bar::b, foo::a]1129null1130["a","b","c","a"]11311132import "c" as foo; [foo::a, foo::c]1133null1134[0,"acmehbah"]11351136modulemeta1137"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"}]}11391140%%FAIL1141import "syntaxerror" as e; .1142jq: error: syntax error, unexpected ';', expecting $end (Unix shell quoting issues?)11431144%%FAIL1145%::wat1146jq: error: syntax error, unexpected '%', expecting $end (Unix shell quoting issues?)11471148import "test_bind_order" as check; check::check1149null1150true1151
modified:tests/run+5 added-54 removed
8 unmodified lines
9 VALGRIND=10 Q=11fi1213cat $@ | $VALGRIND $Q ./jq --run-tests13mods=$PWD/tests/modules1415cat $@ | $VALGRIND $Q ./jq -L "$mods" --run-tests1617set -x1817mods=$PWD/tests/modules1819clean=true20d=21clean () {22 if ! $clean; then
166 unmodified lines
189clean=true190191## Test library/module system192193# Check handling of ~/.jq; these can't move into jq_test.c yet because194# they depend on $HOME195if [ "`HOME="$mods" $VALGRIND $Q ./jq -nr fg`" != foobar ]; then196 echo "Bug #479 appears to be back" 1>&2197 exit 1198fi
2 unmodified lines
201 echo "Binding too many defs into program" 1>&2202 exit 1203fi204203if ! $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 1206fi207208if ! $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 1211fi212213if [ "`$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 1216fi217 218if $VALGRIND ./jq -ner -L "$mods" 'import "syntaxerror" as e; .' > $d/out 2>&1; then219 echo "Module system appears to be broken" 1>&2220 exit 1221fi222if [ -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 1226fi227if ! grep '^jq: error: syntax error,' $d/out > /dev/null; then228 echo "Module system not detecting syntax errors in modules correctly" 1>&2229 exit 1230fi231232if $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 1236fi237if [ -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 1241fi242243if ! $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 1246fi247248if [ -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 1252fi253205exit 0
modified:jq_test.c+6 added-3 removed
7 unmodified lines
8static void jv_test();9static void run_jq_tests();101112int jq_testsuite(int argc, char* argv[]) {12int 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 line
18 perror("fopen");19 exit(1);20 }21 }22 run_jq_tests(testdata);22 run_jq_tests(libdirs, testdata);23 return 0;24}2526static int skipline(const char* buf) {
21 unmodified lines
48 *(strchr(err_data->buf, '\n')) = '\0';49 jv_free(e);50}5152static void run_jq_tests(FILE *testdata) {52static 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 lines
59 jq_state *jq = NULL;6061 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);6667 while (1) {68 if (!fgets(prog, sizeof(prog), testdata)) break;69 lineno++;
265 unmodified lines
modified:main.c+7 added-6 removed
11 unmodified lines
12#include "jv_alloc.h"13#include "util.h"14#include "version.h"1516int jq_testsuite(int argc, char* argv[]);16int jq_testsuite(jv lib_dirs, int argc, char* argv[]);1718static const char* progname;1920/*
71 unmodified lines
92 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};100static int options = 0;101102static int process(jq_state *jq, jv value, int flags, int dumpopts) {
133 unmodified lines
236 char *t = NULL;237238 if (argc) progname = argv[0];239239 if (argc > 1 && !strcmp(argv[1], "--run-tests")) {240 return jq_testsuite(argc, argv);241 }242240 jq = jq_init();241 if (jq == NULL) {242 perror("malloc");243 ret = 2;
173 unmodified lines
417 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 }425426 // 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