]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/test.qc
Merge branch 'master' into terencehill/weapon_panel_fix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / test.qc
1 #if defined(CSQC)
2         #include "../dpdefs/csprogsdefs.qh"
3         #include "test.qh"
4 #elif defined(MENUQC)
5 #elif defined(SVQC)
6         #include "../dpdefs/dpextensions.qh"
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         int f = 0;
28         float n = numentityfields();
29         for(int i = 0; i < n; ++i)
30         {
31                 string name = entityfieldname(i);
32                 if(substring(name, 0, 6) == "_TEST_")
33                         if(!TEST_Run(substring(name, 6, -1)))
34                                 ++f;
35         }
36         if(f)
37         {
38                 printf("%d tests failed\n", f);
39                 return 1;
40         }
41         else
42         {
43                 printf("All tests OK\n", f);
44                 return 0;
45         }
46 }
47
48 float TEST_Run(string s)
49 {
50         printf("%s: testing...\n", s);
51         TEST_failed = TEST_ok = 0;
52         callfunction(strcat("_TEST_", s));
53         if(TEST_failed > 0)
54         {
55                 printf("%s: %d items failed.\n", s, TEST_failed);
56                 return 0;
57         }
58         else if(!TEST_ok)
59         {
60                 printf("%s: did not complete.\n", s);
61                 return 0;
62         }
63         return 1;
64 }