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