]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/test.qc
Uncrustify lib/*
[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))) ++f;
27         }
28         if (f)
29         {
30                 LOG_INFOF("%d tests failed\n", f);
31                 return 1;
32         }
33         else
34         {
35                 LOG_INFOF("All tests OK\n", f);
36                 return 0;
37         }
38 }
39
40 float TEST_Run(string s)
41 {
42         LOG_INFOF("%s: testing...\n", s);
43         TEST_failed = TEST_ok = 0;
44         callfunction(strcat("_TEST_", s));
45         if (TEST_failed > 0)
46         {
47                 LOG_INFOF("%s: %d items failed.\n", s, TEST_failed);
48                 return 0;
49         }
50         else if (!TEST_ok)
51         {
52                 LOG_INFOF("%s: did not complete.\n", s);
53                 return 0;
54         }
55         return 1;
56 }