From 2f4d2c4141e741aab767af2aa3e9c6fb3316e384 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 9 Mar 2022 05:32:49 +0100 Subject: Add --args to sibs test command --- backend/ninja/Ninja.cpp | 9 ++++++++- include/Conf.hpp | 1 + src/main.cpp | 12 +++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index eecbaee..6c69d13 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -1843,7 +1843,14 @@ namespace backend if(!zigTest && !config.testsBuildOnly) { - Result runTestResult = exec({ Path(buildPath).join(toFileString(sibsTestConfig.getPackageName())).data }, true); + FileString executableName = toFileString(sibsTestConfig.getPackageName()); + if(isSamePlatformFamily(sibsTestConfig.platform, PLATFORM_WIN)) + executableName += TINYDIR_STRING(".exe"); + + std::vector args = { Path(buildPath).join(executableName).data }; + args.insert(args.end(), config.testRunArgs.begin(), config.testRunArgs.end()); + + Result runTestResult = exec(args, true); if(!runTestResult) return Result::Err(runTestResult); diff --git a/include/Conf.hpp b/include/Conf.hpp index 673a7f6..54c6b89 100644 --- a/include/Conf.hpp +++ b/include/Conf.hpp @@ -444,6 +444,7 @@ namespace sibs std::string linker; bool testsBuildOnly = false; bool skipCompile = false; + std::vector testRunArgs; protected: virtual void processObject(StringView name) override; virtual void processField(StringView name, const ConfigValue &value) override; diff --git a/src/main.cpp b/src/main.cpp index 0caaf22..2592135 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -139,7 +139,9 @@ static void usageBuild(bool run) printf(" --lto Use link-time optimization. May increase compile times - Optional (default: not used)\n"); printf(" --debug-symbols Include debug symbols in release mode - Optional (default: not used)\n"); printf(" --linker=linker The linker to use. \"gold\" is the default linker when using gcc\n"); - if(!run) { + if(run) { + printf(" --args A list of arguments to run the program with\n"); + } else { printf(" --skip-compile Skip compilation. This can be used to generate a compile_commands.json file without compiling. Note that the compile_commands.json can miss files that are generated when this option is used\n"); } printf("Examples:\n"); @@ -182,6 +184,7 @@ static void usageTest() printf(" --all-files Test all files - Optional (default: not used), Only applicable for Zig\n"); printf(" --linker=linker The linker to use. \"gold\" is the default linker when using gcc\n"); printf(" --skip-compile Skip compilation. This can be used to generate a compile_commands.json file without compiling. Note that the compile_commands.json can miss files that are generated when this option is used. This option also skips running the tests\n"); + printf(" --args A list of arguments to run the program with\n"); printf("Examples:\n"); printf(" sibs test\n"); printf(" sibs test dirA/dirB\n"); @@ -683,6 +686,7 @@ static int testProject(int argc, const _tinydir_char_t **argv) bool buildOnly = false; bool skipCompile = false; std::string linker; + std::vector run_args; for(int i = 0; i < argc; ++i) { @@ -768,6 +772,11 @@ static int testProject(int argc, const _tinydir_char_t **argv) usageTest(); } } + else if(_tinydir_strcmp(arg, TINYDIR_STRING("--args")) == 0) + { + run_args.insert(run_args.end(), argv + i + 1, argv + argc); + break; + } else if(_tinydir_strncmp(arg, TINYDIR_STRING("--"), 2) == 0) { ferr << "Error: Invalid argument " << arg << endl; @@ -861,6 +870,7 @@ static int testProject(int argc, const _tinydir_char_t **argv) sibsConfig.zigTestAllFiles = testAllFiles; sibsConfig.testsBuildOnly = buildOnly; sibsConfig.skipCompile = skipCompile; + sibsConfig.testRunArgs = std::move(run_args); return buildProject(projectPath, projectConfFilePath, sibsConfig, false, {}); } -- cgit v1.2.3