From a49402c53a99e6ab58c20921c80603d777666db4 Mon Sep 17 00:00:00 2001 From: Stephen Dolan Date: Sun, 5 May 2013 22:53:45 +0100 Subject: [PATCH] Combine the functionality of jq and jq_test One binary is much simpler. ./jq --run-tests now runs the tests. --- Makefile | 6 +++--- jq_test.c | 3 ++- main.c | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index aa2cc133..45f8ea75 100644 --- a/Makefile +++ b/Makefile @@ -27,15 +27,15 @@ main.c: version.gen.h JQ_SRC=parser.gen.c lexer.gen.c opcode.c bytecode.c compile.c execute.c builtin.c jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c jv_aux.c jv_alloc.c jq_test: CFLAGS += -DJQ_DEBUG=1 -jq_test: $(JQ_SRC) jq_test.c +jq_test: $(JQ_SRC) main.c jq_test.c $(CC) $(CFLAGS) $(CFLAGS_DEBUG) -o $@ $^ jq: CFLAGS += -O -DJQ_DEBUG=0 -jq: $(JQ_SRC) main.c +jq: $(JQ_SRC) main.c jq_test.c $(CC) $(CFLAGS) $(CFLAGS_OPT) -o $@ $^ test: jq_test - valgrind --error-exitcode=1 -q --leak-check=full ./jq_test >/dev/null + valgrind --error-exitcode=1 -q --leak-check=full ./jq_test --run-tests >/dev/null LIBRARIES=libjq BINARIES=jq jq_test diff --git a/jq_test.c b/jq_test.c index 8b5ee2c2..cbcbd8f5 100644 --- a/jq_test.c +++ b/jq_test.c @@ -10,7 +10,7 @@ static void run_jq_tests(); FILE* testdata; -int main(int argc, char* argv[]) { +int jq_testsuite(int argc, char* argv[]) { jv_test(); if (argc == 1) { testdata = fopen("testdata", "r"); @@ -26,6 +26,7 @@ int main(int argc, char* argv[]) { } run_jq_tests(); if (testdata != stdin) fclose(testdata); + return 0; } diff --git a/main.c b/main.c index ac80e4d0..06466d4e 100644 --- a/main.c +++ b/main.c @@ -11,6 +11,8 @@ #include "jv_alloc.h" #include "version.gen.h" +int jq_testsuite(int argc, char* argv[]); + static const char* progname; static void usage() { @@ -140,6 +142,10 @@ static int read_more(char* buf, size_t size) { int main(int argc, char* argv[]) { if (argc) progname = argv[0]; + if (argc > 1 && !strcmp(argv[1], "--run-tests")) { + return jq_testsuite(argc - 1, argv + 1); + } + const char* program = 0; input_filenames = jv_mem_alloc(sizeof(const char*) * argc); ninput_files = 0;