Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tests to use slurpfile and rawfile arguments #3123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/jq_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
2 changes: 1 addition & 1 deletion tests/jqtest
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions tests/setup
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ else
fi

mods=$JQTESTDIR/modules
rawfile=$mods/data.json
slurpfile=$mods/data.json

clean=true
d=
Expand Down
Loading