diff options
author | Sergey Bobrenok <bobrofon@gmail.com> | 2019-05-15 15:10:39 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-06-07 17:14:29 (GMT) |
commit | e791ffac61912f6540742aabaf4cb78a4d475a16 (patch) | |
tree | b8aa85f7406bfc599ce113ecf32f5f0312d2db65 /Source/cmTestGenerator.cxx | |
parent | e2414ee13d1fad8b6775581d01975109c9867854 (diff) | |
download | CMake-e791ffac61912f6540742aabaf4cb78a4d475a16.zip CMake-e791ffac61912f6540742aabaf4cb78a4d475a16.tar.gz CMake-e791ffac61912f6540742aabaf4cb78a4d475a16.tar.bz2 |
add_test: Add COMMAND_EXPAND_LISTS option
Add a `COMMAND_EXPAND_LISTS` option to the `add_test` command to cause
`;`-separated lists produced by generator expressions to be expanded
into multiple arguments. The `add_custom_command` command already
has such an option.
Fixes: #17284
Diffstat (limited to 'Source/cmTestGenerator.cxx')
-rw-r--r-- | Source/cmTestGenerator.cxx | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx index 571cd09..ce960dc 100644 --- a/Source/cmTestGenerator.cxx +++ b/Source/cmTestGenerator.cxx @@ -76,12 +76,22 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os, // Start the test command. os << indent << "add_test(" << this->Test->GetName() << " "; - // Get the test command line to be executed. - std::vector<std::string> const& command = this->Test->GetCommand(); + // Evaluate command line arguments + std::vector<std::string> argv = + EvaluateCommandLineArguments(this->Test->GetCommand(), ge, config); + + // Expand arguments if COMMAND_EXPAND_LISTS is set + if (this->Test->GetCommandExpandLists()) { + argv = cmSystemTools::ExpandedLists(argv.begin(), argv.end()); + // Expanding lists on an empty command may have left it empty + if (argv.empty()) { + argv.emplace_back(); + } + } // Check whether the command executable is a target whose name is to // be translated. - std::string exe = command[0]; + std::string exe = argv[0]; cmGeneratorTarget* target = this->LG->FindGeneratorTargetToUse(exe); if (target && target->GetType() == cmStateEnums::EXECUTABLE) { // Use the target file on disk. @@ -101,16 +111,14 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os, } } else { // Use the command name given. - exe = ge.Parse(exe)->Evaluate(this->LG, config); cmSystemTools::ConvertToUnixSlashes(exe); } // Generate the command line with full escapes. os << cmOutputConverter::EscapeForCMake(exe); - for (std::string const& arg : cmMakeRange(command).advance(1)) { - os << " " - << cmOutputConverter::EscapeForCMake( - ge.Parse(arg)->Evaluate(this->LG, config)); + + for (auto const& arg : cmMakeRange(argv).advance(1)) { + os << " " << cmOutputConverter::EscapeForCMake(arg); } // Finish the test command. @@ -208,3 +216,16 @@ void cmTestGenerator::GenerateInternalProperties(std::ostream& os) os << "\""; } + +std::vector<std::string> cmTestGenerator::EvaluateCommandLineArguments( + const std::vector<std::string>& argv, cmGeneratorExpression& ge, + const std::string& config) const +{ + // Evaluate executable name and arguments + auto evaluatedRange = + cmMakeRange(argv).transform([&](const std::string& arg) { + return ge.Parse(arg)->Evaluate(this->LG, config); + }); + + return { evaluatedRange.begin(), evaluatedRange.end() }; +} |