test: Initial testing framework
Configure with --enable-testtools. BLD_ROOT is now the top build directory. Current test requires ttynvt to be started (by root) like # BLD_ROOT/src/ttynvt -d -E -S localhost:1234 -n ttyNVT99 Device and server name parameters must be as shown above. Run tests like $ make -C BLD_ROOT test # Builds the other programs too $ make -C BLD_ROOT/test # Only running tests $ make -C BLD_ROOT/test V=1 RUN_OPTS="--gtest_filter=Test1.t1"
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* General test stuff
|
||||
*
|
||||
* - The main() function
|
||||
* - Some printing functions
|
||||
*/
|
||||
#include "test.h"
|
||||
|
||||
int debug = 0;
|
||||
|
||||
static bool ttyout = false;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
ttyout = isatty(STDOUT_FILENO);
|
||||
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
for (argc--, argv++; argc > 0; argc--, argv++)
|
||||
{
|
||||
s = argv[0];
|
||||
if (*s++ != '-')
|
||||
break;
|
||||
again:
|
||||
switch (*s++)
|
||||
{
|
||||
case 'd':
|
||||
debug++;
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
void _pr_text(const char *col, const char *fmt, va_list args)
|
||||
{
|
||||
char fmtx[1024];
|
||||
|
||||
if (ttyout)
|
||||
snprintf(fmtx, sizeof(fmtx), "%s[ ] - %s%s\n",
|
||||
col, fmt, COL_RST);
|
||||
else
|
||||
snprintf(fmtx, sizeof(fmtx), "[ ] - %s\n", fmt);
|
||||
fmt = fmtx;
|
||||
|
||||
vprintf(fmt, args);
|
||||
}
|
||||
|
||||
void pr_text(const char *col, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
_pr_text(col, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void pr_info(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
_pr_text(COL_YEL, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
Reference in New Issue
Block a user