diff --git a/src/jq_test.c b/src/jq_test.c index 2e574642f6..a75da18368 100644 --- a/src/jq_test.c +++ b/src/jq_test.c @@ -9,12 +9,12 @@ #include "jq.h" static void jv_test(); -static void run_jq_tests(jv, int, FILE *, int, int); +static void run_jq_tests(jv, jv, int, FILE *, int, int); #ifdef HAVE_PTHREAD static void run_jq_pthread_tests(); #endif -int jq_testsuite(jv libdirs, int verbose, int argc, char* argv[]) { +int jq_testsuite(jv progargs, jv libdirs, int verbose, int argc, char* argv[]) { FILE *testdata = stdin; int skip = -1; int take = -1; @@ -36,7 +36,7 @@ int jq_testsuite(jv libdirs, int verbose, int argc, char* argv[]) { } } } - run_jq_tests(libdirs, verbose, testdata, skip, take); + run_jq_tests(progargs, libdirs, verbose, testdata, skip, take); #ifdef HAVE_PTHREAD run_jq_pthread_tests(); #endif @@ -73,7 +73,7 @@ static void test_err_cb(void *data, jv e) { jv_free(e); } -static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int take) { +static void run_jq_tests(jv prog_args, jv lib_dirs, int verbose, FILE *testdata, int skip, int take) { char prog[4096] = {0}; char buf[4096]; struct err_data err_msg; @@ -133,7 +133,7 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int int pass = 1; tests++; printf("Test #%d: '%s' at line number %u\n", tests + tests_to_skip, prog, lineno); - int compiled = jq_compile(jq, prog); + int compiled = jq_compile_args(jq, prog, jv_copy(prog_args)); if (must_fail) { jq_set_error_cb(jq, NULL, NULL); diff --git a/src/main.c b/src/main.c index 832330802e..c2716810a9 100644 --- a/src/main.c +++ b/src/main.c @@ -38,7 +38,7 @@ extern void jv_tsd_dtoa_ctx_init(); #include "src/version.h" #include "src/config_opts.inc" -int jq_testsuite(jv lib_dirs, int verbose, int argc, char* argv[]); +int jq_testsuite(jv prog_args, jv lib_dirs, int verbose, int argc, char* argv[]); static const char* progname; @@ -573,7 +573,7 @@ int main(int argc, char* argv[]) { i++; // XXX Pass program_arguments, even a whole jq_state *, through; // could be useful for testing - ret = jq_testsuite(lib_search_paths, + ret = jq_testsuite(program_arguments, lib_search_paths, (options & DUMP_DISASM) || (jq_flags & JQ_DEBUG_TRACE), argc - i, argv + i); goto out; diff --git a/tests/jq.test b/tests/jq.test index 1502fbe058..2f5ab7d3cc 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -2176,3 +2176,15 @@ try ltrimstr("x") catch "x", try rtrimstr("x") catch "x" | "ok" try ["OK", setpath([[1]]; 1)] catch ["KO", .] [] ["KO","Cannot update field at array index of array"] + +$data|map(select(type=="object"))|map(.this|select(type=="string")) +null +["is a test"] + +$raw | try ({type:type,slice:.[16:22]}) catch . +null +{"type":"string","slice":"a test"} + +.+($data|map(select(.this|type=="string"))|.[0]) +{"foo":"bar"} +{"foo":"bar","this":"is a test","that":"is too"} \ No newline at end of file diff --git a/tests/jqtest b/tests/jqtest index 2420e0378f..2079b71e82 100755 --- a/tests/jqtest +++ b/tests/jqtest @@ -2,4 +2,4 @@ . "${0%/*}/setup" "$@" -$VALGRIND $Q $JQ -L "$mods" --run-tests $JQTESTDIR/jq.test +$VALGRIND $Q $JQ -L "$mods" --slurpfile data "$slurpfile" --rawfile raw "$rawfile" --run-tests $JQTESTDIR/jq.test diff --git a/tests/setup b/tests/setup index 935ab038c5..4dacd23a48 100755 --- a/tests/setup +++ b/tests/setup @@ -29,6 +29,8 @@ else fi mods=$JQTESTDIR/modules +rawfile=$mods/data.json +slurpfile=$mods/data.json clean=true d=