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