Functions starting with _TEST_ are unit tests, shall call TEST_OK() at the end, and TEST_Check(condition) to test conditions.
../common/teams.qh
../common/util.qh
+../common/test.qh
../common/counting.qh
../common/items.qh
../common/explosion_equation.qh
bgmscript.qc
noise.qc
+../common/test.qc
../common/util.qc
../common/notifications.qc
../common/command/markup.qc
}
}
+void GenericCommand_runtest(float request, float argc)
+{
+ switch(request)
+ {
+ case CMD_REQUEST_COMMAND:
+ {
+ if(argc > 1)
+ {
+ float i;
+ for(i = 1; i < argc; ++i)
+ TEST_Run(argv(i));
+ }
+ else
+ TEST_RunAll();
+ return;
+ }
+
+ default:
+ case CMD_REQUEST_USAGE:
+ {
+ print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " [function to run]"));
+ return;
+ }
+ }
+}
+
/* use this when creating a new command, making sure to place it in alphabetical order... also,
** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
void GenericCommand_(float request)
GENERIC_COMMAND("rpn", GenericCommand_rpn(request, arguments, command), "RPN calculator") \
GENERIC_COMMAND("settemp", GenericCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored later") \
GENERIC_COMMAND("settemp_restore", GenericCommand_settemp_restore(request, arguments), "Restore all cvars set by settemp command") \
+ GENERIC_COMMAND("runtest", GenericCommand_runtest(request, arguments), "Run unit tests") \
/* nothing */
void GenericCommand_macro_help()
--- /dev/null
+float TEST_failed;
+float TEST_ok;
+
+void TEST_Fail(string cond)
+{
+ print(sprintf("Assertion failed: ", cond));
+ //backtrace();
+ ++TEST_failed;
+}
+
+void TEST_OK()
+{
+ TEST_ok = TRUE;
+}
+
+float TEST_RunAll()
+{
+ float f = 0;
+ float n = numentityfields();
+ float i;
+ for(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)
+ {
+ print(sprintf("%d tests failed\n", f));
+ return 1;
+ }
+ else
+ {
+ print(sprintf("All tests OK\n", f));
+ return 0;
+ }
+}
+
+float TEST_Run(string s)
+{
+ print(sprintf("%s: testing...\n", s));
+ TEST_failed = TEST_ok = 0;
+ callfunction(strcat("_TEST_", s));
+ if(TEST_failed > 0)
+ {
+ print(sprintf("%s: %d items failed.\n", s, TEST_failed));
+ return 0;
+ }
+ else if(!TEST_ok)
+ {
+ print(sprintf("%s: did not complete.\n", s));
+ return 0;
+ }
+ return 1;
+}
--- /dev/null
+#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);
../warpzonelib/mathlib.qh
../common/util.qh
+../common/test.qh
oo/base.h
classes.c
../common/util.qc
+../common/test.qc
../common/command/markup.qc
../common/command/rpn.qc
../common/command/generic.qc
../common/constants.qh
../common/teams.qh
../common/util.qh
+../common/test.qh
../common/counting.qh
../common/items.qh
../common/explosion_equation.qh
../warpzonelib/server.qc
../common/animdecide.qc
+../common/test.qc
../common/util.qc
../common/notifications.qc