diff options
Diffstat (limited to 'Source/CTest')
22 files changed, 204 insertions, 148 deletions
diff --git a/Source/CTest/cmCTestBZR.cxx b/Source/CTest/cmCTestBZR.cxx index 0fe4ff4..81a866a 100644 --- a/Source/CTest/cmCTestBZR.cxx +++ b/Source/CTest/cmCTestBZR.cxx @@ -88,7 +88,6 @@ class cmCTestBZR::InfoParser : public cmCTestVC::LineParser public: InfoParser(cmCTestBZR* bzr, const char* prefix) : BZR(bzr) - , CheckOutFound(false) { this->SetLog(&bzr->Log, prefix); this->RegexCheckOut.compile("checkout of branch: *([^\t\r\n]+)$"); @@ -97,7 +96,7 @@ public: private: cmCTestBZR* BZR; - bool CheckOutFound; + bool CheckOutFound = false; cmsys::RegularExpression RegexCheckOut; cmsys::RegularExpression RegexParent; bool ProcessLine() override @@ -255,26 +254,26 @@ private: this->BZR->DoRevision(this->Rev, this->Changes); } else if (!this->CData.empty() && (name == "file" || name == "directory")) { - this->CurChange.Path.assign(&this->CData[0], this->CData.size()); + this->CurChange.Path.assign(this->CData.data(), this->CData.size()); cmSystemTools::ConvertToUnixSlashes(this->CurChange.Path); this->Changes.push_back(this->CurChange); } else if (!this->CData.empty() && name == "symlink") { // symlinks have an arobase at the end in the log - this->CurChange.Path.assign(&this->CData[0], this->CData.size() - 1); + this->CurChange.Path.assign(this->CData.data(), this->CData.size() - 1); cmSystemTools::ConvertToUnixSlashes(this->CurChange.Path); this->Changes.push_back(this->CurChange); } else if (!this->CData.empty() && name == "committer") { - this->Rev.Author.assign(&this->CData[0], this->CData.size()); + this->Rev.Author.assign(this->CData.data(), this->CData.size()); if (this->EmailRegex.find(this->Rev.Author)) { this->Rev.Author = this->EmailRegex.match(1); this->Rev.EMail = this->EmailRegex.match(2); } } else if (!this->CData.empty() && name == "timestamp") { - this->Rev.Date.assign(&this->CData[0], this->CData.size()); + this->Rev.Date.assign(this->CData.data(), this->CData.size()); } else if (!this->CData.empty() && name == "message") { - this->Rev.Log.assign(&this->CData[0], this->CData.size()); + this->Rev.Log.assign(this->CData.data(), this->CData.size()); } else if (!this->CData.empty() && name == "revno") { - this->Rev.Rev.assign(&this->CData[0], this->CData.size()); + this->Rev.Rev.assign(this->CData.data(), this->CData.size()); } this->CData.clear(); } @@ -389,7 +388,7 @@ bool cmCTestBZR::UpdateImpl() // For some reason bzr uses stderr to display the update status. OutputLogger out(this->Log, "pull-out> "); UpdateParser err(this, "pull-err> "); - return this->RunUpdateCommand(&bzr_update[0], &out, &err); + return this->RunUpdateCommand(bzr_update.data(), &out, &err); } bool cmCTestBZR::LoadRevisions() diff --git a/Source/CTest/cmCTestBinPacker.cxx b/Source/CTest/cmCTestBinPacker.cxx index e21b14d..6eb45fa 100644 --- a/Source/CTest/cmCTestBinPacker.cxx +++ b/Source/CTest/cmCTestBinPacker.cxx @@ -34,7 +34,7 @@ namespace { * more combinations can be tried. */ template <typename AllocationStrategy> -static bool AllocateCTestResources( +bool AllocateCTestResources( const std::map<std::string, cmCTestResourceAllocator::Resource>& resources, const std::vector<std::string>& resourcesSorted, std::size_t currentIndex, std::vector<cmCTestBinPackerAllocation*>& allocations) @@ -82,7 +82,7 @@ static bool AllocateCTestResources( } template <typename AllocationStrategy> -static bool AllocateCTestResources( +bool AllocateCTestResources( const std::map<std::string, cmCTestResourceAllocator::Resource>& resources, std::vector<cmCTestBinPackerAllocation>& allocations) { @@ -108,7 +108,7 @@ static bool AllocateCTestResources( // Do the actual allocation return AllocateCTestResources<AllocationStrategy>( - resources, resourcesSorted, std::size_t(0), allocationsPtr); + resources, resourcesSorted, static_cast<std::size_t>(0), allocationsPtr); } class RoundRobinAllocationStrategy diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx index e09b4dd..a39c52f 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.cxx +++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx @@ -44,9 +44,9 @@ int cmCTestBuildAndTestHandler::ProcessHandler() { this->Output.clear(); std::string output; - cmSystemTools::ResetErrorOccuredFlag(); + cmSystemTools::ResetErrorOccurredFlag(); int retv = this->RunCMakeAndTest(&this->Output); - cmSystemTools::ResetErrorOccuredFlag(); + cmSystemTools::ResetErrorOccurredFlag(); return retv; } diff --git a/Source/CTest/cmCTestBuildCommand.cxx b/Source/CTest/cmCTestBuildCommand.cxx index 6e7c9e1..71787ea 100644 --- a/Source/CTest/cmCTestBuildCommand.cxx +++ b/Source/CTest/cmCTestBuildCommand.cxx @@ -84,7 +84,7 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler() std::string e = cmStrCat("could not create generator named \"", *cmakeGeneratorName, '"'); this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return nullptr; } } diff --git a/Source/CTest/cmCTestCVS.cxx b/Source/CTest/cmCTestCVS.cxx index 1209e06..87ab762 100644 --- a/Source/CTest/cmCTestCVS.cxx +++ b/Source/CTest/cmCTestCVS.cxx @@ -101,7 +101,7 @@ bool cmCTestCVS::UpdateImpl() UpdateParser out(this, "up-out> "); UpdateParser err(this, "up-err> "); - return this->RunUpdateCommand(&cvs_update[0], &out, &err); + return this->RunUpdateCommand(cvs_update.data(), &out, &err); } class cmCTestCVS::LogParser : public cmCTestVC::LineParser @@ -111,7 +111,6 @@ public: LogParser(cmCTestCVS* cvs, const char* prefix, std::vector<Revision>& revs) : CVS(cvs) , Revisions(revs) - , Section(SectionHeader) { this->SetLog(&cvs->Log, prefix); this->RegexRevision.compile("^revision +([^ ]*) *$"); @@ -131,7 +130,7 @@ private: SectionRevisions, SectionEnd }; - SectionType Section; + SectionType Section = SectionHeader; Revision Rev; bool ProcessLine() override @@ -259,7 +258,7 @@ void cmCTestCVS::WriteXMLDirectory(cmXMLWriter& xml, std::string const& path, revisions.resize(2, this->Unknown); // Write the entry for this file with these revisions. - File f(fi.second, &revisions[0], &revisions[1]); + File f(fi.second, revisions.data(), revisions.data() + 1); this->WriteXMLEntry(xml, path, fi.first, full, f); } xml.EndElement(); // Directory diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 1b2f769..f7c6a9c 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -1218,11 +1218,8 @@ int cmCTestCoverageHandler::HandleGCovCoverage( cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open file: " << gcovFile << std::endl); } else { - long cnt = -1; std::string nl; while (cmSystemTools::GetLineFromStream(ifile, nl)) { - cnt++; - // Skip empty lines if (nl.empty()) { continue; @@ -1528,7 +1525,6 @@ int cmCTestCoverageHandler::HandleLCovCoverage( cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open file: " << lcovFile << std::endl); } else { - long cnt = -1; std::string nl; // Skip the first line @@ -1537,8 +1533,6 @@ int cmCTestCoverageHandler::HandleLCovCoverage( "File is ready, start reading." << std::endl, this->Quiet); while (cmSystemTools::GetLineFromStream(ifile, nl)) { - cnt++; - // Skip empty lines if (nl.empty()) { continue; @@ -2216,7 +2210,7 @@ int cmCTestCoverageHandler::GetLabelId(std::string const& label) { auto i = this->LabelIdMap.find(label); if (i == this->LabelIdMap.end()) { - int n = int(this->Labels.size()); + int n = static_cast<int>(this->Labels.size()); this->Labels.push_back(label); LabelIdMapType::value_type entry(label, n); i = this->LabelIdMap.insert(entry).first; diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 56f805c..b2fb069 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -176,7 +176,7 @@ bool cmCTestGIT::UpdateByFetchAndReset() // Fetch upstream refs. OutputLogger fetch_out(this->Log, "fetch-out> "); OutputLogger fetch_err(this->Log, "fetch-err> "); - if (!this->RunUpdateCommand(&git_fetch[0], &fetch_out, &fetch_err)) { + if (!this->RunUpdateCommand(git_fetch.data(), &fetch_out, &fetch_err)) { return false; } @@ -225,7 +225,7 @@ bool cmCTestGIT::UpdateByCustom(std::string const& custom) OutputLogger custom_out(this->Log, "custom-out> "); OutputLogger custom_err(this->Log, "custom-err> "); - return this->RunUpdateCommand(&git_custom[0], &custom_out, &custom_err); + return this->RunUpdateCommand(git_custom.data(), &custom_out, &custom_err); } bool cmCTestGIT::UpdateInternal() @@ -332,7 +332,6 @@ public: DiffParser(cmCTestGIT* git, const char* prefix) : LineParser('\0', false) , GIT(git) - , DiffField(DiffFieldNone) { this->SetLog(&git->Log, prefix); } @@ -349,7 +348,7 @@ protected: DiffFieldSrc, DiffFieldDst }; - DiffFieldType DiffField; + DiffFieldType DiffField = DiffFieldNone; Change CurChange; void DiffReset() @@ -454,7 +453,6 @@ class cmCTestGIT::CommitParser : public cmCTestGIT::DiffParser public: CommitParser(cmCTestGIT* git, const char* prefix) : DiffParser(git, prefix) - , Section(SectionHeader) { this->Separator = SectionSep[this->Section]; } @@ -469,7 +467,7 @@ private: SectionCount }; static char const SectionSep[SectionCount]; - SectionType Section; + SectionType Section = SectionHeader; Revision Rev; struct Person @@ -537,7 +535,8 @@ private: void NextSection() { - this->Section = SectionType((this->Section + 1) % SectionCount); + this->Section = + static_cast<SectionType>((this->Section + 1) % SectionCount); this->Separator = SectionSep[this->Section]; if (this->Section == SectionHeader) { this->GIT->DoRevision(this->Rev, this->Changes); diff --git a/Source/CTest/cmCTestGenericHandler.cxx b/Source/CTest/cmCTestGenericHandler.cxx index 9800192..1c292c7 100644 --- a/Source/CTest/cmCTestGenericHandler.cxx +++ b/Source/CTest/cmCTestGenericHandler.cxx @@ -137,7 +137,7 @@ bool cmCTestGenericHandler::StartResultingXML(cmCTest::Part part, "maybe you forgot to call ctest_start() before calling " "ctest_configure()." << std::endl); - cmSystemTools::SetFatalErrorOccured(); + cmSystemTools::SetFatalErrorOccurred(); return false; } if (!this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(), ostr.str(), diff --git a/Source/CTest/cmCTestHG.cxx b/Source/CTest/cmCTestHG.cxx index 5f4581e..97b01ba 100644 --- a/Source/CTest/cmCTestHG.cxx +++ b/Source/CTest/cmCTestHG.cxx @@ -157,7 +157,7 @@ bool cmCTestHG::UpdateImpl() OutputLogger out(this->Log, "update-out> "); OutputLogger err(this->Log, "update-err> "); - return this->RunUpdateCommand(&hg_update[0], &out, &err); + return this->RunUpdateCommand(hg_update.data(), &out, &err); } class cmCTestHG::LogParser @@ -213,13 +213,13 @@ private: if (name == "logentry") { this->HG->DoRevision(this->Rev, this->Changes); } else if (!this->CData.empty() && name == "author") { - this->Rev.Author.assign(&this->CData[0], this->CData.size()); + this->Rev.Author.assign(this->CData.data(), this->CData.size()); } else if (!this->CData.empty() && name == "email") { - this->Rev.EMail.assign(&this->CData[0], this->CData.size()); + this->Rev.EMail.assign(this->CData.data(), this->CData.size()); } else if (!this->CData.empty() && name == "date") { - this->Rev.Date.assign(&this->CData[0], this->CData.size()); + this->Rev.Date.assign(this->CData.data(), this->CData.size()); } else if (!this->CData.empty() && name == "msg") { - this->Rev.Log.assign(&this->CData[0], this->CData.size()); + this->Rev.Log.assign(this->CData.data(), this->CData.size()); } else if (!this->CData.empty() && name == "files") { std::vector<std::string> paths = this->SplitCData(); for (std::string const& path : paths) { diff --git a/Source/CTest/cmCTestHandlerCommand.cxx b/Source/CTest/cmCTestHandlerCommand.cxx index ea8feaa..5494d20 100644 --- a/Source/CTest/cmCTestHandlerCommand.cxx +++ b/Source/CTest/cmCTestHandlerCommand.cxx @@ -29,8 +29,8 @@ class SaveRestoreErrorState public: SaveRestoreErrorState() { - this->InitialErrorState = cmSystemTools::GetErrorOccuredFlag(); - cmSystemTools::ResetErrorOccuredFlag(); // rest the error state + this->InitialErrorState = cmSystemTools::GetErrorOccurredFlag(); + cmSystemTools::ResetErrorOccurredFlag(); // rest the error state this->CaptureCMakeErrorValue = false; } // if the function has a CAPTURE_CMAKE_ERROR then we should restore @@ -44,21 +44,21 @@ public: // otherwise leave it be what it is if (!this->CaptureCMakeErrorValue) { if (this->InitialErrorState) { - cmSystemTools::SetErrorOccured(); + cmSystemTools::SetErrorOccurred(); } return; } // if we have saved the error in a return variable // then put things back exactly like they were - bool currentState = cmSystemTools::GetErrorOccuredFlag(); + bool currentState = cmSystemTools::GetErrorOccurredFlag(); // if the state changed during this command we need // to handle it, if not then nothing needs to be done if (currentState != this->InitialErrorState) { // restore the initial error state if (this->InitialErrorState) { - cmSystemTools::SetErrorOccured(); + cmSystemTools::SetErrorOccurred(); } else { - cmSystemTools::ResetErrorOccuredFlag(); + cmSystemTools::ResetErrorOccurredFlag(); } } } @@ -212,7 +212,7 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args, // log the error message if there was an error if (captureCMakeError) { const char* returnString = "0"; - if (cmSystemTools::GetErrorOccuredFlag()) { + if (cmSystemTools::GetErrorOccurredFlag()) { returnString = "-1"; std::string const& err = status.GetError(); // print out the error if it is not "unknown error" which means diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index 6bb8e79..788845b 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -371,7 +371,8 @@ void cmCTestMemCheckHandler::GenerateCTestXML(cmXMLWriter& xml) } this->CleanTestOutput( memcheckstr, - static_cast<size_t>(this->CustomMaximumFailedTestOutputSize)); + static_cast<size_t>(this->CustomMaximumFailedTestOutputSize), + this->TestOutputTruncation); this->WriteTestResultHeader(xml, result); xml.StartElement("Results"); int memoryErrors = 0; @@ -1206,7 +1207,8 @@ bool cmCTestMemCheckHandler::ProcessMemCheckCudaOutput( if (failure >= 0) { ostr << "<b>" << this->ResultStrings[failure] << "</b> "; - if (results.empty() || unsigned(failure) > results.size() - 1) { + if (results.empty() || + static_cast<unsigned>(failure) > results.size() - 1) { results.push_back(1); } else { results[failure]++; diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index d90c4a6..abd1aa6 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -1284,10 +1284,8 @@ void cmCTestMultiProcessHandler::PrintTestList() } this->TestHandler->SetMaxIndex(this->FindMaxIndex()); - int count = 0; for (auto& it : this->Properties) { - count++; cmCTestTestHandler::cmCTestTestProperties& p = *it.second; // Don't worry if this fails, we are only showing the test list, not diff --git a/Source/CTest/cmCTestP4.cxx b/Source/CTest/cmCTestP4.cxx index 50c9c16..0e67c41 100644 --- a/Source/CTest/cmCTestP4.cxx +++ b/Source/CTest/cmCTestP4.cxx @@ -118,7 +118,6 @@ class cmCTestP4::DiffParser : public cmCTestVC::LineParser public: DiffParser(cmCTestP4* p4, const char* prefix) : P4(p4) - , AlreadyNotified(false) { this->SetLog(&this->P4->Log, prefix); this->RegexDiff.compile("^==== (.*)#[0-9]+ - (.*)"); @@ -126,7 +125,7 @@ public: private: cmCTestP4* P4; - bool AlreadyNotified; + bool AlreadyNotified = false; std::string CurrentPath; cmsys::RegularExpression RegexDiff; @@ -161,7 +160,7 @@ cmCTestP4::User cmCTestP4::GetUserData(const std::string& username) UserParser out(this, "users-out> "); OutputLogger err(this->Log, "users-err> "); - this->RunChild(&p4_users[0], &out, &err); + this->RunChild(p4_users.data(), &out, &err); // The user should now be added to the map. Search again. it = this->Users.find(username); @@ -193,7 +192,6 @@ public: DescribeParser(cmCTestP4* p4, const char* prefix) : LineParser('\n', false) , P4(p4) - , Section(SectionHeader) { this->SetLog(&this->P4->Log, prefix); this->RegexHeader.compile("^Change ([0-9]+) by (.+)@(.+) on (.*)$"); @@ -216,7 +214,7 @@ private: SectionDiff, SectionCount }; - SectionType Section; + SectionType Section = SectionHeader; Revision Rev; bool ProcessLine() override @@ -250,7 +248,8 @@ private: this->Rev = Revision(); } - this->Section = SectionType((this->Section + 1) % SectionCount); + this->Section = + static_cast<SectionType>((this->Section + 1) % SectionCount); } void DoHeaderLine() @@ -354,7 +353,7 @@ std::string cmCTestP4::GetWorkingRevision() IdentifyParser out(this, "p4_changes-out> ", rev); OutputLogger err(this->Log, "p4_changes-err> "); - bool result = this->RunChild(&p4_identify[0], &out, &err); + bool result = this->RunChild(p4_identify.data(), &out, &err); // If there was a problem contacting the server return "<unknown>" if (!result) { @@ -418,7 +417,7 @@ bool cmCTestP4::LoadRevisions() OutputLogger err(this->Log, "p4_changes-err> "); this->ChangeLists.clear(); - this->RunChild(&p4_changes[0], &out, &err); + this->RunChild(p4_changes.data(), &out, &err); if (this->ChangeLists.empty()) { return true; @@ -435,7 +434,7 @@ bool cmCTestP4::LoadRevisions() DescribeParser outDescribe(this, "p4_describe-out> "); OutputLogger errDescribe(this->Log, "p4_describe-err> "); - this->RunChild(&p4_describe[0], &outDescribe, &errDescribe); + this->RunChild(p4_describe.data(), &outDescribe, &errDescribe); } return true; } @@ -455,7 +454,7 @@ bool cmCTestP4::LoadModifications() DiffParser out(this, "p4_diff-out> "); OutputLogger err(this->Log, "p4_diff-err> "); - this->RunChild(&p4_diff[0], &out, &err); + this->RunChild(p4_diff.data(), &out, &err); return true; } @@ -473,7 +472,7 @@ bool cmCTestP4::UpdateCustom(const std::string& custom) OutputLogger custom_out(this->Log, "p4_customsync-out> "); OutputLogger custom_err(this->Log, "p4_customsync-err> "); - return this->RunUpdateCommand(&p4_custom[0], &custom_out, &custom_err); + return this->RunUpdateCommand(p4_custom.data(), &custom_out, &custom_err); } bool cmCTestP4::UpdateImpl() @@ -523,5 +522,5 @@ bool cmCTestP4::UpdateImpl() OutputLogger out(this->Log, "p4_sync-out> "); OutputLogger err(this->Log, "p4_sync-err> "); - return this->RunUpdateCommand(&p4_sync[0], &out, &err); + return this->RunUpdateCommand(p4_sync.data(), &out, &err); } diff --git a/Source/CTest/cmCTestResourceSpec.cxx b/Source/CTest/cmCTestResourceSpec.cxx index 101dc2c..142b07d 100644 --- a/Source/CTest/cmCTestResourceSpec.cxx +++ b/Source/CTest/cmCTestResourceSpec.cxx @@ -19,6 +19,8 @@ #include "cmJSONHelpers.h" namespace { +using JSONHelperBuilder = + cmJSONHelperBuilder<cmCTestResourceSpec::ReadFileResult>; const cmsys::RegularExpression IdentifierRegex{ "^[a-z_][a-z0-9_]*$" }; const cmsys::RegularExpression IdRegex{ "^[a-z0-9_]+$" }; @@ -34,21 +36,19 @@ struct TopVersion }; auto const VersionFieldHelper = - cmJSONIntHelper<cmCTestResourceSpec::ReadFileResult>( - cmCTestResourceSpec::ReadFileResult::READ_OK, - cmCTestResourceSpec::ReadFileResult::INVALID_VERSION); + JSONHelperBuilder::Int(cmCTestResourceSpec::ReadFileResult::READ_OK, + cmCTestResourceSpec::ReadFileResult::INVALID_VERSION); -auto const VersionHelper = - cmJSONRequiredHelper<Version, cmCTestResourceSpec::ReadFileResult>( - cmCTestResourceSpec::ReadFileResult::NO_VERSION, - cmJSONObjectHelper<Version, cmCTestResourceSpec::ReadFileResult>( - cmCTestResourceSpec::ReadFileResult::READ_OK, - cmCTestResourceSpec::ReadFileResult::INVALID_VERSION) - .Bind("major"_s, &Version::Major, VersionFieldHelper) - .Bind("minor"_s, &Version::Minor, VersionFieldHelper)); +auto const VersionHelper = JSONHelperBuilder::Required<Version>( + cmCTestResourceSpec::ReadFileResult::NO_VERSION, + JSONHelperBuilder::Object<Version>( + cmCTestResourceSpec::ReadFileResult::READ_OK, + cmCTestResourceSpec::ReadFileResult::INVALID_VERSION) + .Bind("major"_s, &Version::Major, VersionFieldHelper) + .Bind("minor"_s, &Version::Minor, VersionFieldHelper)); auto const RootVersionHelper = - cmJSONObjectHelper<TopVersion, cmCTestResourceSpec::ReadFileResult>( + JSONHelperBuilder::Object<TopVersion>( cmCTestResourceSpec::ReadFileResult::READ_OK, cmCTestResourceSpec::ReadFileResult::INVALID_ROOT) .Bind("version"_s, &TopVersion::Version, VersionHelper, false); @@ -56,7 +56,7 @@ auto const RootVersionHelper = cmCTestResourceSpec::ReadFileResult ResourceIdHelper(std::string& out, const Json::Value* value) { - auto result = cmJSONStringHelper( + auto result = JSONHelperBuilder::String( cmCTestResourceSpec::ReadFileResult::READ_OK, cmCTestResourceSpec::ReadFileResult::INVALID_RESOURCE)(out, value); if (result != cmCTestResourceSpec::ReadFileResult::READ_OK) { @@ -70,27 +70,24 @@ cmCTestResourceSpec::ReadFileResult ResourceIdHelper(std::string& out, } auto const ResourceHelper = - cmJSONObjectHelper<cmCTestResourceSpec::Resource, - cmCTestResourceSpec::ReadFileResult>( + JSONHelperBuilder::Object<cmCTestResourceSpec::Resource>( cmCTestResourceSpec::ReadFileResult::READ_OK, cmCTestResourceSpec::ReadFileResult::INVALID_RESOURCE) .Bind("id"_s, &cmCTestResourceSpec::Resource::Id, ResourceIdHelper) .Bind("slots"_s, &cmCTestResourceSpec::Resource::Capacity, - cmJSONUIntHelper( + JSONHelperBuilder::UInt( cmCTestResourceSpec::ReadFileResult::READ_OK, cmCTestResourceSpec::ReadFileResult::INVALID_RESOURCE, 1), false); auto const ResourceListHelper = - cmJSONVectorHelper<cmCTestResourceSpec::Resource, - cmCTestResourceSpec::ReadFileResult>( + JSONHelperBuilder::Vector<cmCTestResourceSpec::Resource>( cmCTestResourceSpec::ReadFileResult::READ_OK, cmCTestResourceSpec::ReadFileResult::INVALID_RESOURCE_TYPE, ResourceHelper); auto const ResourceMapHelper = - cmJSONMapFilterHelper<std::vector<cmCTestResourceSpec::Resource>, - cmCTestResourceSpec::ReadFileResult>( + JSONHelperBuilder::MapFilter<std::vector<cmCTestResourceSpec::Resource>>( cmCTestResourceSpec::ReadFileResult::READ_OK, cmCTestResourceSpec::ReadFileResult::INVALID_SOCKET_SPEC, ResourceListHelper, [](const std::string& key) -> bool { @@ -98,7 +95,7 @@ auto const ResourceMapHelper = return IdentifierRegex.find(key.c_str(), match); }); -auto const SocketSetHelper = cmJSONVectorHelper< +auto const SocketSetHelper = JSONHelperBuilder::Vector< std::map<std::string, std::vector<cmCTestResourceSpec::Resource>>>( cmCTestResourceSpec::ReadFileResult::READ_OK, cmCTestResourceSpec::ReadFileResult::INVALID_SOCKET_SPEC, ResourceMapHelper); @@ -125,16 +122,14 @@ cmCTestResourceSpec::ReadFileResult SocketHelper( } auto const LocalRequiredHelper = - cmJSONRequiredHelper<cmCTestResourceSpec::Socket, - cmCTestResourceSpec::ReadFileResult>( + JSONHelperBuilder::Required<cmCTestResourceSpec::Socket>( cmCTestResourceSpec::ReadFileResult::INVALID_SOCKET_SPEC, SocketHelper); -auto const RootHelper = - cmJSONObjectHelper<cmCTestResourceSpec, cmCTestResourceSpec::ReadFileResult>( - cmCTestResourceSpec::ReadFileResult::READ_OK, - cmCTestResourceSpec::ReadFileResult::INVALID_ROOT) - .Bind("local", &cmCTestResourceSpec::LocalSocket, LocalRequiredHelper, - false); +auto const RootHelper = JSONHelperBuilder::Object<cmCTestResourceSpec>( + cmCTestResourceSpec::ReadFileResult::READ_OK, + cmCTestResourceSpec::ReadFileResult::INVALID_ROOT) + .Bind("local", &cmCTestResourceSpec::LocalSocket, + LocalRequiredHelper, false); } cmCTestResourceSpec::ReadFileResult cmCTestResourceSpec::ReadFromJSONFile( diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 6cd3b09..2a2cb1c 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -277,7 +277,8 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started) static_cast<size_t>( this->TestResult.Status == cmCTestTestHandler::COMPLETED ? this->TestHandler->CustomMaximumPassedTestOutputSize - : this->TestHandler->CustomMaximumFailedTestOutputSize)); + : this->TestHandler->CustomMaximumFailedTestOutputSize), + this->TestHandler->TestOutputTruncation); } this->TestResult.Reason = reason; if (this->TestHandler->LogFile) { @@ -694,6 +695,14 @@ void cmCTestRunTest::ComputeArguments() << " command: " << testCommand << std::endl); // Print any test-specific env vars in verbose mode + if (!this->TestProperties->Directory.empty()) { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + this->Index << ": " + << "Working Directory: " + << this->TestProperties->Directory << std::endl); + } + + // Print any test-specific env vars in verbose mode if (!this->TestProperties->Environment.empty()) { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index << ": " diff --git a/Source/CTest/cmCTestSVN.cxx b/Source/CTest/cmCTestSVN.cxx index 4692dbd..4c98fdf 100644 --- a/Source/CTest/cmCTestSVN.cxx +++ b/Source/CTest/cmCTestSVN.cxx @@ -286,9 +286,9 @@ bool cmCTestSVN::RunSVNCommand(std::vector<char const*> const& parameters, args.push_back(nullptr); if (strcmp(parameters[0], "update") == 0) { - return this->RunUpdateCommand(&args[0], out, err); + return this->RunUpdateCommand(args.data(), out, err); } - return this->RunChild(&args[0], out, err); + return this->RunChild(args.data(), out, err); } class cmCTestSVN::LogParser @@ -353,16 +353,16 @@ private: if (name == "logentry") { this->SVN->DoRevisionSVN(this->Rev, this->Changes); } else if (!this->CData.empty() && name == "path") { - std::string orig_path(&this->CData[0], this->CData.size()); + std::string orig_path(this->CData.data(), this->CData.size()); std::string new_path = this->SVNRepo.BuildLocalPath(orig_path); this->CurChange.Path.assign(new_path); this->Changes.push_back(this->CurChange); } else if (!this->CData.empty() && name == "author") { - this->Rev.Author.assign(&this->CData[0], this->CData.size()); + this->Rev.Author.assign(this->CData.data(), this->CData.size()); } else if (!this->CData.empty() && name == "date") { - this->Rev.Date.assign(&this->CData[0], this->CData.size()); + this->Rev.Date.assign(this->CData.data(), this->CData.size()); } else if (!this->CData.empty() && name == "msg") { - this->Rev.Log.assign(&this->CData[0], this->CData.size()); + this->Rev.Log.assign(this->CData.data(), this->CData.size()); } this->CData.clear(); } diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index 16c0a0e..5a66f82 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -277,7 +277,7 @@ void cmCTestScriptHandler::CreateCMake() int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) { // Reset the error flag so that the script is read in no matter what - cmSystemTools::ResetErrorOccuredFlag(); + cmSystemTools::ResetErrorOccurredFlag(); // if the argument has a , in it then it needs to be broken into the fist // argument (which is the script) and the second argument which will be @@ -341,7 +341,7 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) std::string systemFile = this->Makefile->GetModulesFile("CTestScriptMode.cmake"); if (!this->Makefile->ReadListFile(systemFile) || - cmSystemTools::GetErrorOccuredFlag()) { + cmSystemTools::GetErrorOccurredFlag()) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Error in read:" << systemFile << "\n"); return 2; @@ -356,10 +356,10 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) // finally read in the script if (!this->Makefile->ReadListFile(script) || - cmSystemTools::GetErrorOccuredFlag()) { + cmSystemTools::GetErrorOccurredFlag()) { // Reset the error flag so that it can run more than // one script with an error when you use ctest_run_script. - cmSystemTools::ResetErrorOccuredFlag(); + cmSystemTools::ResetErrorOccurredFlag(); return 2; } diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index fae5e30..da085a6 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -56,7 +56,7 @@ private: { std::string val; if (!this->CurrentValue.empty()) { - val.assign(&this->CurrentValue[0], this->CurrentValue.size()); + val.assign(this->CurrentValue.data(), this->CurrentValue.size()); } return val; } @@ -124,7 +124,7 @@ void cmCTestSubmitHandler::Initialize() { // We submit all available parts by default. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount; - p = cmCTest::Part(p + 1)) { + p = static_cast<cmCTest::Part>(p + 1)) { this->SubmitPart[p] = true; } this->HasWarnings = false; @@ -730,15 +730,15 @@ int cmCTestSubmitHandler::ProcessHandler() return -1; } - if (getenv("HTTP_PROXY")) { + if (char const* proxy = getenv("HTTP_PROXY")) { this->HTTPProxyType = 1; - this->HTTPProxy = getenv("HTTP_PROXY"); + this->HTTPProxy = proxy; if (getenv("HTTP_PROXY_PORT")) { this->HTTPProxy += ":"; this->HTTPProxy += getenv("HTTP_PROXY_PORT"); } - if (getenv("HTTP_PROXY_TYPE")) { - std::string type = getenv("HTTP_PROXY_TYPE"); + if (char const* proxy_type = getenv("HTTP_PROXY_TYPE")) { + std::string type = proxy_type; // HTTP/SOCKS4/SOCKS5 if (type == "HTTP") { this->HTTPProxyType = 1; @@ -810,7 +810,7 @@ int cmCTestSubmitHandler::ProcessHandler() // Query parts for files to submit. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount; - p = cmCTest::Part(p + 1)) { + p = static_cast<cmCTest::Part>(p + 1)) { // Skip parts we are not submitting. if (!this->SubmitPart[p]) { continue; @@ -894,9 +894,8 @@ void cmCTestSubmitHandler::SelectParts(std::set<cmCTest::Part> const& parts) { // Check whether each part is selected. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount; - p = cmCTest::Part(p + 1)) { - this->SubmitPart[p] = - (std::set<cmCTest::Part>::const_iterator(parts.find(p)) != parts.end()); + p = static_cast<cmCTest::Part>(p + 1)) { + this->SubmitPart[p] = parts.find(p) != parts.end(); } } diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 5a3a8d0..daaf5fd 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -281,6 +281,7 @@ cmCTestTestHandler::cmCTestTestHandler() this->CustomMaximumPassedTestOutputSize = 1 * 1024; this->CustomMaximumFailedTestOutputSize = 300 * 1024; + this->TestOutputTruncation = cmCTestTypes::TruncationMode::Tail; this->MemCheck = false; @@ -325,6 +326,7 @@ void cmCTestTestHandler::Initialize() this->CustomPostTest.clear(); this->CustomMaximumPassedTestOutputSize = 1 * 1024; this->CustomMaximumFailedTestOutputSize = 300 * 1024; + this->TestOutputTruncation = cmCTestTypes::TruncationMode::Tail; this->TestsToRun.clear(); @@ -358,6 +360,15 @@ void cmCTestTestHandler::PopulateCustomVectors(cmMakefile* mf) this->CTest->PopulateCustomInteger( mf, "CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE", this->CustomMaximumFailedTestOutputSize); + + cmValue dval = mf->GetDefinition("CTEST_CUSTOM_TEST_OUTPUT_TRUNCATION"); + if (dval) { + if (!this->SetTestOutputTruncation(dval)) { + cmCTestLog(this->CTest, ERROR_MESSAGE, + "Invalid value for CTEST_CUSTOM_TEST_OUTPUT_TRUNCATION: " + << dval << std::endl); + } + } } int cmCTestTestHandler::PreProcessHandler() @@ -579,7 +590,8 @@ void cmCTestTestHandler::LogTestSummary(const std::vector<std::string>& passed, { std::size_t total = passed.size() + failed.size(); - float percent = float(passed.size()) * 100.0f / float(total); + float percent = + static_cast<float>(passed.size()) * 100.0f / static_cast<float>(total); if (!failed.empty() && percent > 99) { percent = 99; } @@ -1810,7 +1822,7 @@ bool cmCTestTestHandler::GetListOfTests() if (!mf.ReadListFile(testFilename)) { return false; } - if (cmSystemTools::GetErrorOccuredFlag()) { + if (cmSystemTools::GetErrorOccurredFlag()) { // SEND_ERROR or FATAL_ERROR in CTestTestfile or TEST_INCLUDE_FILES return false; } @@ -2076,6 +2088,20 @@ void cmCTestTestHandler::SetExcludeRegExp(const std::string& arg) this->ExcludeRegExp = arg; } +bool cmCTestTestHandler::SetTestOutputTruncation(const std::string& mode) +{ + if (mode == "tail") { + this->TestOutputTruncation = cmCTestTypes::TruncationMode::Tail; + } else if (mode == "middle") { + this->TestOutputTruncation = cmCTestTypes::TruncationMode::Middle; + } else if (mode == "head") { + this->TestOutputTruncation = cmCTestTypes::TruncationMode::Head; + } else { + return false; + } + return true; +} + void cmCTestTestHandler::SetTestsToRunInformation(cmValue in) { if (!in) { @@ -2094,41 +2120,58 @@ void cmCTestTestHandler::SetTestsToRunInformation(cmValue in) } } -void cmCTestTestHandler::CleanTestOutput(std::string& output, size_t length) +void cmCTestTestHandler::CleanTestOutput(std::string& output, size_t length, + cmCTestTypes::TruncationMode truncate) { if (!length || length >= output.size() || output.find("CTEST_FULL_OUTPUT") != std::string::npos) { return; } - // Truncate at given length but do not break in the middle of a multi-byte - // UTF-8 encoding. - char const* const begin = output.c_str(); - char const* const end = begin + output.size(); - char const* const truncate = begin + length; - char const* current = begin; - while (current < truncate) { - unsigned int ch; - if (const char* next = cm_utf8_decode_character(current, end, &ch)) { - if (next > truncate) { - break; + // Advance n bytes in string delimited by begin/end but do not break in the + // middle of a multi-byte UTF-8 encoding. + auto utf8_advance = [](char const* const begin, char const* const end, + size_t n) -> const char* { + char const* const stop = begin + n; + char const* current = begin; + while (current < stop) { + unsigned int ch; + if (const char* next = cm_utf8_decode_character(current, end, &ch)) { + if (next > stop) { + break; + } + current = next; + } else // Bad byte will be handled by cmXMLWriter. + { + ++current; } - current = next; - } else // Bad byte will be handled by cmXMLWriter. - { - ++current; } - } - output.erase(current - begin); + return current; + }; + + // Truncation message. + const std::string msg = + "\n[This part of the test output was removed since it " + "exceeds the threshold of " + + std::to_string(length) + " bytes.]\n"; + + char const* const begin = output.c_str(); + char const* const end = begin + output.size(); - // Append truncation message. - std::ostringstream msg; - msg << "...\n" - "The rest of the test output was removed since it exceeds the " - "threshold " - "of " - << length << " bytes.\n"; - output += msg.str(); + // Erase head, middle or tail of output. + if (truncate == cmCTestTypes::TruncationMode::Head) { + char const* current = utf8_advance(begin, end, output.size() - length); + output.erase(0, current - begin); + output.insert(0, msg + "..."); + } else if (truncate == cmCTestTypes::TruncationMode::Middle) { + char const* current = utf8_advance(begin, end, length / 2); + output.erase(current - begin, output.size() - length); + output.insert(current - begin, "..." + msg + "..."); + } else { // default or "tail" + char const* current = utf8_advance(begin, end, length); + output.erase(current - begin); + output += ("..." + msg); + } } bool cmCTestTestHandler::SetTestsProperties( @@ -2448,22 +2491,19 @@ bool cmCTestTestHandler::WriteJUnitXML() // Iterate over the test results to get the number of tests that // passed, failed, etc. auto num_tests = 0; - auto num_passed = 0; auto num_failed = 0; auto num_notrun = 0; auto num_disabled = 0; SetOfTests resultsSet(this->TestResults.begin(), this->TestResults.end()); for (cmCTestTestResult const& result : resultsSet) { num_tests++; - if (result.Status == cmCTestTestHandler::COMPLETED) { - num_passed++; - } else if (result.Status == cmCTestTestHandler::NOT_RUN) { + if (result.Status == cmCTestTestHandler::NOT_RUN) { if (result.CompletionStatus == "Disabled") { num_disabled++; } else { num_notrun++; } - } else { + } else if (result.Status != cmCTestTestHandler::COMPLETED) { num_failed++; } } diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 135e764..d0049da 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -19,6 +19,7 @@ #include "cmCTest.h" #include "cmCTestGenericHandler.h" #include "cmCTestResourceSpec.h" +#include "cmCTestTypes.h" #include "cmDuration.h" #include "cmListFileCache.h" #include "cmValue.h" @@ -32,6 +33,7 @@ class cmXMLWriter; */ class cmCTestTestHandler : public cmCTestGenericHandler { + friend class cmCTest; friend class cmCTestRunTest; friend class cmCTestMultiProcessHandler; @@ -80,6 +82,9 @@ public: this->CustomMaximumFailedTestOutputSize = n; } + //! Set test output truncation mode. Return false if unknown mode. + bool SetTestOutputTruncation(const std::string& mode); + //! pass the -I argument down void SetTestsToRunInformation(cmValue); @@ -242,8 +247,9 @@ protected: void AttachFile(cmXMLWriter& xml, std::string const& file, std::string const& name); - //! Clean test output to specified length - void CleanTestOutput(std::string& output, size_t length); + //! Clean test output to specified length and truncation mode + void CleanTestOutput(std::string& output, size_t length, + cmCTestTypes::TruncationMode truncate); cmDuration ElapsedTestingTime; @@ -258,6 +264,7 @@ protected: bool MemCheck; int CustomMaximumPassedTestOutputSize; int CustomMaximumFailedTestOutputSize; + cmCTestTypes::TruncationMode TestOutputTruncation; int MaxIndex; public: diff --git a/Source/CTest/cmCTestTypes.h b/Source/CTest/cmCTestTypes.h new file mode 100644 index 0000000..843d27a --- /dev/null +++ b/Source/CTest/cmCTestTypes.h @@ -0,0 +1,16 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ + +#pragma once + +#include "cmConfigure.h" // IWYU pragma: keep + +namespace cmCTestTypes { + +enum class TruncationMode +{ // Test output truncation mode + Tail, + Middle, + Head +}; +} diff --git a/Source/CTest/cmCTestVC.cxx b/Source/CTest/cmCTestVC.cxx index d5711c5..609ccba 100644 --- a/Source/CTest/cmCTestVC.cxx +++ b/Source/CTest/cmCTestVC.cxx @@ -66,7 +66,7 @@ bool cmCTestVC::InitialCheckout(const std::string& command) this->Log << "--- Begin Initial Checkout ---\n"; OutputLogger out(this->Log, "co-out> "); OutputLogger err(this->Log, "co-err> "); - bool result = this->RunChild(&vc_co[0], &out, &err, parent.c_str()); + bool result = this->RunChild(vc_co.data(), &out, &err, parent.c_str()); this->Log << "--- End Initial Checkout ---\n"; if (!result) { cmCTestLog(this->CTest, ERROR_MESSAGE, |