mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-17 18:40:02 +00:00
engine: add simple unit-testing (v3?)
This commit is contained in:
parent
5bc4359a2f
commit
6ea25b8194
@ -40,12 +40,16 @@ GNU General Public License for more details.
|
||||
#include "input.h"
|
||||
#include "enginefeatures.h"
|
||||
#include "render_api.h" // decallist_t
|
||||
|
||||
#include "tests.h"
|
||||
|
||||
pfnChangeGame pChangeGame = NULL;
|
||||
host_parm_t host; // host parms
|
||||
sysinfo_t SI;
|
||||
|
||||
#ifdef XASH_ENGINE_TESTS
|
||||
struct tests_stats_s tests_stats;
|
||||
#endif
|
||||
|
||||
CVAR_DEFINE( host_developer, "developer", "0", 0, "engine is in development-mode" );
|
||||
CVAR_DEFINE_AUTO( sys_ticrate, "100", 0, "framerate in dedicated mode" );
|
||||
|
||||
@ -771,6 +775,19 @@ void Host_Userconfigd_f( void )
|
||||
Mem_Free( t );
|
||||
}
|
||||
|
||||
#if XASH_ENGINE_TESTS
|
||||
static void Host_RunTests( void )
|
||||
{
|
||||
memset( &tests_stats, 0, sizeof( tests_stats ));
|
||||
|
||||
Test_RunLibCommon();
|
||||
|
||||
Msg( "Done! %d passed, %d failed\n", tests_stats.passed, tests_stats.failed );
|
||||
|
||||
Sys_Quit();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
=================
|
||||
Host_InitCommon
|
||||
@ -827,6 +844,14 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha
|
||||
}
|
||||
}
|
||||
|
||||
#if XASH_ENGINE_TESTS
|
||||
if( Sys_CheckParm( "-runtests" ))
|
||||
{
|
||||
host.allow_console = true;
|
||||
developer = DEV_EXTENDED;
|
||||
}
|
||||
#endif
|
||||
|
||||
host.con_showalways = true;
|
||||
|
||||
#if XASH_DEDICATED
|
||||
@ -896,6 +921,11 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha
|
||||
|
||||
Con_Init(); // early console running to catch all the messages
|
||||
|
||||
#if XASH_ENGINE_TESTS
|
||||
if( Sys_CheckParm( "-runtests" ))
|
||||
Host_RunTests();
|
||||
#endif
|
||||
|
||||
Platform_Init();
|
||||
|
||||
baseDir = getenv( "XASH3D_BASEDIR" );
|
||||
|
28
engine/common/tests.h
Normal file
28
engine/common/tests.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef TESTS_H
|
||||
#define TESTS_H
|
||||
|
||||
#if XASH_ENGINE_TESTS
|
||||
|
||||
struct tests_stats_s
|
||||
{
|
||||
uint passed;
|
||||
uint failed;
|
||||
};
|
||||
|
||||
extern struct tests_stats_s tests_stats;
|
||||
|
||||
#define TRUN( x ) Msg( "Running " #x "\n" ); x
|
||||
|
||||
#define TASSERT( exp ) \
|
||||
if(!( exp )) \
|
||||
{ \
|
||||
tests_stats.failed++; \
|
||||
Msg( "assert failed at %s:%i\n", __FILE__, __LINE__ ) \
|
||||
} \
|
||||
else tests_stats.passed++;
|
||||
|
||||
void Test_RunLibCommon( void );
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* TESTS_H */
|
@ -29,6 +29,9 @@ def options(opt):
|
||||
grp.add_option('--enable-static-binary', action = 'store_true', dest = 'STATIC', default = False,
|
||||
help = 'build static binary(not recommended, --single-binary required) [default: %default]')
|
||||
|
||||
grp.add_option('--enable-engine-tests', action = 'store_true', dest = 'ENGINE_TESTS', default = False,
|
||||
help = 'embed tests into the engine, jump into them by -runtests command line switch [default: %default]')
|
||||
|
||||
opt.load('sdl2')
|
||||
|
||||
def configure(conf):
|
||||
@ -79,6 +82,9 @@ def configure(conf):
|
||||
if hasattr(conf.options, 'DLLEMU'):
|
||||
conf.define_cond('XASH_DLL_LOADER', conf.options.DLLEMU)
|
||||
|
||||
conf.env.ENGINE_TESTS = conf.options.ENGINE_TESTS
|
||||
|
||||
conf.define_cond('XASH_ENGINE_TESTS', conf.env.ENGINE_TESTS)
|
||||
conf.define_cond('XASH_STATIC_LIBS', conf.env.STATIC_LINKING)
|
||||
conf.define_cond('XASH_CUSTOM_SWAP', conf.options.CUSTOM_SWAP)
|
||||
conf.define_cond('SINGLE_BINARY', conf.env.SINGLE_BINARY)
|
||||
@ -92,6 +98,8 @@ def configure(conf):
|
||||
def build(bld):
|
||||
is_cxx_link = False
|
||||
libs = [ 'public', 'dllemu' ]
|
||||
|
||||
# basic build: dedicated only
|
||||
source = bld.path.ant_glob([
|
||||
'common/*.c',
|
||||
'common/imagelib/*.c',
|
||||
@ -99,7 +107,9 @@ def build(bld):
|
||||
'common/soundlib/libmpg/*.c',
|
||||
'server/*.c'])
|
||||
|
||||
# basic build: dedicated only, no dependencies
|
||||
if bld.env.ENGINE_TESTS:
|
||||
source += bld.path.ant_glob(['tests/*.c'])
|
||||
|
||||
if bld.env.DEST_OS == 'win32':
|
||||
libs += ['USER32', 'SHELL32', 'GDI32', 'ADVAPI32', 'DBGHELP', 'PSAPI', 'WS2_32' ]
|
||||
source += bld.path.ant_glob(['platform/win32/*.c'])
|
||||
@ -146,7 +156,7 @@ def build(bld):
|
||||
'client/vgui/*.c',
|
||||
'client/avi/*.c'])
|
||||
|
||||
includes = ['common', 'server', 'client', 'client/vgui', '.', '../public', '../common', '../pm_shared' ]
|
||||
includes = ['common', 'server', 'client', 'client/vgui', 'tests', '.', '../public', '../common', '../pm_shared' ]
|
||||
|
||||
if bld.env.SINGLE_BINARY:
|
||||
install_path = bld.env.BINDIR
|
||||
|
Loading…
x
Reference in New Issue
Block a user