X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=test.c;h=5e99df404063de4b7d638cd3e6217107414f5f36;hp=c33b4ac38d8a80f0de156b9ff1d7620592154583;hb=52ffc6db10de5815e4256d9fdc4665b409c34147;hpb=d201cfe6b49f95ba8bcaa0eebb3a6fb7e1a16913 diff --git a/test.c b/test.c index c33b4ac..5e99df4 100644 --- a/test.c +++ b/test.c @@ -311,6 +311,9 @@ int task_pclose(FILE **handles) { * Used to set the compilation flags for the given task, this * must be provided, this tag is NOT optional. * + * F: Used to set some test suite flags, currently the only option + * is -no-defs (to including of defs.qh) + * * E: * Used to set the execution flags for the given task. This tag * must be provided if T == -execute, otherwise it's erroneous @@ -350,6 +353,7 @@ typedef struct { char *tempfilename; char **comparematch; char *rulesfile; + char *testflags; } task_template_t; /* @@ -369,6 +373,7 @@ bool task_template_generate(task_template_t *template, char tag, const char *fil case 'C': destval = &template->compileflags; break; case 'E': destval = &template->executeflags; break; case 'I': destval = &template->sourcefile; break; + case 'F': destval = &template->testflags; break; default: con_printmsg(LVL_ERROR, __FILE__, __LINE__, "internal error", "invalid tag `%c:` during code generation\n", @@ -475,6 +480,7 @@ bool task_template_parse(const char *file, task_template_t *template, FILE *fp, case 'C': case 'E': case 'I': + case 'F': if (data[1] != ':') { con_printmsg(LVL_ERROR, file, line, "template parse error", "expected `:` after `%c`", @@ -561,6 +567,7 @@ void task_template_nullify(task_template_t *template) { template->sourcefile = NULL; template->tempfilename = NULL; template->rulesfile = NULL; + template->testflags = NULL; } task_template_t *task_template_compile(const char *file, const char *dir, size_t *pad) { @@ -682,6 +689,7 @@ void task_template_destroy(task_template_t **template) { if ((*template)->executeflags) mem_d((*template)->executeflags); if ((*template)->sourcefile) mem_d((*template)->sourcefile); if ((*template)->rulesfile) mem_d((*template)->rulesfile); + if ((*template)->testflags) mem_d((*template)->testflags); /* * Delete all allocated string for task template then destroy the @@ -722,7 +730,7 @@ task_t *task_tasks = NULL; * Read a directory and searches for all template files in it * which is later used to run all tests. */ -bool task_propagate(const char *curdir, size_t *pad) { +bool task_propagate(const char *curdir, size_t *pad, const char *defs) { bool success = true; DIR *dir; struct dirent *files; @@ -782,22 +790,47 @@ bool task_propagate(const char *curdir, size_t *pad) { */ memset (buf,0,sizeof(buf)); if (qcflags) { - snprintf(buf, sizeof(buf), "%s %s/%s %s %s -o %s", - task_bins[TASK_COMPILE], - curdir, - template->sourcefile, - qcflags, - template->compileflags, - template->tempfilename - ); + if (template->testflags && !strcmp(template->testflags, "-no-defs")) { + snprintf(buf, sizeof(buf), "%s %s/%s %s %s -o %s", + task_bins[TASK_COMPILE], + curdir, + template->sourcefile, + qcflags, + template->compileflags, + template->tempfilename + ); + } else { + snprintf(buf, sizeof(buf), "%s %s/%s %s/%s %s %s -o %s", + task_bins[TASK_COMPILE], + curdir, + defs, + curdir, + template->sourcefile, + qcflags, + template->compileflags, + template->tempfilename + ); + } } else { - snprintf(buf, sizeof(buf), "%s %s/%s %s -o %s", - task_bins[TASK_COMPILE], - curdir, - template->sourcefile, - template->compileflags, - template->tempfilename - ); + if (template->testflags && !strcmp(template->testflags, "-no-defs")) { + snprintf(buf, sizeof(buf), "%s %s/%s %s -o %s", + task_bins[TASK_COMPILE], + curdir, + template->sourcefile, + template->compileflags, + template->tempfilename + ); + } else { + snprintf(buf, sizeof(buf), "%s %s/%s %s/%s %s -o %s", + task_bins[TASK_COMPILE], + curdir, + defs, + curdir, + template->sourcefile, + template->compileflags, + template->tempfilename + ); + } } /* @@ -1165,13 +1198,24 @@ void task_schedualize(size_t *pad) { * * It expects con_init() was called before hand. */ -bool test_perform(const char *curdir) { +GMQCC_WARN bool test_perform(const char *curdir, const char *defs) { + static const char *default_defs = "defs.qh"; + size_t pad[] = { 0, 0 }; + /* + * If the default definition file isn't set to anything. We will + * use the default_defs here, which is "defs.qc" + */ + if (!defs) { + defs = default_defs; + } + + task_precleanup(curdir); - if (!task_propagate(curdir, pad)) { + if (!task_propagate(curdir, pad, defs)) { con_err("error: failed to propagate tasks\n"); task_destroy(); return false; @@ -1220,8 +1264,10 @@ static bool parsecmd(const char *optname, int *argc_, char ***argv_, char **out, } int main(int argc, char **argv) { + bool succeed = false; char *redirout = (char*)stdout; char *redirerr = (char*)stderr; + char *defs = NULL; con_init(); @@ -1238,15 +1284,17 @@ int main(int argc, char **argv) { continue; if (parsecmd("redirerr", &argc, &argv, &redirerr, 1, false)) continue; + if (parsecmd("defs", &argc, &argv, &defs, 1, false)) + continue; con_change(redirout, redirerr); if (!strcmp(argv[0]+1, "debug")) { - OPTION_VALUE_BOOL(OPTION_DEBUG) = true; + OPTS_OPTION_BOOL(OPTION_DEBUG) = true; continue; } if (!strcmp(argv[0]+1, "memchk")) { - OPTION_VALUE_BOOL(OPTION_MEMCHK) = true; + OPTS_OPTION_BOOL(OPTION_MEMCHK) = true; continue; } if (!strcmp(argv[0]+1, "nocolor")) { @@ -1259,7 +1307,9 @@ int main(int argc, char **argv) { } } con_change(redirout, redirerr); - test_perform("tests"); + succeed = test_perform("tests", defs); util_meminfo(); - return 0; + + + return (succeed) ? EXIT_SUCCESS : EXIT_FAILURE; }