]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/test.qc
1a71c7529705f7f99c7bd8bf55dd0067a1d8d1e0
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / test.qc
1 #include "test.qh"
2
3 int TEST_failed;
4 bool TEST_ok;
5
6 void TEST_Fail(string cond)
7 {
8         LOG_INFOF("Assertion failed: %s", cond);
9         // backtrace();
10         ++TEST_failed;
11 }
12
13 void TEST_OK()
14 {
15         TEST_ok = true;
16 }
17
18 int TEST_RunAll_accumulated(int init);
19 bool TEST_RunAll()
20 {
21         int f = TEST_RunAll_accumulated(0);
22         if (f)
23         {
24                 LOG_INFOF("%d tests failed\n", f);
25                 return true;
26         }
27         else
28         {
29                 LOG_INFO("All tests OK\n");
30                 return false;
31         }
32 }
33
34 bool TEST_Run(string s)
35 {
36         LOG_INFOF("%s: testing...\n", s);
37         TEST_failed = 0;
38         TEST_ok = false;
39         callfunction(strcat("_TEST_", s));
40         if (TEST_failed > 0)
41         {
42                 LOG_INFOF("%s: %d items failed.\n", s, TEST_failed);
43                 return false;
44         }
45         else if (!TEST_ok)
46         {
47                 LOG_INFOF("%s: did not complete.\n", s);
48                 return false;
49         }
50         return true;
51 }