From: TimePath Date: Wed, 26 Aug 2015 23:40:54 +0000 (+1000) Subject: Move test to /lib X-Git-Tag: xonotic-v0.8.2~2019 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=bcadfbac06557383ee6d266bb92331d6fb1e9599;p=xonotic%2Fxonotic-data.pk3dir.git Move test to /lib --- diff --git a/qcsrc/client/progs.src b/qcsrc/client/progs.src index 3c6ccc1c6..1b5471b94 100644 --- a/qcsrc/client/progs.src +++ b/qcsrc/client/progs.src @@ -52,7 +52,6 @@ weapons/projectile.qc // TODO ../common/physics.qc ../common/playerstats.qc ../common/p2mathlib.qc -../common/test.qc ../common/util.qc ../common/viewloc.qc diff --git a/qcsrc/common/command/generic.qc b/qcsrc/common/command/generic.qc index d12cc064e..14bc58947 100644 --- a/qcsrc/common/command/generic.qc +++ b/qcsrc/common/command/generic.qc @@ -5,7 +5,6 @@ #include "rpn.qh" #include "../mapinfo.qh" -#include "../test.qh" #ifndef MENUQC #include "../notifications.qh" diff --git a/qcsrc/common/test.qc b/qcsrc/common/test.qc deleted file mode 100644 index 966553b27..000000000 --- a/qcsrc/common/test.qc +++ /dev/null @@ -1,64 +0,0 @@ -#if defined(CSQC) - #include "../dpdefs/csprogsdefs.qh" - #include "test.qh" -#elif defined(MENUQC) -#elif defined(SVQC) - #include "../dpdefs/dpextensions.qh" - #include "test.qh" -#endif - -float TEST_failed; -float TEST_ok; - -void TEST_Fail(string cond) -{ - printf("Assertion failed: ", cond); - //backtrace(); - ++TEST_failed; -} - -void TEST_OK() -{ - TEST_ok = true; -} - -float TEST_RunAll() -{ - int f = 0; - float n = numentityfields(); - for(int i = 0; i < n; ++i) - { - string name = entityfieldname(i); - if(substring(name, 0, 6) == "_TEST_") - if(!TEST_Run(substring(name, 6, -1))) - ++f; - } - if(f) - { - printf("%d tests failed\n", f); - return 1; - } - else - { - printf("All tests OK\n", f); - return 0; - } -} - -float TEST_Run(string s) -{ - printf("%s: testing...\n", s); - TEST_failed = TEST_ok = 0; - callfunction(strcat("_TEST_", s)); - if(TEST_failed > 0) - { - printf("%s: %d items failed.\n", s, TEST_failed); - return 0; - } - else if(!TEST_ok) - { - printf("%s: did not complete.\n", s); - return 0; - } - return 1; -} diff --git a/qcsrc/common/test.qh b/qcsrc/common/test.qh deleted file mode 100644 index edc2f5bf3..000000000 --- a/qcsrc/common/test.qh +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef TEST_H -#define TEST_H - -#define TEST_Check(cond) do { if(!(cond)) TEST_Fail(#cond); } while(0) - -void TEST_OK(); -void TEST_Fail(string cond); - -float TEST_RunAll(); -float TEST_Run(string test); -#endif diff --git a/qcsrc/lib/_all.inc b/qcsrc/lib/_all.inc index 1e7b85f48..5a55b538b 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -7,4 +7,5 @@ #include "OO.qh" #include "Progname.qh" #include "Registry.qh" +#include "test.qc" #include "urllib.qc" diff --git a/qcsrc/lib/test.qc b/qcsrc/lib/test.qc new file mode 100644 index 000000000..04f9f68fe --- /dev/null +++ b/qcsrc/lib/test.qc @@ -0,0 +1,57 @@ +#include "test.qh" + +float TEST_failed; +float TEST_ok; + +void TEST_Fail(string cond) +{ + printf("Assertion failed: ", cond); + //backtrace(); + ++TEST_failed; +} + +void TEST_OK() +{ + TEST_ok = true; +} + +float TEST_RunAll() +{ + int f = 0; + float n = numentityfields(); + for(int i = 0; i < n; ++i) + { + string name = entityfieldname(i); + if(substring(name, 0, 6) == "_TEST_") + if(!TEST_Run(substring(name, 6, -1))) + ++f; + } + if(f) + { + printf("%d tests failed\n", f); + return 1; + } + else + { + printf("All tests OK\n", f); + return 0; + } +} + +float TEST_Run(string s) +{ + printf("%s: testing...\n", s); + TEST_failed = TEST_ok = 0; + callfunction(strcat("_TEST_", s)); + if(TEST_failed > 0) + { + printf("%s: %d items failed.\n", s, TEST_failed); + return 0; + } + else if(!TEST_ok) + { + printf("%s: did not complete.\n", s); + return 0; + } + return 1; +} diff --git a/qcsrc/lib/test.qh b/qcsrc/lib/test.qh new file mode 100644 index 000000000..d1f5357a5 --- /dev/null +++ b/qcsrc/lib/test.qh @@ -0,0 +1,13 @@ +#ifndef TEST_H +#define TEST_H + +#include "../common/util.qh" + +#define TEST_Check(cond) do { if(!(cond)) TEST_Fail(#cond); } while(0) + +void TEST_OK(); +void TEST_Fail(string cond); + +float TEST_RunAll(); +float TEST_Run(string test); +#endif diff --git a/qcsrc/menu/menu.qh b/qcsrc/menu/menu.qh index 020a65a20..e4f594f71 100644 --- a/qcsrc/menu/menu.qh +++ b/qcsrc/menu/menu.qh @@ -9,7 +9,6 @@ #include "xonotic/util.qh" #include "../common/constants.qh" -#include "../common/test.qh" #include "../common/util.qh" #define localcmd cmd diff --git a/qcsrc/menu/progs.src b/qcsrc/menu/progs.src index 4192c6991..600e326a3 100644 --- a/qcsrc/menu/progs.src +++ b/qcsrc/menu/progs.src @@ -20,7 +20,6 @@ xonotic/util.qc ../common/campaign_setup.qc ../common/mapinfo.qc ../common/playerstats.qc -../common/test.qc ../common/util.qc ../common/items/all.qc diff --git a/qcsrc/server/mutators/mutators_include.qc b/qcsrc/server/mutators/mutators_include.qc index a703fdc19..c5b1ce2ca 100644 --- a/qcsrc/server/mutators/mutators_include.qc +++ b/qcsrc/server/mutators/mutators_include.qc @@ -14,7 +14,6 @@ #include "../../common/util.qh" #include "../../common/nades.qh" #include "../../common/buffs.qh" - #include "../../common/test.qh" #include "../../common/command/markup.qh" #include "../../common/command/rpn.qh" #include "../../common/command/generic.qh" diff --git a/qcsrc/server/progs.src b/qcsrc/server/progs.src index 0cf64cae3..61ec76196 100644 --- a/qcsrc/server/progs.src +++ b/qcsrc/server/progs.src @@ -99,7 +99,6 @@ weapons/weaponsystem.qc ../common/physics.qc ../common/playerstats.qc ../common/p2mathlib.qc -../common/test.qc ../common/viewloc.qc ../common/triggers/include.qc ../common/util.qc