From 9cebd36a2c258a47ccca3d0a5f81a637ef43c935 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 13 Dec 2023 17:37:13 +0300 Subject: [PATCH] Fix Windows compatibility --- tools/tester.c | 50 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/tools/tester.c b/tools/tester.c index 64d8f26..86303c8 100644 --- a/tools/tester.c +++ b/tools/tester.c @@ -285,21 +285,47 @@ static int run_test(const char *filename, test *t, int show_diff) return 0; } - ret = system(cmd) >> 8; + ret = system(cmd); - if (ret) { - FILE *f = fopen(out_filename, "a+"); - fprintf(f, "\nexit code = %d\n", ret); - fclose(f); + if (ret != -1) { + FILE *f; + +#ifdef _WIN32 + if (ret) { + f = fopen(out_filename, "a+"); + fprintf(f, "\nexit code = %d\n", ret); + fclose(f); + } +#else + if (WIFEXITED(ret)) { + ret = WEXITSTATUS(ret); + if (ret > 128 && ret < 160) { + f = fopen(out_filename, "a+"); + fprintf(f, "\ntermsig = %d\n", ret - 128); + fclose(f); + } else if (ret) { + f = fopen(out_filename, "a+"); + fprintf(f, "\nexit code = %d\n", ret); + fclose(f); + } + } else if (WIFSIGNALED(ret)) { + ret = WTERMSIG(ret); + f = fopen(out_filename, "a+"); + fprintf(f, "\ntermsig = %d\n", ret); + fclose(f); + } +#endif + + out = read_file(out_filename); + if (!out) { + out = malloc(1); + out[0] = 0; + } + ret = same_text(t->expect, out); + } else { + ret = 0; } - out = read_file(out_filename); - if (!out) { - out = malloc(1); - out[0] = 0; - } - - ret = same_text(t->expect, out); if (ret) { unlink(code_filename); unlink(out_filename);