diff options
Diffstat (limited to 'Source/cmCTest.cxx')
-rw-r--r-- | Source/cmCTest.cxx | 334 |
1 files changed, 185 insertions, 149 deletions
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index e260556..a4ca301 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1,5 +1,11 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ +#ifdef _WIN32 +/* windows.h defines min() and max() macros by default. This interferes with + * C++ functions names. + */ +#define NOMINMAX +#endif #include "cmCTest.h" #include "cm_curl.h" @@ -11,9 +17,12 @@ #include "cmsys/Process.h" #include "cmsys/String.hxx" #include "cmsys/SystemInformation.hxx" +#include <algorithm> +#include <chrono> #include <ctype.h> #include <iostream> #include <map> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stdio.h> #include <stdlib.h> @@ -41,6 +50,7 @@ #include "cmGeneratedFileStream.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" +#include "cmProcess.h" #include "cmProcessOutput.h" #include "cmState.h" #include "cmStateSnapshot.h" @@ -49,7 +59,6 @@ #include "cmVersion.h" #include "cmVersionConfig.h" #include "cmXMLWriter.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #if defined(__BEOS__) || defined(__HAIKU__) @@ -66,7 +75,7 @@ struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag) { struct tm* lctime; - time_t tctime = time(CM_NULLPTR); + time_t tctime = time(nullptr); lctime = gmtime(&tctime); char buf[1024]; // add todays year day and month to the time in str because @@ -84,7 +93,7 @@ struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag) // As such, this time may be in the past or in the future. time_t ntime = curl_getdate(buf, &tctime); cmCTestLog(this, DEBUG, " Get curl time: " << ntime << std::endl); - tctime = time(CM_NULLPTR); + tctime = time(nullptr); cmCTestLog(this, DEBUG, " Get the current time: " << tctime << std::endl); const int dayLength = 24 * 60 * 60; @@ -130,7 +139,7 @@ std::string cmCTest::CleanString(const std::string& str) std::string cmCTest::CurrentTime() { - time_t currenttime = time(CM_NULLPTR); + time_t currenttime = time(nullptr); struct tm* t = localtime(¤ttime); // return ::CleanString(ctime(¤ttime)); char current_time[1024]; @@ -146,7 +155,7 @@ std::string cmCTest::CurrentTime() std::string cmCTest::GetCostDataFile() { std::string fname = this->GetCTestConfiguration("CostDataFile"); - if (fname == "") { + if (fname.empty()) { fname = this->GetBinaryDir() + "/Testing/Temporary/CTestCostData.txt"; } return fname; @@ -156,7 +165,7 @@ std::string cmCTest::GetCostDataFile() static size_t HTTPResponseCallback(void* ptr, size_t size, size_t nmemb, void* data) { - int realsize = (int)(size * nmemb); + int realsize = static_cast<int>(size * nmemb); std::string* response = static_cast<std::string*>(data); const char* chPtr = static_cast<char*>(ptr); @@ -190,7 +199,8 @@ int cmCTest::HTTPRequest(std::string url, HTTPMethod method, ::curl_easy_setopt(curl, CURLOPT_PUT, 1); file = cmsys::SystemTools::Fopen(putFile, "rb"); ::curl_easy_setopt(curl, CURLOPT_INFILE, file); - // fall through to append GET fields + // fall through to append GET fields + CM_FALLTHROUGH; case cmCTest::HTTP_GET: if (!fields.empty()) { url += "?" + fields; @@ -204,7 +214,7 @@ int cmCTest::HTTPRequest(std::string url, HTTPMethod method, // set response options ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPResponseCallback); - ::curl_easy_setopt(curl, CURLOPT_FILE, (void*)&response); + ::curl_easy_setopt(curl, CURLOPT_FILE, &response); ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); CURLcode res = ::curl_easy_perform(curl); @@ -220,12 +230,11 @@ std::string cmCTest::MakeURLSafe(const std::string& str) { std::ostringstream ost; char buffer[10]; - for (std::string::size_type pos = 0; pos < str.size(); pos++) { - unsigned char ch = str[pos]; + for (unsigned char ch : str) { if ((ch > 126 || ch < 32 || ch == '&' || ch == '%' || ch == '+' || ch == '=' || ch == '@') && ch != 9) { - sprintf(buffer, "%02x;", (unsigned int)ch); + sprintf(buffer, "%02x;", static_cast<unsigned int>(ch)); ost << buffer; } else { ost << ch; @@ -240,7 +249,7 @@ std::string cmCTest::DecodeURL(const std::string& in) for (const char* c = in.c_str(); *c; ++c) { if (*c == '%' && isxdigit(*(c + 1)) && isxdigit(*(c + 2))) { char buf[3] = { *(c + 1), *(c + 2), 0 }; - out.append(1, char(strtoul(buf, CM_NULLPTR, 16))); + out.append(1, char(strtoul(buf, nullptr, 16))); c += 2; } else { out.append(1, *c); @@ -252,6 +261,7 @@ std::string cmCTest::DecodeURL(const std::string& in) cmCTest::cmCTest() { this->LabelSummary = true; + this->SubprojectSummary = true; this->ParallelLevel = 1; this->ParallelLevelSetInCli = false; this->TestLoad = 0; @@ -275,15 +285,14 @@ cmCTest::cmCTest() this->TestModel = cmCTest::EXPERIMENTAL; this->MaxTestNameWidth = 30; this->InteractiveDebugMode = true; - this->TimeOut = 0; - this->GlobalTimeout = 0; - this->LastStopTimeout = 24 * 60 * 60; + this->TimeOut = std::chrono::duration<double>::zero(); + this->GlobalTimeout = std::chrono::duration<double>::zero(); + this->LastStopTimeout = std::chrono::hours(24); this->CompressXMLFiles = false; - this->CTestConfigFile = ""; - this->ScheduleType = ""; - this->StopTime = ""; + this->ScheduleType.clear(); + this->StopTime.clear(); this->NextDayStopTime = false; - this->OutputLogFile = CM_NULLPTR; + this->OutputLogFile = nullptr; this->OutputLogFileLastTag = -1; this->SuppressUpdatingCTestConfiguration = false; this->DartVersion = 1; @@ -328,10 +337,8 @@ cmCTest::cmCTest() this->TestingHandlers["submit"] = new cmCTestSubmitHandler; this->TestingHandlers["upload"] = new cmCTestUploadHandler; - cmCTest::t_TestingHandlers::iterator it; - for (it = this->TestingHandlers.begin(); it != this->TestingHandlers.end(); - ++it) { - it->second->SetCTestInstance(this); + for (auto& handler : this->TestingHandlers) { + handler.second->SetCTestInstance(this); } // Make sure we can capture the build tool output. @@ -341,7 +348,7 @@ cmCTest::cmCTest() cmCTest::~cmCTest() { cmDeleteAll(this->TestingHandlers); - this->SetOutputLogFileName(CM_NULLPTR); + this->SetOutputLogFileName(nullptr); } void cmCTest::SetParallelLevel(int level) @@ -421,9 +428,8 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) cm.SetHomeOutputDirectory(""); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator gg(&cm); - CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); - if (!this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), - mf.get())) { + cmMakefile mf(&gg, cm.GetCurrentSnapshot()); + if (!this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), &mf)) { cmCTestOptionalLog( this, DEBUG, "Cannot find custom configuration file tree" << std::endl, quiet); @@ -462,7 +468,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) std::string tag; if (createNewTag) { - time_t tctime = time(CM_NULLPTR); + time_t tctime = time(nullptr); if (this->TomorrowTag) { tctime += (24 * 60 * 60); } @@ -477,7 +483,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) &min); if (year != lctime->tm_year + 1900 || mon != lctime->tm_mon + 1 || day != lctime->tm_mday) { - tag = ""; + tag.clear(); } std::string tagmode; if (cmSystemTools::GetLineFromStream(tfin, tagmode)) { @@ -487,7 +493,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) } tfin.close(); } - if (tag.empty() || (CM_NULLPTR != command) || this->Parts[PartStart]) { + if (tag.empty() || (nullptr != command) || this->Parts[PartStart]) { cmCTestOptionalLog( this, DEBUG, "TestModel: " << this->GetTestModelString() << std::endl, quiet); @@ -509,7 +515,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) ofs << this->GetTestModelString() << std::endl; } ofs.close(); - if (CM_NULLPTR == command) { + if (nullptr == command) { cmCTestOptionalLog(this, OUTPUT, "Create new tag: " << tag << " - " << this->GetTestModelString() << std::endl, @@ -623,12 +629,9 @@ bool cmCTest::UpdateCTestConfiguration() if (this->SuppressUpdatingCTestConfiguration) { return true; } - std::string fileName = this->CTestConfigFile; - if (fileName.empty()) { - fileName = this->BinaryDir + "/CTestConfiguration.ini"; - if (!cmSystemTools::FileExists(fileName.c_str())) { - fileName = this->BinaryDir + "/DartConfiguration.tcl"; - } + std::string fileName = this->BinaryDir + "/CTestConfiguration.ini"; + if (!cmSystemTools::FileExists(fileName.c_str())) { + fileName = this->BinaryDir + "/DartConfiguration.tcl"; } cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "UpdateCTestConfiguration from :" << fileName << "\n"); @@ -682,7 +685,8 @@ bool cmCTest::UpdateCTestConfiguration() this->BinaryDir = this->GetCTestConfiguration("BuildDirectory"); cmSystemTools::ChangeDirectory(this->BinaryDir); } - this->TimeOut = atoi(this->GetCTestConfiguration("TimeOut").c_str()); + this->TimeOut = + std::chrono::seconds(atoi(this->GetCTestConfiguration("TimeOut").c_str())); std::string const& testLoad = this->GetCTestConfiguration("TestLoad"); if (!testLoad.empty()) { unsigned long load; @@ -805,7 +809,7 @@ cmCTestGenericHandler* cmCTest::GetInitializedHandler(const char* handler) cmCTest::t_TestingHandlers::iterator it = this->TestingHandlers.find(handler); if (it == this->TestingHandlers.end()) { - return CM_NULLPTR; + return nullptr; } it->second->Initialize(); return it->second; @@ -816,7 +820,7 @@ cmCTestGenericHandler* cmCTest::GetHandler(const char* handler) cmCTest::t_TestingHandlers::iterator it = this->TestingHandlers.find(handler); if (it == this->TestingHandlers.end()) { - return CM_NULLPTR; + return nullptr; } return it->second; } @@ -840,7 +844,8 @@ int cmCTest::ProcessSteps() for (Part p = PartStart; notest && p != PartCount; p = Part(p + 1)) { notest = !this->Parts[p]; } - if (this->Parts[PartUpdate] && (this->GetRemainingTimeAllowed() - 120 > 0)) { + if (this->Parts[PartUpdate] && + (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) { cmCTestGenericHandler* uphandler = this->GetHandler("update"); uphandler->SetPersistentOption( "SourceDirectory", @@ -854,33 +859,34 @@ int cmCTest::ProcessSteps() return 0; } if (this->Parts[PartConfigure] && - (this->GetRemainingTimeAllowed() - 120 > 0)) { + (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) { if (this->GetHandler("configure")->ProcessHandler() < 0) { res |= cmCTest::CONFIGURE_ERRORS; } } - if (this->Parts[PartBuild] && (this->GetRemainingTimeAllowed() - 120 > 0)) { + if (this->Parts[PartBuild] && + (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) { this->UpdateCTestConfiguration(); if (this->GetHandler("build")->ProcessHandler() < 0) { res |= cmCTest::BUILD_ERRORS; } } if ((this->Parts[PartTest] || notest) && - (this->GetRemainingTimeAllowed() - 120 > 0)) { + (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) { this->UpdateCTestConfiguration(); if (this->GetHandler("test")->ProcessHandler() < 0) { res |= cmCTest::TEST_ERRORS; } } if (this->Parts[PartCoverage] && - (this->GetRemainingTimeAllowed() - 120 > 0)) { + (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) { this->UpdateCTestConfiguration(); if (this->GetHandler("coverage")->ProcessHandler() < 0) { res |= cmCTest::COVERAGE_ERRORS; } } if (this->Parts[PartMemCheck] && - (this->GetRemainingTimeAllowed() - 120 > 0)) { + (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) { this->UpdateCTestConfiguration(); if (this->GetHandler("memcheck")->ProcessHandler() < 0) { res |= cmCTest::MEMORY_ERRORS; @@ -959,7 +965,8 @@ int cmCTest::GetTestModelFromString(const char* str) //###################################################################### int cmCTest::RunMakeCommand(const char* command, std::string& output, - int* retVal, const char* dir, int timeout, + int* retVal, const char* dir, + std::chrono::duration<double> timeout, std::ostream& ofs, Encoding encoding) { // First generate the command and arguments @@ -970,17 +977,19 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, } std::vector<const char*> argv; - for (std::vector<std::string>::const_iterator a = args.begin(); - a != args.end(); ++a) { - argv.push_back(a->c_str()); + argv.reserve(args.size() + 1); + for (std::string const& a : args) { + argv.push_back(a.c_str()); } - argv.push_back(CM_NULLPTR); + argv.push_back(nullptr); - output = ""; + output.clear(); cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Run command:"); - std::vector<const char*>::iterator ait; - for (ait = argv.begin(); ait != argv.end() && *ait; ++ait) { - cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, " \"" << *ait << "\""); + for (char const* arg : argv) { + if (!arg) { + break; + } + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, " \"" << arg << "\""); } cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, std::endl); @@ -1004,11 +1013,11 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, " Each . represents " << tick_len << " bytes of output" << std::endl << " " << std::flush); - while (cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR)) { + while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) { processOutput.DecodeText(data, length, strdata); - for (size_t cc = 0; cc < strdata.size(); ++cc) { - if (strdata[cc] == 0) { - strdata[cc] = '\n'; + for (char& cc : strdata) { + if (cc == 0) { + cc = '\n'; } } output.append(strdata); @@ -1040,7 +1049,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, " Size of output: " << int(double(output.size()) / 1024.0) << "K" << std::endl); - cmsysProcess_WaitForExit(cp, CM_NULLPTR); + cmsysProcess_WaitForExit(cp, nullptr); int result = cmsysProcess_GetState(cp); @@ -1073,26 +1082,37 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, //###################################################################### int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, - int* retVal, std::ostream* log, double testTimeOut, + int* retVal, std::ostream* log, + std::chrono::duration<double> testTimeOut, std::vector<std::string>* environment, Encoding encoding) { bool modifyEnv = (environment && !environment->empty()); // determine how much time we have - double timeout = this->GetRemainingTimeAllowed() - 120; - if (this->TimeOut > 0 && this->TimeOut < timeout) { + std::chrono::duration<double> timeout = + std::min<std::chrono::duration<double>>(this->GetRemainingTimeAllowed(), + std::chrono::minutes(2)); + if (this->TimeOut > std::chrono::duration<double>::zero() && + this->TimeOut < timeout) { timeout = this->TimeOut; } - if (testTimeOut > 0 && testTimeOut < this->GetRemainingTimeAllowed()) { + if (testTimeOut > std::chrono::duration<double>::zero() && + testTimeOut < this->GetRemainingTimeAllowed()) { timeout = testTimeOut; } // always have at least 1 second if we got to here - if (timeout <= 0) { - timeout = 1; + if (timeout <= std::chrono::duration<double>::zero()) { + timeout = std::chrono::seconds(1); } - cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, - "Test timeout computed to be: " << timeout << "\n"); + cmCTestLog( + this, HANDLER_VERBOSE_OUTPUT, "Test timeout computed to be: " + << (timeout == std::chrono::duration<double>::max() + ? std::string("infinite") + : std::to_string( + std::chrono::duration_cast<std::chrono::seconds>(timeout) + .count())) + << "\n"); if (cmSystemTools::SameFile(argv[0], cmSystemTools::GetCTestCommand()) && !this->ForceNewCTestProcess) { cmCTest inst; @@ -1104,27 +1124,29 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, inst.SetStreams(&oss, &oss); std::vector<std::string> args; - for (unsigned int i = 0; i < argv.size(); ++i) { - if (argv[i]) { + for (char const* i : argv) { + if (i) { // make sure we pass the timeout in for any build and test // invocations. Since --build-generator is required this is a // good place to check for it, and to add the arguments in - if (strcmp(argv[i], "--build-generator") == 0 && timeout > 0) { + if (strcmp(i, "--build-generator") == 0 && + timeout > std::chrono::duration<double>::zero()) { args.push_back("--test-timeout"); std::ostringstream msg; - msg << timeout; + msg << std::chrono::duration_cast<std::chrono::seconds>(timeout) + .count(); args.push_back(msg.str()); } - args.push_back(argv[i]); + args.push_back(i); } } if (log) { *log << "* Run internal CTest" << std::endl; } - CM_AUTO_PTR<cmSystemTools::SaveRestoreEnvironment> saveEnv; + std::unique_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv; if (modifyEnv) { - saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment); + saveEnv = cm::make_unique<cmSystemTools::SaveRestoreEnvironment>(); cmSystemTools::AppendEnv(*environment); } @@ -1146,12 +1168,12 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, } std::vector<char> tempOutput; if (output) { - *output = ""; + output->clear(); } - CM_AUTO_PTR<cmSystemTools::SaveRestoreEnvironment> saveEnv; + std::unique_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv; if (modifyEnv) { - saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment); + saveEnv = cm::make_unique<cmSystemTools::SaveRestoreEnvironment>(); cmSystemTools::AppendEnv(*environment); } @@ -1169,7 +1191,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, int length; cmProcessOutput processOutput(encoding); std::string strdata; - while (cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR)) { + while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) { processOutput.DecodeText(data, length, strdata); if (output) { tempOutput.insert(tempOutput.end(), data, data + length); @@ -1189,7 +1211,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, } } - cmsysProcess_WaitForExit(cp, CM_NULLPTR); + cmsysProcess_WaitForExit(cp, nullptr); processOutput.DecodeText(tempOutput, tempOutput); if (output && tempOutput.begin() != tempOutput.end()) { output->append(&*tempOutput.begin(), tempOutput.size()); @@ -1234,7 +1256,7 @@ std::string cmCTest::SafeBuildIdField(const std::string& value) { std::string safevalue(value); - if (safevalue != "") { + if (!safevalue.empty()) { // Disallow non-filename and non-space whitespace characters. // If they occur, replace them with "" // @@ -1253,7 +1275,7 @@ std::string cmCTest::SafeBuildIdField(const std::string& value) } } - if (safevalue == "") { + if (safevalue.empty()) { safevalue = "(empty)"; } @@ -1345,9 +1367,8 @@ void cmCTest::AddSiteProperties(cmXMLWriter& xml) std::string l = labels; std::vector<std::string> args; cmSystemTools::ExpandListArgument(l, args); - for (std::vector<std::string>::iterator i = args.begin(); - i != args.end(); ++i) { - xml.Element("Label", *i); + for (std::string const& i : args) { + xml.Element("Label", i); } xml.EndElement(); } @@ -1363,6 +1384,33 @@ void cmCTest::AddSiteProperties(cmXMLWriter& xml) } } +void cmCTest::GenerateSubprojectsOutput(cmXMLWriter& xml) +{ + for (std::string const& subproj : this->GetLabelsForSubprojects()) { + xml.StartElement("Subproject"); + xml.Attribute("name", subproj); + xml.Element("Label", subproj); + xml.EndElement(); // Subproject + } +} + +std::vector<std::string> cmCTest::GetLabelsForSubprojects() +{ + std::string labelsForSubprojects = + this->GetCTestConfiguration("LabelsForSubprojects"); + std::vector<std::string> subprojects; + cmSystemTools::ExpandListArgument(labelsForSubprojects, subprojects); + + // sort the array + std::sort(subprojects.begin(), subprojects.end()); + // remove duplicates + std::vector<std::string>::iterator new_end = + std::unique(subprojects.begin(), subprojects.end()); + subprojects.erase(new_end, subprojects.end()); + + return subprojects; +} + void cmCTest::EndXML(cmXMLWriter& xml) { xml.EndElement(); // Site @@ -1374,7 +1422,6 @@ int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml, { std::string buildname = cmCTest::SafeBuildIdField(this->GetCTestConfiguration("BuildName")); - cmCTest::VectorOfStrings::const_iterator it; xml.StartDocument(); xml.ProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" " @@ -1390,15 +1437,15 @@ int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml, this->AddSiteProperties(xml); xml.StartElement("Notes"); - for (it = files.begin(); it != files.end(); it++) { - cmCTestLog(this, OUTPUT, "\tAdd file: " << *it << std::endl); + for (cmsys::String const& file : files) { + cmCTestLog(this, OUTPUT, "\tAdd file: " << file << std::endl); std::string note_time = this->CurrentTime(); xml.StartElement("Note"); - xml.Attribute("Name", *it); - xml.Element("Time", cmSystemTools::GetTime()); + xml.Attribute("Name", file); + xml.Element("Time", std::chrono::system_clock::now()); xml.Element("DateTime", note_time); xml.StartElement("Text"); - cmsys::ifstream ifs(it->c_str()); + cmsys::ifstream ifs(file.c_str()); if (ifs) { std::string line; while (cmSystemTools::GetLineFromStream(ifs, line)) { @@ -1407,9 +1454,9 @@ int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml, } ifs.close(); } else { - xml.Content("Problem reading file: " + *it + "\n"); + xml.Content("Problem reading file: " + file + "\n"); cmCTestLog(this, ERROR_MESSAGE, "Problem reading file: " - << *it << " while creating notes" << std::endl); + << file << " while creating notes" << std::endl); } xml.EndElement(); // Text xml.EndElement(); // Note @@ -1491,14 +1538,13 @@ std::string cmCTest::Base64EncodeFile(std::string const& file) bool cmCTest::SubmitExtraFiles(const VectorOfStrings& files) { - VectorOfStrings::const_iterator it; - for (it = files.begin(); it != files.end(); ++it) { - if (!cmSystemTools::FileExists(it->c_str())) { + for (cmsys::String const& file : files) { + if (!cmSystemTools::FileExists(file.c_str())) { cmCTestLog(this, ERROR_MESSAGE, "Cannot find extra file: " - << *it << " to submit." << std::endl;); + << file << " to submit." << std::endl;); return false; } - this->AddSubmitFile(PartExtraFiles, it->c_str()); + this->AddSubmitFile(PartExtraFiles, file.c_str()); } return true; } @@ -1735,7 +1781,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, if (this->CheckArgument(arg, "--timeout") && i < args.size() - 1) { i++; - double timeout = (double)atof(args[i].c_str()); + auto timeout = std::chrono::duration<double>(atof(args[i].c_str())); this->GlobalTimeout = timeout; } @@ -1764,6 +1810,9 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, if (this->CheckArgument(arg, "--no-label-summary")) { this->LabelSummary = false; } + if (this->CheckArgument(arg, "--no-subproject-summary")) { + this->SubprojectSummary = false; + } if (this->CheckArgument(arg, "-Q", "--quiet")) { this->Quiet = true; } @@ -2069,10 +2118,8 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output) // pass the argument to all the handlers as well, but i may no longer be // set to what it was originally so I'm not sure this is working as // intended - cmCTest::t_TestingHandlers::iterator it; - for (it = this->TestingHandlers.begin(); it != this->TestingHandlers.end(); - ++it) { - if (!it->second->ProcessCommandLineArguments(arg, i, args)) { + for (auto& handler : this->TestingHandlers) { + if (!handler.second->ProcessCommandLineArguments(arg, i, args)) { cmCTestLog(this, ERROR_MESSAGE, "Problem parsing command line arguments within a handler"); return 0; @@ -2169,11 +2216,9 @@ int cmCTest::ExecuteTests() if (this->ExtraVerbose) { cmCTestLog(this, OUTPUT, "* Extra verbosity turned on" << std::endl); } - cmCTest::t_TestingHandlers::iterator it; - for (it = this->TestingHandlers.begin(); it != this->TestingHandlers.end(); - ++it) { - it->second->SetVerbose(this->ExtraVerbose); - it->second->SetSubmitIndex(this->SubmitIndex); + for (auto& handler : this->TestingHandlers) { + handler.second->SetVerbose(this->ExtraVerbose); + handler.second->SetSubmitIndex(this->SubmitIndex); } this->GetHandler("script")->SetVerbose(this->Verbose); res = this->GetHandler("script")->ProcessHandler(); @@ -2187,14 +2232,12 @@ int cmCTest::ExecuteTests() // and Verbose is always on in this case this->ExtraVerbose = this->Verbose; this->Verbose = true; - cmCTest::t_TestingHandlers::iterator it; - for (it = this->TestingHandlers.begin(); it != this->TestingHandlers.end(); - ++it) { - it->second->SetVerbose(this->Verbose); - it->second->SetSubmitIndex(this->SubmitIndex); + for (auto& handler : this->TestingHandlers) { + handler.second->SetVerbose(this->Verbose); + handler.second->SetSubmitIndex(this->SubmitIndex); } std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); - if (!this->Initialize(cwd.c_str(), CM_NULLPTR)) { + if (!this->Initialize(cwd.c_str(), nullptr)) { res = 12; cmCTestLog(this, ERROR_MESSAGE, "Problem initializing the dashboard." << std::endl); @@ -2292,13 +2335,11 @@ int cmCTest::ReadCustomConfigurationFileTree(const char* dir, cmMakefile* mf) } if (found) { - cmCTest::t_TestingHandlers::iterator it; - for (it = this->TestingHandlers.begin(); it != this->TestingHandlers.end(); - ++it) { - cmCTestLog(this, DEBUG, - "* Read custom CTest configuration vectors for handler: " - << it->first << " (" << it->second << ")" << std::endl); - it->second->PopulateCustomVectors(mf); + for (auto& handler : this->TestingHandlers) { + cmCTestLog( + this, DEBUG, "* Read custom CTest configuration vectors for handler: " + << handler.first << " (" << handler.second << ")" << std::endl); + handler.second->PopulateCustomVectors(mf); } } @@ -2317,9 +2358,8 @@ void cmCTest::PopulateCustomVector(cmMakefile* mf, const std::string& def, vec.clear(); cmSystemTools::ExpandListArgument(dval, vec); - for (std::vector<std::string>::const_iterator it = vec.begin(); - it != vec.end(); ++it) { - cmCTestLog(this, DEBUG, " -- " << *it << std::endl); + for (std::string const& it : vec) { + cmCTestLog(this, DEBUG, " -- " << it << std::endl); } } @@ -2352,7 +2392,7 @@ std::string cmCTest::GetShortPathToFile(const char* cfname) bool inBld = bldRelpath.find("..") == std::string::npos; // TODO: Handle files with .. in their name - std::string* res = CM_NULLPTR; + std::string* res = nullptr; if (inSrc && inBld) { // If both have relative path with no dots, pick the shorter one @@ -2402,7 +2442,7 @@ void cmCTest::EmptyCTestConfiguration() void cmCTest::DetermineNextDayStop() { struct tm* lctime; - time_t current_time = time(CM_NULLPTR); + time_t current_time = time(nullptr); lctime = gmtime(¤t_time); int gm_hour = lctime->tm_hour; time_t gm_time = mktime(lctime); @@ -2486,7 +2526,7 @@ bool cmCTest::GetProduceXML() const char* cmCTest::GetSpecificTrack() { if (this->SpecificTrack.empty()) { - return CM_NULLPTR; + return nullptr; } return this->SpecificTrack.c_str(); } @@ -2494,7 +2534,7 @@ const char* cmCTest::GetSpecificTrack() void cmCTest::SetSpecificTrack(const char* track) { if (!track) { - this->SpecificTrack = ""; + this->SpecificTrack.clear(); return; } this->SpecificTrack = track; @@ -2546,25 +2586,21 @@ bool cmCTest::SetCTestConfigurationFromCMakeVariable( return true; } -bool cmCTest::RunCommand(const char* command, std::string* stdOut, - std::string* stdErr, int* retVal, const char* dir, - double timeout, Encoding encoding) +bool cmCTest::RunCommand(std::vector<std::string> const& args, + std::string* stdOut, std::string* stdErr, int* retVal, + const char* dir, + std::chrono::duration<double> timeout, + Encoding encoding) { - std::vector<std::string> args = cmSystemTools::ParseArguments(command); - - if (args.empty()) { - return false; - } - std::vector<const char*> argv; - for (std::vector<std::string>::const_iterator a = args.begin(); - a != args.end(); ++a) { - argv.push_back(a->c_str()); + argv.reserve(args.size() + 1); + for (std::string const& a : args) { + argv.push_back(a.c_str()); } - argv.push_back(CM_NULLPTR); + argv.push_back(nullptr); - *stdOut = ""; - *stdErr = ""; + stdOut->clear(); + stdErr->clear(); cmsysProcess* cp = cmsysProcess_New(); cmsysProcess_SetCommand(cp, &*argv.begin()); @@ -2584,7 +2620,7 @@ bool cmCTest::RunCommand(const char* command, std::string* stdOut, int res; bool done = false; while (!done) { - res = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR); + res = cmsysProcess_WaitForData(cp, &data, &length, nullptr); switch (res) { case cmsysProcess_Pipe_STDOUT: tempOutput.insert(tempOutput.end(), data, data + length); @@ -2608,7 +2644,7 @@ bool cmCTest::RunCommand(const char* command, std::string* stdOut, } } - cmsysProcess_WaitForExit(cp, CM_NULLPTR); + cmsysProcess_WaitForExit(cp, nullptr); if (!tempOutput.empty()) { processOutput.DecodeText(tempOutput, tempOutput); stdOut->append(&*tempOutput.begin(), tempOutput.size()); @@ -2652,7 +2688,7 @@ void cmCTest::SetOutputLogFileName(const char* name) { if (this->OutputLogFile) { delete this->OutputLogFile; - this->OutputLogFile = CM_NULLPTR; + this->OutputLogFile = nullptr; } if (name) { this->OutputLogFile = new cmGeneratedFileStream(name); @@ -2666,7 +2702,7 @@ static const char* cmCTestStringLogType[] = { "DEBUG", "HANDLER_VERBOSE_OUTPUT", "WARNING", "ERROR_MESSAGE", - CM_NULLPTR }; + nullptr }; #define cmCTestLogOutputFileLine(stream) \ if (this->ShowLineNumbers) { \ @@ -2765,10 +2801,10 @@ void cmCTest::Log(int logType, const char* file, int line, const char* msg, } } -double cmCTest::GetRemainingTimeAllowed() +std::chrono::duration<double> cmCTest::GetRemainingTimeAllowed() { if (!this->GetHandler("script")) { - return 1.0e7; + return std::chrono::duration<double>::max(); } cmCTestScriptHandler* ch = |