diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index 85ea2152d9..cde5a041a2 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -97,7 +97,12 @@ int cmCTestScriptHandler::ExecuteScript(std::string const& total_script_arg) this->CTest->GetInitialCommandLineArguments(); //*** need to make sure this does not have the current script *** for (size_t i = 1; i < initArgs.size(); ++i) { - argv.push_back(initArgs[i]); + // in a nested subprocess, skip the parent's `-SR ` arguments. + if (initArgs[i] == "-SR") { + i++; // + } else { + argv.push_back(initArgs[i]); + } } // Now create process object diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 603b1f4b5e..c23adb8ad7 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1975,9 +1975,12 @@ int cmCTest::Run(std::vector const& args) }; auto const dashSR = [&runScripts, &SRArgumentSpecified](std::string const& script) -> bool { - SRArgumentSpecified = true; - runScripts.emplace_back(cmSystemTools::ToNormalizedPathOnDisk(script), - true); + // -SR should be processed only once + if (!SRArgumentSpecified) { + SRArgumentSpecified = true; + runScripts.emplace_back(cmSystemTools::ToNormalizedPathOnDisk(script), + true); + } return true; }; auto const dash_S =