X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=test.c;h=020cb2f1db1aad78e59290aa766b78c9fe1c684a;hb=77ef7f516de7b87178a2af2ebe91e7c28d051ea0;hp=34b3744952b5320ff8e79ccdb7407dba78a0c996;hpb=ca52ecc20af641a20b3d3cdb0921f55c27541491;p=xonotic%2Fgmqcc.git diff --git a/test.c b/test.c index 34b3744..020cb2f 100644 --- a/test.c +++ b/test.c @@ -802,8 +802,8 @@ void task_destroy(const char *curdir) { * using the template passed into it for call-flags and user defined * messages. */ -bool task_execute(task_template_t *template) { - bool success = false; +bool task_execute(task_template_t *template, char ***line) { + bool success = true; FILE *execute; char buffer[4096]; memset (buffer,0,sizeof(buffer)); @@ -860,12 +860,18 @@ bool task_execute(task_template_t *template) { if (strrchr(data, '\n')) *strrchr(data, '\n') = '\0'; + if (strcmp(data, template->comparematch[compare++])) + success = false; /* - * We only care about the last line from the output for now - * implementing multi-line match is TODO. - */ - success = !!!(strcmp(data, template->comparematch[compare++])); + * Copy to output vector for diagnostics if execution match + * fails. + */ + vec_push(*line, data); + + /* reset */ + data = NULL; + size = 0; } mem_d(data); data = NULL; @@ -883,8 +889,10 @@ bool task_execute(task_template_t *template) { void task_schedualize() { bool execute = false; char *data = NULL; + 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)); @@ -910,8 +918,10 @@ void task_schedualize() { while (util_getline(&data, &size, task_tasks[i].runhandles[1]) != EOF) { fputs(data, task_tasks[i].stdoutlog); - if (strstr(data, "failed to open file")) - execute = false; + if (strstr(data, "failed to open file")) { + task_tasks[i].compiled = false; + execute = false; + } fflush(task_tasks[i].stdoutlog); } @@ -933,12 +943,8 @@ void task_schedualize() { fflush(task_tasks[i].stdoutlog); } - /* - * If we made it here that concludes the task is to be executed - * in the virtual machine. - */ - if (!execute || !task_execute(task_tasks[i].template)) { - con_err("test failure: `%s` [%s] see %s.stdout and %s.stderr\n", + if (!execute) { + 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) ? task_tasks[i].template->failuremessage : "unknown", @@ -947,11 +953,47 @@ void task_schedualize() { ); continue; } + /* + * If we made it here that concludes the task is to be executed + * in the virtual machine. + */ + if (!task_execute(task_tasks[i].template, &match)) { + size_t d = 0; + + con_err("test failure: `%s` [%s] (invalid results from execution)\n", + task_tasks[i].template->description, + (task_tasks[i].template->failuremessage) ? + task_tasks[i].template->failuremessage : "unknown" + ); + + /* + * Print nicely formatted expected match lists to console error + * 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)); + for (; d < vec_size(task_tasks[i].template->comparematch); d++) { + char *select = task_tasks[i].template->comparematch[d]; + size_t length = 40 - strlen(select); + + con_err(" Expected: \"%s\"", select); + while (length --) + con_err(" "); + con_err("| Got: \"%s\"\n", (d >= vec_size(match)) ? "<>" : match[d]); + } + 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, + task_tasks[i].template->description, (task_tasks[i].template->successmessage) ? - task_tasks[i].template->successmessage : "unknown" + task_tasks[i].template->successmessage : "unknown" ); } mem_d(data);