]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/test.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / test.qc
index 23907fe5f15ed4106c69fae466807abd79fe2911..e2b7b56a746435c0fd0af4f275fbf54cc88e117f 100644 (file)
@@ -1,57 +1,32 @@
 #include "test.qh"
 
-float TEST_failed;
-float TEST_ok;
-
-void TEST_Fail(string cond)
-{
-       LOG_INFOF("Assertion failed: ", cond);
-       //backtrace();
-       ++TEST_failed;
-}
-
-void TEST_OK()
-{
-       TEST_ok = true;
-}
-
-float TEST_RunAll()
+int TEST_RunAll_accumulated(int init);
+bool RUN_ALL_TESTS()
 {
-       int f = 0;
-       float n = numentityfields();
-       for(int i = 0; i < n; ++i)
-       {
-               string name = entityfieldname(i);
-               if(substring(name, 0, 6) == "_TEST_")
-                       if(!TEST_Run(substring(name, 6, -1)))
-                               ++f;
-       }
-       if(f)
-       {
-               LOG_INFOF("%d tests failed\n", f);
-               return 1;
-       }
-       else
-       {
-               LOG_INFOF("All tests OK\n", f);
-               return 0;
+       int f = TEST_RunAll_accumulated(0);
+       if (f) {
+               LOG_INFOF("%d tests failed", f);
+               return true;
+       } else {
+               LOG_INFO("All tests OK");
+               return false;
        }
 }
 
-float TEST_Run(string s)
+bool TEST_Run(string s)
 {
-       LOG_INFOF("%s: testing...\n", s);
-       TEST_failed = TEST_ok = 0;
-       callfunction(strcat("_TEST_", s));
-       if(TEST_failed > 0)
-       {
-               LOG_INFOF("%s: %d items failed.\n", s, TEST_failed);
-               return 0;
-       }
-       else if(!TEST_ok)
-       {
-               LOG_INFOF("%s: did not complete.\n", s);
-               return 0;
+       LOG_INFOF("%s: testing...", s);
+       TEST_failed = 0;
+       TEST_fatal = 0;
+       TEST_ok = false;
+       string fn = strcat("_TEST_", s);
+       if (isfunction(fn)) { callfunction(fn); }
+       if (TEST_failed > 0) {
+               LOG_INFOF("%s: %d items failed.", s, TEST_failed);
+               return false;
+       } else if (!TEST_ok) {
+               LOG_INFOF("%s: did not complete.", s);
+               return false;
        }
-       return 1;
+       return true;
 }