X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=test.c;h=9694161b81567c7509c393b4426bdb742f414c7d;hb=60807b677cecb414b501503d73b50714534ff3b0;hp=ca1add20faef4cbd93296ce2e2589c2c6213866c;hpb=b5a0fd7e42257af7547e0c8a44ba5436c6399384;p=xonotic%2Fgmqcc.git diff --git a/test.c b/test.c index ca1add2..9694161 100644 --- a/test.c +++ b/test.c @@ -25,8 +25,8 @@ #include #include -bool opts_memchk = false; -bool opts_debug = false; +cmd_options opts; + char *task_bins[] = { "./gmqcc", "./qcvm" @@ -803,7 +803,7 @@ void task_destroy(const char *curdir) { * messages. */ bool task_execute(task_template_t *template, char ***line) { - bool success = false; + bool success = true; FILE *execute; char buffer[4096]; memset (buffer,0,sizeof(buffer)); @@ -860,18 +860,22 @@ bool task_execute(task_template_t *template, char ***line) { if (strrchr(data, '\n')) *strrchr(data, '\n') = '\0'; - - /* - * We only care about the last line from the output for now - * implementing multi-line match is TODO. - */ - success = !!!(strcmp(data, template->comparematch[compare++])); + if (vec_size(template->comparematch) > compare) { + if (strcmp(data, template->comparematch[compare++])) + success = false; + } else { + success = false; + } /* * Copy to output vector for diagnostics if execution match * fails. */ vec_push(*line, data); + + /* reset */ + data = NULL; + size = 0; } mem_d(data); data = NULL; @@ -892,6 +896,7 @@ void task_schedualize() { char **match = NULL; size_t size = 0; size_t i; + size_t j; util_debug("TEST", "found %d tasks, preparing to execute\n", vec_size(task_tasks)); @@ -901,8 +906,7 @@ void task_schedualize() { * Generate a task from thin air if it requires execution in * the QCVM. */ - if (!strcmp(task_tasks[i].template->proceduretype, "-execute")) - execute = true; + execute = !!(!strcmp(task_tasks[i].template->proceduretype, "-execute")); /* * We assume it compiled before we actually compiled :). On error @@ -942,7 +946,7 @@ void task_schedualize() { fflush(task_tasks[i].stdoutlog); } - if (!execute) { + if (!task_tasks[i].compiled) { con_err("test failure: `%s` [%s] (failed to compile) see %s.stdout and %s.stderr\n", task_tasks[i].template->description, (task_tasks[i].template->failuremessage) ? @@ -952,6 +956,16 @@ void task_schedualize() { ); continue; } + + if (!execute) { + con_out("test succeeded: `%s` [%s]\n", + task_tasks[i].template->description, + (task_tasks[i].template->successmessage) ? + task_tasks[i].template->successmessage : "unknown" + ); + continue; + } + /* * If we made it here that concludes the task is to be executed * in the virtual machine. @@ -970,7 +984,10 @@ void task_schedualize() { * handler for the all the given matches in the template file and * what was actually returned from executing. */ - con_err(" Expected From %u Matches:\n", vec_size(task_tasks[i].template->comparematch)); + con_err(" Expected From %u Matches: (got %u Matches)\n", + vec_size(task_tasks[i].template->comparematch), + vec_size(match) + ); for (; d < vec_size(task_tasks[i].template->comparematch); d++) { char *select = task_tasks[i].template->comparematch[d]; size_t length = 40 - strlen(select); @@ -980,9 +997,29 @@ void task_schedualize() { con_err(" "); con_err("| Got: \"%s\"\n", (d >= vec_size(match)) ? "<>" : match[d]); } + + /* + * Print the non-expected out (since we are simply not expecting it) + * This will help track down bugs in template files that fail to match + * something. + */ + if (vec_size(match) > vec_size(task_tasks[i].template->comparematch)) { + for (d = 0; d < vec_size(match) - vec_size(task_tasks[i].template->comparematch); d++) { + con_err(" Expected: Nothing | Got: \"%s\"\n", + match[d + vec_size(task_tasks[i].template->comparematch)] + ); + } + } + + + for (j = 0; j < vec_size(match); j++) + mem_d(match[j]); vec_free(match); continue; } + for (j = 0; j < vec_size(match); j++) + mem_d(match[j]); + vec_free(match); con_out("test succeeded: `%s` [%s]\n", task_tasks[i].template->description, @@ -1080,11 +1117,11 @@ int main(int argc, char **argv) { con_change(redirout, redirerr); if (!strcmp(argv[0]+1, "debug")) { - opts_debug = true; + opts.debug = true; continue; } if (!strcmp(argv[0]+1, "memchk")) { - opts_memchk = true; + opts.memchk = true; continue; } if (!strcmp(argv[0]+1, "nocolor")) {