Add matrix to test all available GH Actions images
This commit is contained in:
2 files changed
+155
-117
No files matched your search
+30
-46
@@ -1,21 +1,18 @@
|
|||||||
name: CI
|
name: CI
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
tags:
|
|
||||||
- "v*"
|
|
||||||
pull_request:
|
pull_request:
|
||||||
jobs:
|
jobs:
|
||||||
linux:
|
linux:
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
arch: [x86_64]
|
compiler: [gcc, clang]
|
||||||
include:
|
image: [ubuntu-20.04, ubuntu-22.04]
|
||||||
- arch: x86_64
|
runs-on: ${{ matrix.image }}
|
||||||
suffix: amd64
|
env:
|
||||||
|
CC: ${{ matrix.compiler }}
|
||||||
|
SUFFIX: linux-${{ matrix.image}}-${{ matrix.compiler }}
|
||||||
steps:
|
steps:
|
||||||
- name: Clone repository
|
- name: Clone repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
@@ -32,8 +29,6 @@ jobs:
|
|||||||
gdb \
|
gdb \
|
||||||
python3
|
python3
|
||||||
- name: Build
|
- name: Build
|
||||||
env:
|
|
||||||
CC: clang -arch ${{ matrix.arch }}
|
|
||||||
run: |
|
run: |
|
||||||
autoreconf -fi
|
autoreconf -fi
|
||||||
./configure --disable-dependency-tracking \
|
./configure --disable-dependency-tracking \
|
||||||
@@ -43,18 +38,15 @@ jobs:
|
|||||||
--with-oniguruma=builtin \
|
--with-oniguruma=builtin \
|
||||||
YACC="$(which bison) -y"
|
YACC="$(which bison) -y"
|
||||||
make
|
make
|
||||||
make dist
|
cp jq jq-${{ env.SUFFIX }}
|
||||||
cp jq jq-linux-${{ matrix.suffix }}
|
|
||||||
- name: Test
|
- name: Test
|
||||||
env:
|
|
||||||
CC: clang -arch ${{ matrix.arch }}
|
|
||||||
run: |
|
run: |
|
||||||
make check
|
make check
|
||||||
- name: Upload Test Logs
|
- name: Upload Test Logs
|
||||||
if: ${{ failure() }}
|
if: ${{ failure() }}
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: test-logs-linux-${{ matrix.arch }}
|
name: test-logs-${{ env.SUFFIX }}
|
||||||
retention-days: 7
|
retention-days: 7
|
||||||
path: |
|
path: |
|
||||||
test-suite.log
|
test-suite.log
|
||||||
@@ -62,20 +54,21 @@ jobs:
|
|||||||
- name: Upload Artifacts
|
- name: Upload Artifacts
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: jq-linux-${{ matrix.suffix }}
|
name: jq-${{ env.SUFFIX }}
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
retention-days: 7
|
retention-days: 7
|
||||||
path: |
|
path: |
|
||||||
jq-linux-${{ matrix.suffix }}
|
jq-${{ env.SUFFIX }}
|
||||||
macos:
|
macos:
|
||||||
runs-on: macos-13
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
arch: [x86_64]
|
compiler: [gcc, clang]
|
||||||
include:
|
image: [macos-11, macos-12, macos-13]
|
||||||
- arch: x86_64
|
runs-on: ${{ matrix.image }}
|
||||||
suffix: amd64
|
env:
|
||||||
|
CC: ${{ matrix.compiler }}
|
||||||
|
SUFFIX: macos-${{ matrix.image}}-${{ matrix.compiler }}
|
||||||
steps:
|
steps:
|
||||||
- name: Clone repository
|
- name: Clone repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
@@ -92,8 +85,6 @@ jobs:
|
|||||||
bison
|
bison
|
||||||
sed -i.bak '/^AM_INIT_AUTOMAKE(\[-Wno-portability 1\.14\])$/s/14/11/' modules/oniguruma/configure.ac
|
sed -i.bak '/^AM_INIT_AUTOMAKE(\[-Wno-portability 1\.14\])$/s/14/11/' modules/oniguruma/configure.ac
|
||||||
- name: Build
|
- name: Build
|
||||||
env:
|
|
||||||
CC: clang -arch ${{ matrix.arch }}
|
|
||||||
run: |
|
run: |
|
||||||
autoreconf -fi
|
autoreconf -fi
|
||||||
./configure --disable-dependency-tracking \
|
./configure --disable-dependency-tracking \
|
||||||
@@ -103,18 +94,15 @@ jobs:
|
|||||||
--with-oniguruma=builtin \
|
--with-oniguruma=builtin \
|
||||||
YACC="$(brew --prefix)/opt/bison/bin/bison -y"
|
YACC="$(brew --prefix)/opt/bison/bin/bison -y"
|
||||||
make
|
make
|
||||||
make dist
|
cp jq jq-${{ env.SUFFIX }}
|
||||||
cp jq jq-macos-${{ matrix.suffix }}
|
|
||||||
- name: Test
|
- name: Test
|
||||||
env:
|
|
||||||
CC: clang -arch ${{ matrix.arch }}
|
|
||||||
run: |
|
run: |
|
||||||
make check
|
make check
|
||||||
- name: Upload Test Logs
|
- name: Upload Test Logs
|
||||||
if: ${{ failure() }}
|
if: ${{ failure() }}
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: test-logs-macos-${{ matrix.arch }}
|
name: test-logs-${{ env.SUFFIX }}
|
||||||
retention-days: 7
|
retention-days: 7
|
||||||
path: |
|
path: |
|
||||||
test-suite.log
|
test-suite.log
|
||||||
@@ -122,20 +110,21 @@ jobs:
|
|||||||
- name: Upload Artifacts
|
- name: Upload Artifacts
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: jq-macos-${{ matrix.suffix }}
|
name: jq-${{ env.SUFFIX }}
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
retention-days: 7
|
retention-days: 7
|
||||||
path: |
|
path: |
|
||||||
jq-macos-${{ matrix.suffix }}
|
jq-${{ env.SUFFIX }}
|
||||||
windows:
|
windows:
|
||||||
runs-on: windows-latest
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
arch: [x86_64]
|
compiler: [gcc]
|
||||||
include:
|
image: [windows-2019, windows-2022]
|
||||||
- arch: x86_64
|
runs-on: ${{ matrix.image }}
|
||||||
suffix: win64
|
env:
|
||||||
|
CC: ${{ matrix.compiler }}
|
||||||
|
SUFFIX: windows-${{ matrix.image}}-${{ matrix.compiler }}
|
||||||
steps:
|
steps:
|
||||||
- name: Clone repository
|
- name: Clone repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
@@ -155,8 +144,6 @@ jobs:
|
|||||||
flex
|
flex
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: msys2 {0}
|
shell: msys2 {0}
|
||||||
env:
|
|
||||||
CC: clang -arch ${{ matrix.arch }}
|
|
||||||
run: |
|
run: |
|
||||||
autoreconf -fi
|
autoreconf -fi
|
||||||
./configure --disable-dependency-tracking \
|
./configure --disable-dependency-tracking \
|
||||||
@@ -169,8 +156,7 @@ jobs:
|
|||||||
--enable-all-static \
|
--enable-all-static \
|
||||||
YACC="$(which bison) -y"
|
YACC="$(which bison) -y"
|
||||||
make
|
make
|
||||||
make dist
|
cp jq.exe jq-${{ env.SUFFIX }}.exe
|
||||||
cp jq.exe jq-windows-${{ matrix.suffix }}.exe
|
|
||||||
- name: Test
|
- name: Test
|
||||||
shell: msys2 {0}
|
shell: msys2 {0}
|
||||||
run: |
|
run: |
|
||||||
@@ -180,10 +166,8 @@ jobs:
|
|||||||
- name: Upload Test Logs
|
- name: Upload Test Logs
|
||||||
if: ${{ failure() }}
|
if: ${{ failure() }}
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
env:
|
|
||||||
CC: clang -arch ${{ matrix.arch }}
|
|
||||||
with:
|
with:
|
||||||
name: test-logs-windows-${{ matrix.arch }}
|
name: test-logs-${{ env.SUFFIX }}
|
||||||
retention-days: 7
|
retention-days: 7
|
||||||
path: |
|
path: |
|
||||||
test-suite.log
|
test-suite.log
|
||||||
@@ -191,11 +175,11 @@ jobs:
|
|||||||
- name: Upload Artifacts
|
- name: Upload Artifacts
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: jq-windows-${{ matrix.suffix }}
|
name: jq-${{ env.SUFFIX }}
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
retention-days: 7
|
retention-days: 7
|
||||||
path: |
|
path: |
|
||||||
jq-windows-${{ matrix.suffix }}.exe
|
jq-${{ env.SUFFIX }}.exe
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
|
|||||||
+125
-71
@@ -8,23 +8,31 @@
|
|||||||
static void jv_test();
|
static void jv_test();
|
||||||
static void run_jq_tests(jv, int, FILE *, int, int);
|
static void run_jq_tests(jv, int, FILE *, int, int);
|
||||||
|
|
||||||
|
int jq_testsuite(jv libdirs, int verbose, int argc, char *argv[])
|
||||||
int jq_testsuite(jv libdirs, int verbose, int argc, char* argv[]) {
|
{
|
||||||
FILE *testdata = stdin;
|
FILE *testdata = stdin;
|
||||||
int skip = -1;
|
int skip = -1;
|
||||||
int take = -1;
|
int take = -1;
|
||||||
jv_test();
|
jv_test();
|
||||||
if (argc > 0) {
|
if (argc > 0)
|
||||||
for(int i = 0; i < argc; i++) {
|
{
|
||||||
if (!strcmp(argv[i], "--skip")) {
|
for (int i = 0; i < argc; i++)
|
||||||
skip = atoi(argv[i+1]);
|
{
|
||||||
|
if (!strcmp(argv[i], "--skip"))
|
||||||
|
{
|
||||||
|
skip = atoi(argv[i + 1]);
|
||||||
i++;
|
i++;
|
||||||
} else if (!strcmp(argv[i], "--take")) {
|
}
|
||||||
take = atoi(argv[i+1]);
|
else if (!strcmp(argv[i], "--take"))
|
||||||
|
{
|
||||||
|
take = atoi(argv[i + 1]);
|
||||||
i++;
|
i++;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
testdata = fopen(argv[i], "r");
|
testdata = fopen(argv[i], "r");
|
||||||
if (!testdata) {
|
if (!testdata)
|
||||||
|
{
|
||||||
perror("fopen");
|
perror("fopen");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -35,26 +43,33 @@ int jq_testsuite(jv libdirs, int verbose, int argc, char* argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int skipline(const char* buf) {
|
static int skipline(const char *buf)
|
||||||
|
{
|
||||||
int p = 0;
|
int p = 0;
|
||||||
while (buf[p] == ' ' || buf[p] == '\t') p++;
|
while (buf[p] == ' ' || buf[p] == '\t')
|
||||||
if (buf[p] == '#' || buf[p] == '\n' || buf[p] == 0) return 1;
|
p++;
|
||||||
|
if (buf[p] == '#' || buf[p] == '\n' || buf[p] == 0)
|
||||||
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int checkerrormsg(const char* buf) {
|
static int checkerrormsg(const char *buf)
|
||||||
|
{
|
||||||
return strcmp(buf, "%%FAIL\n") == 0;
|
return strcmp(buf, "%%FAIL\n") == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int checkfail(const char* buf) {
|
static int checkfail(const char *buf)
|
||||||
|
{
|
||||||
return strcmp(buf, "%%FAIL\n") == 0 || strcmp(buf, "%%FAIL IGNORE MSG\n") == 0;
|
return strcmp(buf, "%%FAIL\n") == 0 || strcmp(buf, "%%FAIL IGNORE MSG\n") == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct err_data {
|
struct err_data
|
||||||
|
{
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
};
|
};
|
||||||
|
|
||||||
static void test_err_cb(void *data, jv e) {
|
static void test_err_cb(void *data, jv e)
|
||||||
|
{
|
||||||
struct err_data *err_data = data;
|
struct err_data *err_data = data;
|
||||||
if (jv_get_kind(e) != JV_KIND_STRING)
|
if (jv_get_kind(e) != JV_KIND_STRING)
|
||||||
e = jv_dump_string(e, JV_PRINT_INVALID);
|
e = jv_dump_string(e, JV_PRINT_INVALID);
|
||||||
@@ -65,7 +80,8 @@ static void test_err_cb(void *data, jv e) {
|
|||||||
jv_free(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 lib_dirs, int verbose, FILE *testdata, int skip, int take)
|
||||||
|
{
|
||||||
char prog[4096];
|
char prog[4096];
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
struct err_data err_msg;
|
struct err_data err_msg;
|
||||||
@@ -84,40 +100,52 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
|
|||||||
lib_dirs = jv_array();
|
lib_dirs = jv_array();
|
||||||
jq_set_attr(jq, jv_string("JQ_LIBRARY_PATH"), lib_dirs);
|
jq_set_attr(jq, jv_string("JQ_LIBRARY_PATH"), lib_dirs);
|
||||||
|
|
||||||
while (1) {
|
while (1)
|
||||||
if (!fgets(prog, sizeof(prog), testdata)) break;
|
{
|
||||||
|
if (!fgets(prog, sizeof(prog), testdata))
|
||||||
|
break;
|
||||||
lineno++;
|
lineno++;
|
||||||
if (skipline(prog)) continue;
|
if (skipline(prog))
|
||||||
if (checkfail(prog)) {
|
continue;
|
||||||
|
if (checkfail(prog))
|
||||||
|
{
|
||||||
must_fail = 1;
|
must_fail = 1;
|
||||||
check_msg = checkerrormsg(prog);
|
check_msg = checkerrormsg(prog);
|
||||||
jq_set_error_cb(jq, test_err_cb, &err_msg);
|
jq_set_error_cb(jq, test_err_cb, &err_msg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (prog[strlen(prog)-1] == '\n') prog[strlen(prog)-1] = 0;
|
if (prog[strlen(prog) - 1] == '\n')
|
||||||
|
prog[strlen(prog) - 1] = 0;
|
||||||
|
|
||||||
if (skip > 0) {
|
if (skip > 0)
|
||||||
|
{
|
||||||
skip--;
|
skip--;
|
||||||
|
|
||||||
// skip past test data
|
// skip past test data
|
||||||
while (fgets(buf, sizeof(buf), testdata)) {
|
while (fgets(buf, sizeof(buf), testdata))
|
||||||
|
{
|
||||||
lineno++;
|
lineno++;
|
||||||
if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n'))
|
if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n'))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
must_fail = 0;
|
must_fail = 0;
|
||||||
check_msg = 0;
|
check_msg = 0;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
} else if (skip == 0) {
|
}
|
||||||
|
else if (skip == 0)
|
||||||
|
{
|
||||||
printf("Skipped %d tests\n", tests_to_skip);
|
printf("Skipped %d tests\n", tests_to_skip);
|
||||||
skip = -1;
|
skip = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (take > 0) {
|
if (take > 0)
|
||||||
|
{
|
||||||
take--;
|
take--;
|
||||||
} else if (take == 0) {
|
}
|
||||||
|
else if (take == 0)
|
||||||
|
{
|
||||||
printf("Hit the number of tests limit (%d), breaking\n", tests_to_take);
|
printf("Hit the number of tests limit (%d), breaking\n", tests_to_take);
|
||||||
take = -1;
|
take = -1;
|
||||||
break;
|
break;
|
||||||
@@ -128,22 +156,32 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
|
|||||||
printf("Test #%d: '%s' at line number %u\n", tests + tests_to_skip, prog, lineno);
|
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(jq, prog);
|
||||||
|
|
||||||
if (must_fail) {
|
if (must_fail)
|
||||||
|
{
|
||||||
jq_set_error_cb(jq, NULL, NULL);
|
jq_set_error_cb(jq, NULL, NULL);
|
||||||
if (!fgets(buf, sizeof(buf), testdata)) { invalid++; break; }
|
if (!fgets(buf, sizeof(buf), testdata))
|
||||||
|
{
|
||||||
|
invalid++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
lineno++;
|
lineno++;
|
||||||
if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
|
if (buf[strlen(buf) - 1] == '\n')
|
||||||
if (compiled) {
|
buf[strlen(buf) - 1] = 0;
|
||||||
|
if (compiled)
|
||||||
|
{
|
||||||
printf("*** Test program compiled that should not have at line %u: %s\n", lineno, prog);
|
printf("*** Test program compiled that should not have at line %u: %s\n", lineno, prog);
|
||||||
must_fail = 0;
|
must_fail = 0;
|
||||||
check_msg = 0;
|
check_msg = 0;
|
||||||
invalid++;
|
invalid++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (check_msg && strcmp(buf, err_msg.buf) != 0) {
|
if (check_msg && strcmp(buf, err_msg.buf) != 0)
|
||||||
|
{
|
||||||
printf("*** Erroneous test program failed with wrong message (%s) at line %u: %s\n", err_msg.buf, lineno, prog);
|
printf("*** Erroneous test program failed with wrong message (%s) at line %u: %s\n", err_msg.buf, lineno, prog);
|
||||||
invalid++;
|
invalid++;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
passed++;
|
passed++;
|
||||||
}
|
}
|
||||||
must_fail = 0;
|
must_fail = 0;
|
||||||
@@ -151,48 +189,62 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!compiled) {
|
if (!compiled)
|
||||||
|
{
|
||||||
printf("*** Test program failed to compile at line %u: %s\n", lineno, prog);
|
printf("*** Test program failed to compile at line %u: %s\n", lineno, prog);
|
||||||
invalid++;
|
invalid++;
|
||||||
// skip past test data
|
// skip past test data
|
||||||
while (fgets(buf, sizeof(buf), testdata)) {
|
while (fgets(buf, sizeof(buf), testdata))
|
||||||
|
{
|
||||||
lineno++;
|
lineno++;
|
||||||
if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n'))
|
if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n'))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (verbose) {
|
if (verbose)
|
||||||
|
{
|
||||||
printf("Disassembly:\n");
|
printf("Disassembly:\n");
|
||||||
jq_dump_disassembly(jq, 2);
|
jq_dump_disassembly(jq, 2);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
if (!fgets(buf, sizeof(buf), testdata)) { invalid++; break; }
|
if (!fgets(buf, sizeof(buf), testdata))
|
||||||
|
{
|
||||||
|
invalid++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
lineno++;
|
lineno++;
|
||||||
jv input = jv_parse(buf);
|
jv input = jv_parse(buf);
|
||||||
if (!jv_is_valid(input)) {
|
if (!jv_is_valid(input))
|
||||||
|
{
|
||||||
printf("*** Input is invalid on line %u: %s\n", lineno, buf);
|
printf("*** Input is invalid on line %u: %s\n", lineno, buf);
|
||||||
invalid++;
|
invalid++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
jq_start(jq, input, verbose ? JQ_DEBUG_TRACE : 0);
|
jq_start(jq, input, verbose ? JQ_DEBUG_TRACE : 0);
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf), testdata)) {
|
while (fgets(buf, sizeof(buf), testdata))
|
||||||
|
{
|
||||||
lineno++;
|
lineno++;
|
||||||
if (skipline(buf)) break;
|
if (skipline(buf))
|
||||||
|
break;
|
||||||
jv expected = jv_parse(buf);
|
jv expected = jv_parse(buf);
|
||||||
if (!jv_is_valid(expected)) {
|
if (!jv_is_valid(expected))
|
||||||
|
{
|
||||||
printf("*** Expected result is invalid on line %u: %s\n", lineno, buf);
|
printf("*** Expected result is invalid on line %u: %s\n", lineno, buf);
|
||||||
invalid++;
|
invalid++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
jv actual = jq_next(jq);
|
jv actual = jq_next(jq);
|
||||||
if (!jv_is_valid(actual)) {
|
if (!jv_is_valid(actual))
|
||||||
|
{
|
||||||
jv_free(actual);
|
jv_free(actual);
|
||||||
printf("*** Insufficient results for test at line number %u: %s\n", lineno, prog);
|
printf("*** Insufficient results for test at line number %u: %s\n", lineno, prog);
|
||||||
pass = 0;
|
pass = 0;
|
||||||
break;
|
break;
|
||||||
} else if (!jv_equal(jv_copy(expected), jv_copy(actual))) {
|
}
|
||||||
|
else if (!jv_equal(jv_copy(expected), jv_copy(actual)))
|
||||||
|
{
|
||||||
printf("*** Expected ");
|
printf("*** Expected ");
|
||||||
jv_dump(jv_copy(expected), 0);
|
jv_dump(jv_copy(expected), 0);
|
||||||
printf(", but got ");
|
printf(", but got ");
|
||||||
@@ -200,7 +252,7 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
|
|||||||
printf(" for test at line number %u: %s\n", lineno, prog);
|
printf(" for test at line number %u: %s\n", lineno, prog);
|
||||||
pass = 0;
|
pass = 0;
|
||||||
}
|
}
|
||||||
jv as_string = jv_dump_string(jv_copy(expected), rand() & ~(JV_PRINT_COLOR|JV_PRINT_REFCOUNT));
|
jv as_string = jv_dump_string(jv_copy(expected), rand() & ~(JV_PRINT_COLOR | JV_PRINT_REFCOUNT));
|
||||||
jv reparsed = jv_parse_sized(jv_string_value(as_string), jv_string_length_bytes(jv_copy(as_string)));
|
jv reparsed = jv_parse_sized(jv_string_value(as_string), jv_string_length_bytes(jv_copy(as_string)));
|
||||||
assert(jv_equal(jv_copy(expected), jv_copy(reparsed)));
|
assert(jv_equal(jv_copy(expected), jv_copy(reparsed)));
|
||||||
jv_free(as_string);
|
jv_free(as_string);
|
||||||
@@ -208,40 +260,47 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata, int skip, int
|
|||||||
jv_free(expected);
|
jv_free(expected);
|
||||||
jv_free(actual);
|
jv_free(actual);
|
||||||
}
|
}
|
||||||
if (pass) {
|
if (pass)
|
||||||
|
{
|
||||||
jv extra = jq_next(jq);
|
jv extra = jq_next(jq);
|
||||||
if (jv_is_valid(extra)) {
|
if (jv_is_valid(extra))
|
||||||
|
{
|
||||||
printf("*** Superfluous result: ");
|
printf("*** Superfluous result: ");
|
||||||
jv_dump(extra, 0);
|
jv_dump(extra, 0);
|
||||||
printf(" for test at line number %u, %s\n", lineno, prog);
|
printf(" for test at line number %u, %s\n", lineno, prog);
|
||||||
pass = 0;
|
pass = 0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
jv_free(extra);
|
jv_free(extra);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
passed+=pass;
|
passed += pass;
|
||||||
}
|
}
|
||||||
jq_teardown(&jq);
|
jq_teardown(&jq);
|
||||||
|
|
||||||
int total_skipped = tests_to_skip;
|
int total_skipped = tests_to_skip;
|
||||||
|
|
||||||
if (skip > 0) {
|
if (skip > 0)
|
||||||
|
{
|
||||||
total_skipped = tests_to_skip - skip;
|
total_skipped = tests_to_skip - skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%d of %d tests passed (%d malformed, %d skipped)\n",
|
printf("%d of %d tests passed (%d malformed, %d skipped)\n",
|
||||||
passed, tests, invalid, total_skipped);
|
passed, tests, invalid, total_skipped);
|
||||||
|
|
||||||
if (skip > 0) {
|
if (skip > 0)
|
||||||
|
{
|
||||||
printf("WARN: skipped past the end of file, exiting with status 2\n");
|
printf("WARN: skipped past the end of file, exiting with status 2\n");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (passed != tests) exit(1);
|
if (passed != tests)
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void jv_test()
|
||||||
static void jv_test() {
|
{
|
||||||
/// JSON parser regression tests
|
/// JSON parser regression tests
|
||||||
{
|
{
|
||||||
jv v = jv_parse("{\"a':\"12\"}");
|
jv v = jv_parse("{\"a':\"12\"}");
|
||||||
@@ -273,7 +332,6 @@ static void jv_test() {
|
|||||||
assert(!jv_equal(jv_copy(a2), jv_copy(a)));
|
assert(!jv_equal(jv_copy(a2), jv_copy(a)));
|
||||||
jv_free(a2);
|
jv_free(a2);
|
||||||
|
|
||||||
|
|
||||||
assert(jv_get_refcnt(a) == 1);
|
assert(jv_get_refcnt(a) == 1);
|
||||||
a = jv_array_append(a, jv_copy(a));
|
a = jv_array_append(a, jv_copy(a));
|
||||||
assert(jv_get_refcnt(a) == 1);
|
assert(jv_get_refcnt(a) == 1);
|
||||||
@@ -281,7 +339,8 @@ static void jv_test() {
|
|||||||
assert(jv_array_length(jv_copy(a)) == 2);
|
assert(jv_array_length(jv_copy(a)) == 2);
|
||||||
assert(jv_number_value(jv_array_get(jv_copy(a), 0)) == 42);
|
assert(jv_number_value(jv_array_get(jv_copy(a), 0)) == 42);
|
||||||
|
|
||||||
for (int i=0; i<10; i++) {
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
jv subarray = jv_array_get(jv_copy(a), 1);
|
jv subarray = jv_array_get(jv_copy(a), 1);
|
||||||
assert(jv_get_kind(subarray) == JV_KIND_ARRAY);
|
assert(jv_get_kind(subarray) == JV_KIND_ARRAY);
|
||||||
assert(jv_array_length(jv_copy(subarray)) == 1);
|
assert(jv_array_length(jv_copy(subarray)) == 1);
|
||||||
@@ -289,7 +348,6 @@ static void jv_test() {
|
|||||||
jv_free(subarray);
|
jv_free(subarray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
jv subarray = jv_array_get(jv_copy(a), 1);
|
jv subarray = jv_array_get(jv_copy(a), 1);
|
||||||
assert(jv_get_kind(subarray) == JV_KIND_ARRAY);
|
assert(jv_get_kind(subarray) == JV_KIND_ARRAY);
|
||||||
assert(jv_array_length(jv_copy(subarray)) == 1);
|
assert(jv_array_length(jv_copy(subarray)) == 1);
|
||||||
@@ -309,9 +367,9 @@ static void jv_test() {
|
|||||||
|
|
||||||
jv_free(subarray);
|
jv_free(subarray);
|
||||||
|
|
||||||
void* before = sub2.u.ptr;
|
void *before = sub2.u.ptr;
|
||||||
sub2 = jv_array_append(sub2, jv_number(200));
|
sub2 = jv_array_append(sub2, jv_number(200));
|
||||||
void* after = sub2.u.ptr;
|
void *after = sub2.u.ptr;
|
||||||
assert(before == after);
|
assert(before == after);
|
||||||
jv_free(sub2);
|
jv_free(sub2);
|
||||||
|
|
||||||
@@ -322,7 +380,6 @@ static void jv_test() {
|
|||||||
assert(jv_number_value(jv_array_get(jv_copy(a3), 2)) == 19);
|
assert(jv_number_value(jv_array_get(jv_copy(a3), 2)) == 19);
|
||||||
jv_free(a3);
|
jv_free(a3);
|
||||||
|
|
||||||
|
|
||||||
jv a4 = jv_array();
|
jv a4 = jv_array();
|
||||||
a4 = jv_array_append(a4, jv_number(1));
|
a4 = jv_array_append(a4, jv_number(1));
|
||||||
a4 = jv_array_append(a4, jv_number(2));
|
a4 = jv_array_append(a4, jv_number(2));
|
||||||
@@ -336,17 +393,14 @@ static void jv_test() {
|
|||||||
jv_free(a4);
|
jv_free(a4);
|
||||||
jv_free(a5);
|
jv_free(a5);
|
||||||
|
|
||||||
|
|
||||||
assert(jv_array_length(jv_copy(a)) == 2);
|
assert(jv_array_length(jv_copy(a)) == 2);
|
||||||
assert(jv_number_value(jv_array_get(jv_copy(a), 0)) == 42);
|
assert(jv_number_value(jv_array_get(jv_copy(a), 0)) == 42);
|
||||||
assert(jv_array_length(jv_array_get(jv_copy(a), 1)) == 1);
|
assert(jv_array_length(jv_array_get(jv_copy(a), 1)) == 1);
|
||||||
|
|
||||||
|
// jv_dump(jv_copy(a), 0); printf("\n");
|
||||||
//jv_dump(jv_copy(a), 0); printf("\n");
|
|
||||||
jv_free(a);
|
jv_free(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Strings
|
/// Strings
|
||||||
{
|
{
|
||||||
assert(jv_equal(jv_string("foo"), jv_string_sized("foo", 3)));
|
assert(jv_equal(jv_string("foo"), jv_string_sized("foo", 3)));
|
||||||
@@ -357,7 +411,6 @@ static void jv_test() {
|
|||||||
jv_free(shortstr);
|
jv_free(shortstr);
|
||||||
jv_free(longstr);
|
jv_free(longstr);
|
||||||
|
|
||||||
|
|
||||||
char a1s[] = "hello", a2s[] = "hello", bs[] = "goodbye";
|
char a1s[] = "hello", a2s[] = "hello", bs[] = "goodbye";
|
||||||
jv a1 = jv_string(a1s), a2 = jv_string(a2s), b = jv_string(bs);
|
jv a1 = jv_string(a1s), a2 = jv_string(a2s), b = jv_string(bs);
|
||||||
assert(jv_equal(jv_copy(a1), jv_copy(a2)));
|
assert(jv_equal(jv_copy(a1), jv_copy(a2)));
|
||||||
@@ -373,8 +426,9 @@ static void jv_test() {
|
|||||||
|
|
||||||
assert(jv_equal(jv_string("hello42!"), jv_string_fmt("hello%d%s", 42, "!")));
|
assert(jv_equal(jv_string("hello42!"), jv_string_fmt("hello%d%s", 42, "!")));
|
||||||
char big[20000];
|
char big[20000];
|
||||||
for (int i=0; i<(int)sizeof(big); i++) big[i] = 'a';
|
for (int i = 0; i < (int)sizeof(big); i++)
|
||||||
big[sizeof(big)-1] = 0;
|
big[i] = 'a';
|
||||||
|
big[sizeof(big) - 1] = 0;
|
||||||
jv str = jv_string_fmt("%s", big);
|
jv str = jv_string_fmt("%s", big);
|
||||||
assert(jv_string_length_bytes(jv_copy(str)) == sizeof(big) - 1);
|
assert(jv_string_length_bytes(jv_copy(str)) == sizeof(big) - 1);
|
||||||
assert(!strcmp(big, jv_string_value(str)));
|
assert(!strcmp(big, jv_string_value(str)));
|
||||||
@@ -397,7 +451,7 @@ static void jv_test() {
|
|||||||
jv_free(o1);
|
jv_free(o1);
|
||||||
assert(jv_number_value(jv_object_get(jv_copy(o2), jv_string("bar"))) == 240);
|
assert(jv_number_value(jv_object_get(jv_copy(o2), jv_string("bar"))) == 240);
|
||||||
|
|
||||||
//jv_dump(jv_copy(o2), 0); printf("\n");
|
// jv_dump(jv_copy(o2), 0); printf("\n");
|
||||||
jv_free(o2);
|
jv_free(o2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user