]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - test.cpp
add variable search order test
[xonotic/gmqcc.git] / test.cpp
index 5fe22dc75e8454d82757612ac3389b37c600b428..2614c7f1dd78a5ae525c835a103c80e15ef57926 100644 (file)
--- a/test.cpp
+++ b/test.cpp
@@ -76,7 +76,7 @@ static FILE **task_popen(const char *command, const char *mode) {
         dup2(errhandle[1], 2);
 
         execvp(argv[0], &argv[0]);
-        exit(EXIT_FAILURE);
+        exit(95);
     } else {
         /* fork failed */
         goto task_popen_error_3;
@@ -87,7 +87,7 @@ task_popen_error_2: close(outhandle[0]), close(outhandle[1]);
 task_popen_error_1: close(inhandle [0]), close(inhandle [1]);
 task_popen_error_0:
 
-    return NULL;
+    return nullptr;
 }
 
 static int task_pclose(FILE **handles) {
@@ -98,11 +98,17 @@ static int task_pclose(FILE **handles) {
     close(data->pipes[1]); /* stdout */
     close(data->pipes[2]); /* stderr */
 
-    waitpid(data->pid, &status, 0);
+    if (data->pid != waitpid(data->pid, &status, 0)) {
+      abort();
+    }
+    if (!WIFEXITED(status))
+      return -1;
+    if (WIFSIGNALED(status))
+      con_out("got signaled!\n");
 
     mem_d(data);
 
-    return status;
+    return status ? 1 : 0;
 }
 
 #define TASK_COMPILE    0
@@ -199,7 +205,7 @@ struct task_template_t {
 static bool task_template_generate(task_template_t *tmpl, char tag, const char *file, size_t line, char *value, size_t *pad) {
     size_t desclen = 0;
     size_t filelen = 0;
-    char **destval = NULL;
+    char **destval = nullptr;
 
     if (!tmpl)
         return false;
@@ -270,8 +276,8 @@ static bool task_template_generate(task_template_t *tmpl, char tag, const char *
 }
 
 static bool task_template_parse(const char *file, task_template_t *tmpl, FILE *fp, size_t *pad) {
-    char  *data = NULL;
-    char  *back = NULL;
+    char  *data = nullptr;
+    char  *back = nullptr;
     size_t size = 0;
     size_t line = 1;
 
@@ -376,7 +382,7 @@ static bool task_template_parse(const char *file, task_template_t *tmpl, FILE *f
         /* update line and free old sata */
         line++;
         mem_d(back);
-        back = NULL;
+        back = nullptr;
     }
     if (back)
         mem_d(back);
@@ -395,22 +401,22 @@ static void task_template_nullify(task_template_t *tmpl) {
     if (!tmpl)
         return;
 
-    tmpl->description = NULL;
-    tmpl->proceduretype = NULL;
-    tmpl->compileflags = NULL;
-    tmpl->executeflags = NULL;
-    tmpl->sourcefile = NULL;
-    tmpl->tempfilename = NULL;
-    tmpl->rulesfile = NULL;
-    tmpl->testflags = NULL;
+    tmpl->description = nullptr;
+    tmpl->proceduretype = nullptr;
+    tmpl->compileflags = nullptr;
+    tmpl->executeflags = nullptr;
+    tmpl->sourcefile = nullptr;
+    tmpl->tempfilename = nullptr;
+    tmpl->rulesfile = nullptr;
+    tmpl->testflags = nullptr;
 }
 
 static task_template_t *task_template_compile(const char *file, const char *dir, size_t *pad) {
     /* a page should be enough */
     char             fullfile[4096];
     size_t           filepadd = 0;
-    FILE       *tempfile = NULL;
-    task_template_t *tmpl     = NULL;
+    FILE       *tempfile = nullptr;
+    task_template_t *tmpl     = nullptr;
 
     util_snprintf(fullfile, sizeof(fullfile), "%s/%s", dir, file);
 
@@ -524,7 +530,7 @@ failure:
         fclose(tempfile);
     mem_d(tmpl);
 
-    return NULL;
+    return nullptr;
 }
 
 static void task_template_destroy(task_template_t *tmpl) {
@@ -544,7 +550,7 @@ static void task_template_destroy(task_template_t *tmpl) {
         mem_d(it);
 
     /*
-     * Nullify all the template members otherwise NULL comparision
+     * Nullify all the template members otherwise nullptr comparision
      * checks will fail if tmpl pointer is reused.
      */
     mem_d(tmpl->tempfilename);
@@ -600,7 +606,7 @@ static bool task_propagate(const char *curdir, size_t *pad, const char *defs) {
             directories.push_back(claim);
         } else {
             mem_d(claim);
-            claim = NULL;
+            claim = nullptr;
         }
     }
     closedir(dir);
@@ -629,9 +635,11 @@ static bool task_propagate(const char *curdir, size_t *pad, const char *defs) {
             if (strcmp(files->d_name + strlen(files->d_name) - 5, ".tmpl") == 0) {
                 task_template_t *tmpl = task_template_compile(files->d_name, it, pad);
                 char             buf[4096]; /* one page should be enough */
-                const char      *qcflags = NULL;
+                const char      *qcflags = nullptr;
                 task_t           task;
 
+                memset(&task, 0, sizeof(task));
+
                 found ++;
                 if (!tmpl) {
                     con_err("error compiling task template: %s\n", files->d_name);
@@ -642,7 +650,7 @@ static bool task_propagate(const char *curdir, size_t *pad, const char *defs) {
                  * Generate a temportary file name for the output binary
                  * so we don't trample over an existing one.
                  */
-                tmpl->tempfilename = NULL;
+                tmpl->tempfilename = nullptr;
                 util_asprintf(&tmpl->tempfilename, "%s/TMPDAT.%s.dat", it, files->d_name);
 
                 /*
@@ -884,7 +892,7 @@ static bool task_trymatch(task_t &task, std::vector<char *> &line) {
      * and handle accordingly.
      */
     {
-        char  *data    = NULL;
+        char  *data    = nullptr;
         size_t size    = 0;
         size_t compare = 0;
 
@@ -941,7 +949,7 @@ static bool task_trymatch(task_t &task, std::vector<char *> &line) {
             line.push_back(data);
 
             /* reset */
-            data = NULL;
+            data = nullptr;
             size = 0;
         }
 
@@ -949,7 +957,7 @@ static bool task_trymatch(task_t &task, std::vector<char *> &line) {
             success = false;
 
         mem_d(data);
-        data = NULL;
+        data = nullptr;
     }
 
     if (process)
@@ -982,7 +990,7 @@ static const char *task_type(task_template_t *tmpl) {
 static size_t task_schedualize(size_t *pad) {
     char space[2][64];
     bool execute = false;
-    char *data = NULL;
+    char *data = nullptr;
     std::vector<char *> match;
     size_t size = 0;
     size_t i = 0;
@@ -997,6 +1005,10 @@ static size_t task_schedualize(size_t *pad) {
         util_snprintf(space[1], sizeof(space[1]), "%d", (int)(i));
 
         con_out("test #%u %*s", i, strlen(space[0]) - strlen(space[1]), "");
+            //con_out("[[%*s]]",
+            //    (pad[0] + pad[1] - strlen(it.tmpl->description)) + (strlen(it.tmpl->rulesfile) - pad[1]),
+            //    it.tmpl->rulesfile);
+            //fflush(stdout);
 
         /*
          * Generate a task from thin air if it requires execution in
@@ -1057,6 +1069,16 @@ static size_t task_schedualize(size_t *pad) {
         }
 
         status = task_pclose(it.runhandles);
+        if (status != 0 && status != 1) {
+            con_out("compiler failure (returned: %i):   `%s` %*s\n",
+                status,
+                it.tmpl->description,
+                (pad[0] + pad[1] - strlen(it.tmpl->description)) + (strlen(it.tmpl->rulesfile) - pad[1]),
+                it.tmpl->rulesfile
+            );
+            failed++;
+            continue;
+        }
         if ((!strcmp(it.tmpl->proceduretype, "-fail") && status == EXIT_SUCCESS)
         ||  ( strcmp(it.tmpl->proceduretype, "-fail") && status == EXIT_FAILURE)) {
             con_out("failure:   `%s` %*s %*s\n",
@@ -1248,7 +1270,7 @@ static bool parsecmd(const char *optname, int *argc_, char ***argv_, char **out,
 
 int main(int argc, char **argv) {
     bool succeed  = false;
-    char *defs = NULL;
+    char *defs = nullptr;
 
     con_init();