diff options
author | Lee Thompson <stagr.lee@gmail.com> | 2013-02-02 20:39:23 -0600 |
---|---|---|
committer | Lee Thompson <stagr.lee@gmail.com> | 2013-02-02 20:39:23 -0600 |
commit | c7725a8d4d905ff105b576fe351c245edd47d66f (patch) | |
tree | 71562f17b908a1da3a4aa5b0a37f429708d3e112 /jq_test.c | |
parent | dd70eeb29d2a2a735a4be3a3d810f391a8ef4e7e (diff) | |
parent | 925ec3751f3b407c17412b0fa04a84fe39c1e0b7 (diff) |
merging upstream stedolan changes
Diffstat (limited to 'jq_test.c')
-rw-r--r-- | jq_test.c | 41 |
1 files changed, 29 insertions, 12 deletions
@@ -8,9 +8,24 @@ static void jv_test(); static void run_jq_tests(); -int main() { +FILE* testdata; + +int main(int argc, char* argv[]) { jv_test(); + if (argc == 1) { + testdata = fopen("testdata", "r"); + } else if (argc == 2) { + if (!strcmp(argv[1], "-")) { + testdata = stdin; + } else { + testdata = fopen(argv[1], "r"); + } + } else { + printf("usage: %s OR cat testdata | %s - OR %s testdata\n", argv[0], argv[0], argv[0]); + return 127; + } run_jq_tests(); + if (testdata != stdin) fclose(testdata); } @@ -26,7 +41,7 @@ static int skipline(const char* buf) { static void run_jq_tests() { FILE* testdata = NULL; char buf[4096]; - int tests = 0, passed = 0; + int tests = 0, passed = 0, invalid = 0; testdata = fopen("testdata","r"); if ( NULL == testdata ) @@ -42,37 +57,41 @@ static void run_jq_tests() { while (1) { if (!fgets(buf, sizeof(buf), testdata)) break; if (skipline(buf)) continue; + if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0; printf("Testing %s\n", buf); int pass = 1; + tests++; struct bytecode* bc = jq_compile(buf); - assert(bc); + if (!bc) {invalid++; continue;} +#if JQ_DEBUG printf("Disassembly:\n"); dump_disassembly(2, bc); printf("\n"); +#endif fgets(buf, sizeof(buf), testdata); jv input = jv_parse(buf); - assert(jv_is_valid(input)); + if (!jv_is_valid(input)){ invalid++; continue; } jq_init(bc, input); while (fgets(buf, sizeof(buf), testdata)) { if (skipline(buf)) break; jv expected = jv_parse(buf); - assert(jv_is_valid(expected)); + if (!jv_is_valid(expected)){ invalid++; continue; } jv actual = jq_next(); if (!jv_is_valid(actual)) { jv_free(actual); - printf("Insufficient results\n"); + printf("*** Insufficient results\n"); pass = 0; break; } else if (!jv_equal(jv_copy(expected), jv_copy(actual))) { - printf("Expected "); + printf("*** Expected "); jv_dump(jv_copy(expected), 0); printf(", but got "); jv_dump(jv_copy(actual), 0); printf("\n"); pass = 0; } - jv as_string = jv_dump_string(jv_copy(expected), rand()); + jv as_string = jv_dump_string(jv_copy(expected), rand() & ~JV_PRINT_COLOUR); jv reparsed = jv_parse_sized(jv_string_value(as_string), jv_string_length(jv_copy(as_string))); assert(jv_equal(jv_copy(expected), jv_copy(reparsed))); jv_free(as_string); @@ -83,7 +102,7 @@ static void run_jq_tests() { if (pass) { jv extra = jq_next(); if (jv_is_valid(extra)) { - printf("Superfluous result: "); + printf("*** Superfluous result: "); jv_dump(extra, 0); printf("\n"); pass = 0; @@ -93,11 +112,9 @@ static void run_jq_tests() { } jq_teardown(); bytecode_free(bc); - tests++; passed+=pass; } - fclose(testdata); - printf("%d of %d tests passed\n", passed,tests); + printf("%d of %d tests passed (%d malformed)\n", passed,tests,invalid); if (passed != tests) exit(1); } |