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