From a6592e77763d8cc4db8e8897f8e90e1defef85b0 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 12 Nov 2024 21:24:39 +0300 Subject: [PATCH] public: add test to check that pair Q_buildos and Q_buildarch return expected (for this build) data --- public/tests/test_validate_target.c | 21 +++++++++++++++++++++ public/wscript | 14 ++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 public/tests/test_validate_target.c diff --git a/public/tests/test_validate_target.c b/public/tests/test_validate_target.c new file mode 100644 index 00000000..e3a645be --- /dev/null +++ b/public/tests/test_validate_target.c @@ -0,0 +1,21 @@ +#include +#include "build.h" +#include "buildenums.h" +#include "crtlib.h" + +#ifndef VALIDATE_TARGET +#error +#endif + +int main( void ) +{ + string buf; + + if( Q_snprintf( buf, sizeof( buf ), "%s-%s", Q_buildos( ), Q_buildarch( )) < 0 ) + return 1; + + if( Q_strcmp( buf, VALIDATE_TARGET ) != 0 ) + return 2; + + return EXIT_SUCCESS; +} diff --git a/public/wscript b/public/wscript index 70ef340d..ea49da04 100644 --- a/public/wscript +++ b/public/wscript @@ -56,11 +56,16 @@ def export_define(conf, define, value=1): def simple_check(conf, fragment, msg, mandatory=False, **kw): return conf.check_cc(fragment=fragment, msg='Checking for %s' % msg, mandatory=mandatory, **kw) +def options(opt): + opt.add_option('--validate-target', action='store', dest='VALIDATE_TARGET', default=None, + help='development option, needs --enable-tests flag') + def configure(conf): # private to libpublic conf.load('gitversion') conf.define('XASH_BUILD_COMMIT', conf.env.GIT_VERSION if conf.env.GIT_VERSION else 'unknown-commit') conf.define('XASH_BUILD_BRANCH', conf.env.GIT_BRANCH if conf.env.GIT_BRANCH else 'unknown-branch') + conf.env.VALIDATE_TARGET = conf.options.VALIDATE_TARGET # need to expose it for everyone using libpublic headers conf.env.EXPORT_DEFINES_LIST = [] @@ -116,6 +121,15 @@ def build(bld): subsystem = bld.env.MSVC_SUBSYSTEM) if bld.env.TESTS: + if bld.env.VALIDATE_TARGET: + bld.program(features = 'test', + source = 'tests/test_validate_target.c', + target = 'validate_target', + use = 'public', + defines = 'VALIDATE_TARGET="%s"' % bld.env.VALIDATE_TARGET, + subsystem = bld.env.CONSOLE_SUBSYSTEM, + install_path = None) + tests = { 'strings': 'tests/test_strings.c', 'build': 'tests/test_build.c',