From 4e9075ebe2646c6bdf51b04aca26b30b46129fd1 Mon Sep 17 00:00:00 2001 From: AJIOB Date: Fri, 25 Sep 2026 20:21:06 +0000 Subject: [PATCH] Source: reduce ostringstream usage for CTest --- Source/CTest/cmCTestBZR.cxx | 11 +- Source/CTest/cmCTestBuildCommand.cxx | 22 +- Source/CTest/cmCTestBuildHandler.cxx | 165 +++--- Source/CTest/cmCTestCVS.cxx | 7 +- Source/CTest/cmCTestConfigureCommand.cxx | 28 +- Source/CTest/cmCTestCoverageHandler.cxx | 615 ++++++++------------ Source/CTest/cmCTestCurl.cxx | 44 +- Source/CTest/cmCTestGIT.cxx | 6 +- Source/CTest/cmCTestGlobalVC.cxx | 11 +- Source/CTest/cmCTestHG.cxx | 6 +- Source/CTest/cmCTestHandlerCommand.cxx | 18 +- Source/CTest/cmCTestMemCheckHandler.cxx | 194 +++--- Source/CTest/cmCTestMultiProcessHandler.cxx | 139 ++--- Source/CTest/cmCTestP4.cxx | 11 +- Source/CTest/cmCTestRunTest.cxx | 209 +++---- Source/CTest/cmCTestSVN.cxx | 10 +- Source/CTest/cmCTestScriptHandler.cxx | 28 +- Source/CTest/cmCTestStartCommand.cxx | 63 +- Source/CTest/cmCTestSubmitCommand.cxx | 28 +- Source/CTest/cmCTestSubmitHandler.cxx | 232 +++----- Source/CTest/cmCTestTestCommand.cxx | 13 +- Source/CTest/cmCTestTestHandler.cxx | 225 +++---- Source/CTest/cmCTestUpdateCommand.cxx | 33 +- Source/CTest/cmCTestUploadCommand.cxx | 7 +- Source/CTest/cmCTestVC.cxx | 13 +- Source/CTest/cmParseBlanketJSCoverage.cxx | 27 +- Source/CTest/cmParseCacheCoverage.cxx | 42 +- Source/CTest/cmParseCoberturaCoverage.cxx | 13 +- Source/CTest/cmParseDelphiCoverage.cxx | 17 +- Source/CTest/cmParseGTMCoverage.cxx | 26 +- Source/CTest/cmParseJacocoCoverage.cxx | 39 +- Source/CTest/cmParseMumpsCoverage.cxx | 10 +- Source/CTest/cmParsePHPCoverage.cxx | 16 +- Source/CTest/cmProcess.cxx | 16 +- Source/cmCTest.cxx | 385 ++++++------ Source/cmCTest.h | 27 +- Source/cmExportCommand.cxx | 1 + Source/cmStringAlgorithms.h | 13 + 38 files changed, 1185 insertions(+), 1585 deletions(-) diff --git a/Source/CTest/cmCTestBZR.cxx b/Source/CTest/cmCTestBZR.cxx index 81bacaadf6..4d1fda428f 100644 --- a/Source/CTest/cmCTestBZR.cxx +++ b/Source/CTest/cmCTestBZR.cxx @@ -158,8 +158,7 @@ bool cmCTestBZR::NoteOldRevision() this->OldRevision = this->LoadInfo(); this->Log << "Revision before update: " << this->OldRevision << "\n"; cmCTestLog(this->CTest, HANDLER_OUTPUT, - " Old revision of repository is: " << this->OldRevision - << "\n"); + " Old revision of repository is: ", this->OldRevision, '\n'); this->PriorRev.Rev = this->OldRevision; return true; } @@ -169,8 +168,7 @@ bool cmCTestBZR::NoteNewRevision() this->NewRevision = this->LoadInfo(); this->Log << "Revision after update: " << this->NewRevision << "\n"; cmCTestLog(this->CTest, HANDLER_OUTPUT, - " New revision of repository is: " << this->NewRevision - << "\n"); + " New revision of repository is: ", this->NewRevision, '\n'); this->Log << "URL = " << this->URL << "\n"; return true; } @@ -392,8 +390,7 @@ bool cmCTestBZR::LoadRevisions() { cmCTestLog(this->CTest, HANDLER_OUTPUT, " Gathering version information (one . per revision):\n" - " " - << std::flush); + " "); // We are interested in every revision included in the update. this->Revisions.clear(); @@ -414,7 +411,7 @@ bool cmCTestBZR::LoadRevisions() OutputLogger err(this->Log, "log-err> "); this->RunChild(bzr_log, &out, &err); } - cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl); + cmCTestLog(this->CTest, HANDLER_OUTPUT, '\n'); return true; } diff --git a/Source/CTest/cmCTestBuildCommand.cxx b/Source/CTest/cmCTestBuildCommand.cxx index 3c4fa75384..353bfed8e9 100644 --- a/Source/CTest/cmCTestBuildCommand.cxx +++ b/Source/CTest/cmCTestBuildCommand.cxx @@ -2,7 +2,6 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmCTestBuildCommand.h" -#include #include #include @@ -109,9 +108,8 @@ std::unique_ptr cmCTestBuildCommand::InitializeHandler( if (presetCheck == PresetCheckResult::Found) { effectivePreset = *v; } else { - cmCTestLog(this->CTest, WARNING, - "No build preset named \"" - << *v << "\" found, ignoring CTEST_PRESET." << std::endl); + cmCTestLog(this->CTest, WARNING, "No build preset named \"", *v, + "\" found, ignoring CTEST_PRESET.\n"); } } } @@ -125,10 +123,9 @@ std::unique_ptr cmCTestBuildCommand::InitializeHandler( args.Quiet); } else if (!effectivePreset.empty()) { if (cmNonempty(ctestBuildCommand)) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Ignoring CTEST_BUILD_COMMAND because preset \"" - << effectivePreset << "\" is in use.\n", - args.Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, args.Quiet, + "Ignoring CTEST_BUILD_COMMAND because preset \"", + effectivePreset, "\" is in use.\n"); } cmCMakePresetsGraph presetsGraph; if (!presetsGraph.ReadProjectPresets(sourceDirectory, presetsFile)) { @@ -177,8 +174,8 @@ std::unique_ptr cmCTestBuildCommand::InitializeHandler( cmStrCat(std::move(buildCommand), " -- ", cmakeBuildAdditionalFlags); } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "SetMakeCommand:" << buildCommand << "\n", args.Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, args.Quiet, + "SetMakeCommand:", buildCommand, '\n'); this->CTest->SetCTestConfiguration("MakeCommand", buildCommand, args.Quiet); } else { @@ -206,9 +203,8 @@ std::unique_ptr cmCTestBuildCommand::InitializeHandler( std::string buildCommand = globalGenerator->GenerateCMakeBuildCommand( cmakeBuildTarget, cmakeBuildConfiguration, args.ParallelLevel, cmakeBuildAdditionalFlags, false); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "SetMakeCommand:" << buildCommand << "\n", - args.Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, args.Quiet, + "SetMakeCommand:", buildCommand, '\n'); this->CTest->SetCTestConfiguration("MakeCommand", buildCommand, args.Quiet); } else { diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index 71e5bda57b..9e27fdc498 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -2,6 +2,7 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmCTestBuildHandler.h" +#include #include #include #include @@ -227,8 +228,8 @@ void cmCTestBuildHandler::PopulateCustomVectors(cmMakefile* mf) std::string cmCTestBuildHandler::GetMakeCommand() { std::string makeCommand = this->CTest->GetCTestConfiguration("MakeCommand"); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "MakeCommand:" << makeCommand << "\n", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "MakeCommand:", makeCommand, '\n'); std::string configType = this->CTest->GetConfigType(); if (configType.empty()) { @@ -249,8 +250,8 @@ std::string cmCTestBuildHandler::GetMakeCommand() // functions and commented... int cmCTestBuildHandler::ProcessHandler() { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Build project" << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + "Build project\n"); // do we have time for this if (this->CTest->GetRemainingTimeAllowed() < std::chrono::minutes(2)) { @@ -268,10 +269,8 @@ int cmCTestBuildHandler::ProcessHandler() this->ErrorWarningFileLineRegex.push_back(std::move(r)); } else { cmCTestLog( - this->CTest, ERROR_MESSAGE, - "Problem Compiling regular expression: " - << cmCTestWarningErrorFileLine[entry].RegularExpressionString - << std::endl); + this->CTest, ERROR_MESSAGE, "Problem Compiling regular expression: ", + cmCTestWarningErrorFileLine[entry].RegularExpressionString, '\n'); } } @@ -279,17 +278,16 @@ int cmCTestBuildHandler::ProcessHandler() std::string makeCommand = this->GetMakeCommand(); if (makeCommand.empty()) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot find MakeCommand key in the DartConfiguration.tcl" - << std::endl); + "Cannot find MakeCommand key in the DartConfiguration.tcl\n"); return -1; } std::string const& buildDirectory = this->CTest->GetCTestConfiguration("BuildDirectory"); if (buildDirectory.empty()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot find BuildDirectory key in the DartConfiguration.tcl" - << std::endl); + cmCTestLog( + this->CTest, ERROR_MESSAGE, + "Cannot find BuildDirectory key in the DartConfiguration.tcl\n"); return -1; } @@ -301,8 +299,7 @@ int cmCTestBuildHandler::ProcessHandler() cmGeneratedFileStream ofs; auto elapsed_time_start = std::chrono::steady_clock::now(); if (!this->StartLogFile("Build", ofs)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot create build log file" << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build log file\n"); } this->LogFileName = ofs.GetTempName(); @@ -329,12 +326,14 @@ int cmCTestBuildHandler::ProcessHandler() #define cmCTestBuildHandlerPopulateRegexVector(strings, regexes) \ do { \ regexes.clear(); \ - cmCTestOptionalLog(this->CTest, DEBUG, \ - this << "Add " #regexes << std::endl, this->Quiet); \ + char cmCTestBuildHandlerAddr[sizeof(void*) * 2 + 4]; \ + std::snprintf(cmCTestBuildHandlerAddr, sizeof(cmCTestBuildHandlerAddr), \ + "%p", static_cast(this)); \ + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, \ + cmCTestBuildHandlerAddr, "Add " #regexes "\n"); \ for (std::string const& s : (strings)) { \ - cmCTestOptionalLog(this->CTest, DEBUG, \ - "Add " #strings ": " << s << std::endl, \ - this->Quiet); \ + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, \ + "Add " #strings ": ", s, '\n'); \ (regexes).emplace_back(s); \ } \ } while (false) @@ -384,9 +383,8 @@ int cmCTestBuildHandler::ProcessHandler() res = this->RunMakeCommand(makeCommand, &retVal, buildDirectory.c_str(), 0, ofs); } else { - cmCTestOptionalLog(this->CTest, DEBUG, - "Build with command: " << makeCommand << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, + "Build with command: ", makeCommand, '\n'); } // Remember end build time and calculate elapsed time @@ -421,8 +419,7 @@ int cmCTestBuildHandler::ProcessHandler() // Generate XML output cmGeneratedFileStream xofs; if (!this->StartResultingXML(cmCTest::PartBuild, "Build", xofs)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot create build XML file" << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build XML file\n"); return -1; } cmXMLWriter xml(xofs); @@ -440,20 +437,16 @@ int cmCTestBuildHandler::ProcessHandler() this->GenerateXMLFooter(xml, elapsed_build_time); if (!res || retVal || this->TotalErrors > 0) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Error(s) when building project" << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Error(s) when building project\n"); } // Display message about number of errors and warnings - cmCTestLog(this->CTest, HANDLER_OUTPUT, - " " << this->TotalErrors - << (this->TotalErrors >= this->MaxErrors ? " or more" : "") - << " Compiler errors" << std::endl); - cmCTestLog( - this->CTest, HANDLER_OUTPUT, - " " << this->TotalWarnings - << (this->TotalWarnings >= this->MaxWarnings ? " or more" : "") - << " Compiler warnings" << std::endl); + cmCTestLog(this->CTest, HANDLER_OUTPUT, " ", this->TotalErrors, + (this->TotalErrors >= this->MaxErrors ? " or more" : ""), + " Compiler errors\n"); + cmCTestLog(this->CTest, HANDLER_OUTPUT, " ", this->TotalWarnings, + (this->TotalWarnings >= this->MaxWarnings ? " or more" : ""), + " Compiler warnings\n"); return retVal; } @@ -821,14 +814,13 @@ bool cmCTestBuildHandler::RunMakeCommand(std::string const& command, return false; } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Run command:", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Run command:"); for (auto const& arg : args) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " \"" << arg << "\"", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, " \"", + arg, "\""); } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, '\n'); // Optionally use make rule launchers to record errors and warnings. LaunchHelper launchHelper(this); @@ -850,14 +842,11 @@ bool cmCTestBuildHandler::RunMakeCommand(std::string const& command, cmProcessOutput processOutput(encoding); cmCTestOptionalLog( - this->CTest, HANDLER_PROGRESS_OUTPUT, - " Each symbol represents " - << tick_len << " bytes of output." << std::endl - << (this->UseCTestLaunch - ? "" - : " '!' represents an error and '*' a warning.\n") - << " " << std::flush, - this->Quiet); + this->CTest, HANDLER_PROGRESS_OUTPUT, this->Quiet, + " Each symbol represents ", tick_len, " bytes of output.\n", + (this->UseCTestLaunch ? "" + : " '!' represents an error and '*' a warning.\n"), + " "); // Initialize building structures this->BuildProcessingQueue.clear(); @@ -928,11 +917,9 @@ bool cmCTestBuildHandler::RunMakeCommand(std::string const& command, &this->BuildProcessingQueue); this->ProcessBuffer(nullptr, 0, tick, tick_len, ofs, &this->BuildProcessingErrorQueue); - cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT, - " Size of output: " - << ((this->BuildOutputLogSize + 512) / 1024) << "K" - << std::endl, - this->Quiet); + cmCTestOptionalLog( + this->CTest, HANDLER_PROGRESS_OUTPUT, this->Quiet, + " Size of output: ", ((this->BuildOutputLogSize + 512) / 1024), "K\n"); if (chain.Finished()) { auto const& status = chain.GetStatus(0); @@ -941,10 +928,8 @@ bool cmCTestBuildHandler::RunMakeCommand(std::string const& command, case cmUVProcessChain::ExceptionCode::None: if (retVal) { *retVal = static_cast(status.ExitStatus); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Command exited with the value: " << *retVal - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Command exited with the value: ", *retVal, '\n'); // if a non zero return value if (*retVal) { // If there was an error running command, report that on the @@ -1003,21 +988,20 @@ bool cmCTestBuildHandler::RunMakeCommand(std::string const& command, this->ErrorsAndWarnings.push_back(std::move(errorwarning)); this->TotalErrors++; cmCTestLog(this->CTest, ERROR_MESSAGE, - "There was an error: " << exception.second << std::endl); + "There was an error: ", exception.second, '\n'); } break; default: if (retVal) { *retVal = status.TermSignal; - cmCTestOptionalLog( - this->CTest, WARNING, - "There was an exception: " << *retVal << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, WARNING, this->Quiet, + "There was an exception: ", *retVal, '\n'); } break; } } else { chain.Terminate(); - cmCTestOptionalLog(this->CTest, WARNING, - "There was a timeout" << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, WARNING, this->Quiet, + "There was a timeout\n"); } return true; @@ -1139,16 +1123,13 @@ void cmCTestBuildHandler::ProcessBuffer(char const* data, size_t length, int tickDisplayed = false; while (this->BuildOutputLogSize > (tick * tick_len)) { tick++; - cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT, - this->LastTickChar, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT, this->Quiet, + this->LastTickChar); tickDisplayed = true; if (tick % tick_line_len == 0 && tick > 0) { - cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT, - " Size: " - << ((this->BuildOutputLogSize + 512) / 1024) << "K" - << std::endl - << " ", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT, this->Quiet, + " Size: ", ((this->BuildOutputLogSize + 512) / 1024), + "K\n "); } } if (tickDisplayed) { @@ -1175,8 +1156,7 @@ int cmCTestBuildHandler::ProcessSingleLine(char const* data) std::string line; this->ColorRemover->Replace(input, line); - cmCTestOptionalLog(this->CTest, DEBUG, "Line: [" << line << "]" << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, "Line: [", line, "]\n"); int warningLine = 0; int errorLine = 0; @@ -1189,11 +1169,9 @@ int cmCTestBuildHandler::ProcessSingleLine(char const* data) for (cmsys::RegularExpression& rx : this->ErrorMatchRegex) { if (rx.find(line.c_str())) { errorLine = 1; - cmCTestOptionalLog(this->CTest, DEBUG, - " Error Line: " << line << " (matches: " - << this->CustomErrorMatches[wrxCnt] - << ")" << std::endl, - this->Quiet); + cmCTestOptionalLog( + this->CTest, DEBUG, this->Quiet, " Error Line: ", line, + " (matches: ", this->CustomErrorMatches[wrxCnt], ")\n"); break; } wrxCnt++; @@ -1203,12 +1181,9 @@ int cmCTestBuildHandler::ProcessSingleLine(char const* data) for (cmsys::RegularExpression& rx : this->ErrorExceptionRegex) { if (rx.find(line.c_str())) { errorLine = 0; - cmCTestOptionalLog(this->CTest, DEBUG, - " Not an error Line: " - << line << " (matches: " - << this->CustomErrorExceptions[wrxCnt] << ")" - << std::endl, - this->Quiet); + cmCTestOptionalLog( + this->CTest, DEBUG, this->Quiet, " Not an error Line: ", line, + " (matches: ", this->CustomErrorExceptions[wrxCnt], ")\n"); break; } wrxCnt++; @@ -1220,12 +1195,9 @@ int cmCTestBuildHandler::ProcessSingleLine(char const* data) for (cmsys::RegularExpression& rx : this->WarningMatchRegex) { if (rx.find(line.c_str())) { warningLine = 1; - cmCTestOptionalLog(this->CTest, DEBUG, - " Warning Line: " - << line << " (matches: " - << this->CustomWarningMatches[wrxCnt] << ")" - << std::endl, - this->Quiet); + cmCTestOptionalLog( + this->CTest, DEBUG, this->Quiet, " Warning Line: ", line, + " (matches: ", this->CustomWarningMatches[wrxCnt], ")\n"); break; } wrxCnt++; @@ -1236,12 +1208,9 @@ int cmCTestBuildHandler::ProcessSingleLine(char const* data) for (cmsys::RegularExpression& rx : this->WarningExceptionRegex) { if (rx.find(line.c_str())) { warningLine = 0; - cmCTestOptionalLog(this->CTest, DEBUG, - " Not a warning Line: " - << line << " (matches: " - << this->CustomWarningExceptions[wrxCnt] << ")" - << std::endl, - this->Quiet); + cmCTestOptionalLog( + this->CTest, DEBUG, this->Quiet, " Not a warning Line: ", line, + " (matches: ", this->CustomWarningExceptions[wrxCnt], ")\n"); break; } wrxCnt++; diff --git a/Source/CTest/cmCTestCVS.cxx b/Source/CTest/cmCTestCVS.cxx index d3a2b2399f..7525d68a59 100644 --- a/Source/CTest/cmCTestCVS.cxx +++ b/Source/CTest/cmCTestCVS.cxx @@ -217,7 +217,7 @@ std::string cmCTestCVS::ComputeBranchFlag(std::string const& dir) void cmCTestCVS::LoadRevisions(std::string const& file, char const* branchFlag, std::vector& revisions) { - cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush); + cmCTestLog(this->CTest, HANDLER_OUTPUT, '.'); // Run "cvs log" to get revisions of this file on this branch. std::string cvs = this->CommandLineTool; @@ -264,14 +264,13 @@ bool cmCTestCVS::WriteXMLUpdates(cmXMLWriter& xml) { cmCTestLog(this->CTest, HANDLER_OUTPUT, " Gathering version information (one . per updated file):\n" - " " - << std::flush); + " "); for (auto const& d : this->Dirs) { this->WriteXMLDirectory(xml, d.first, d.second); } - cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl); + cmCTestLog(this->CTest, HANDLER_OUTPUT, '\n'); return true; } diff --git a/Source/CTest/cmCTestConfigureCommand.cxx b/Source/CTest/cmCTestConfigureCommand.cxx index cdfe3a599b..59cf7ce8df 100644 --- a/Source/CTest/cmCTestConfigureCommand.cxx +++ b/Source/CTest/cmCTestConfigureCommand.cxx @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include #include @@ -238,10 +238,9 @@ bool cmCTestConfigureCommand::ExecuteConfigure(ConfigureArguments const& args, if (presetName.empty()) { configureCommand = mf.GetDefinition("CTEST_CONFIGURE_COMMAND"); } else if (cmNonempty(mf.GetDefinition("CTEST_CONFIGURE_COMMAND"))) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Ignoring CTEST_CONFIGURE_COMMAND because preset \"" - << presetName << "\" is in use.\n", - args.Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, args.Quiet, + "Ignoring CTEST_CONFIGURE_COMMAND because preset \"", + presetName, "\" is in use.\n"); } if (configureCommand.empty() && !ConstructConfigureCommand(status, mf, sourceDirectory, buildDirectory, @@ -250,13 +249,12 @@ bool cmCTestConfigureCommand::ExecuteConfigure(ConfigureArguments const& args, return false; } - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Configure project\n", - args.Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, args.Quiet, + "Configure project\n"); if (this->CTest->GetShowOnly()) { - cmCTestOptionalLog(this->CTest, DEBUG, - "Configure with command: " << configureCommand << '\n', - args.Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, args.Quiet, + "Configure with command: ", configureCommand, '\n'); if (!args.ReturnValue.empty()) { mf.AddDefinition(args.ReturnValue, "0"); } @@ -268,9 +266,8 @@ bool cmCTestConfigureCommand::ExecuteConfigure(ConfigureArguments const& args, return false; } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Configure with command: " << configureCommand << '\n', - args.Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, args.Quiet, + "Configure with command: ", configureCommand, '\n'); int const submitIndex = args.SubmitIndex.empty() ? 0 : std::atoi(args.SubmitIndex.c_str()); @@ -292,7 +289,7 @@ bool cmCTestConfigureCommand::ExecuteConfigure(ConfigureArguments const& args, auto const elapsedMinutes = std::chrono::duration_cast(endTime - startTime); - cmCTestOptionalLog(this->CTest, DEBUG, "End\n", args.Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, args.Quiet, "End\n"); if (!res || retVal) { cmCTestLog(this->CTest, ERROR_MESSAGE, @@ -315,8 +312,7 @@ bool cmCTestConfigureCommand::ExecuteConfigure(ConfigureArguments const& args, cmGeneratedFileStream xmlFile; if (!this->CTest->StartResultingXML(cmCTest::PartConfigure, "Configure", submitIndex, xmlFile)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot open configure file" << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open configure file\n"); return false; } diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index c0931dcadf..5bf85d85ad 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -61,13 +60,12 @@ bool cmCTestCoverageHandler::StartCoverageLogFile( char covLogFilename[1024]; snprintf(covLogFilename, sizeof(covLogFilename), "CoverageLog-%d", logFileCount); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Open file: " << covLogFilename << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Open file: ", covLogFilename, '\n'); if (!this->StartResultingXML(cmCTest::PartCoverage, covLogFilename, covLogFile)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot open log file: " << covLogFilename << std::endl); + "Cannot open log file: ", covLogFilename, '\n'); return false; } return true; @@ -79,9 +77,8 @@ void cmCTestCoverageHandler::EndCoverageLogFile(cmGeneratedFileStream& ostr, char covLogFilename[1024]; snprintf(covLogFilename, sizeof(covLogFilename), "CoverageLog-%d.xml", logFileCount); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Close file: " << covLogFilename << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Close file: ", covLogFilename, '\n'); ostr.Close(); } @@ -111,10 +108,9 @@ bool cmCTestCoverageHandler::ShouldIDoCoverage(std::string const& file, for (cmsys::RegularExpression& rx : this->CustomCoverageExcludeRegex) { if (rx.find(file)) { - cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - " File " << file << " is excluded in CTestCustom.ctest" << std::endl; - , this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " File ", file, + " is excluded in CTestCustom.ctest\n"); return false; } } @@ -143,10 +139,8 @@ bool cmCTestCoverageHandler::ShouldIDoCoverage(std::string const& file, std::string ndc = cmSystemTools::FileExistsInParentDirectories( ".NoDartCoverage", fFile, checkDir); if (!ndc.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Found: " << ndc << " so skip coverage of " << file - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Found: ", ndc, " so skip coverage of ", file, '\n'); return false; } @@ -175,10 +169,8 @@ bool cmCTestCoverageHandler::ShouldIDoCoverage(std::string const& file, ndc = cmSystemTools::FileExistsInParentDirectories(".NoDartCoverage", fFile, checkDir); if (!ndc.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Found: " << ndc << " so skip coverage of: " << file - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Found: ", ndc, " so skip coverage of: ", file, '\n'); return false; } // Ok, nothing in source tree, nothing in binary tree @@ -205,8 +197,7 @@ int cmCTestCoverageHandler::ProcessHandler() if (binaryDir.empty()) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Binary directory is not set. " - "No coverage checking will be performed." - << std::endl); + "No coverage checking will be performed.\n"); return 0; } this->LoadLabels(); @@ -215,7 +206,7 @@ int cmCTestCoverageHandler::ProcessHandler() auto elapsed_time_start = std::chrono::steady_clock::now(); if (!this->StartLogFile("Coverage", ofs)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot create LastCoverage.log file" << std::endl); + "Cannot create LastCoverage.log file\n"); } ofs << "Performing coverage: " @@ -225,8 +216,8 @@ int cmCTestCoverageHandler::ProcessHandler() cmSystemTools::ConvertToUnixSlashes(sourceDir); cmSystemTools::ConvertToUnixSlashes(binaryDir); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - "Performing coverage" << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + "Performing coverage\n"); cmCTestCoverageHandlerContainer cont; cont.Error = error; @@ -303,10 +294,8 @@ int cmCTestCoverageHandler::ProcessHandler() if (file_count == 0 && this->ExtraCoverageGlobs.empty()) { cmCTestOptionalLog( - this->CTest, WARNING, - " Cannot find any coverage files. Ignoring Coverage request." - << std::endl, - this->Quiet); + this->CTest, WARNING, this->Quiet, + " Cannot find any coverage files. Ignoring Coverage request.\n"); return error; } cmGeneratedFileStream covSumFile; @@ -317,7 +306,7 @@ int cmCTestCoverageHandler::ProcessHandler() if (!this->StartResultingXML(cmCTest::PartCoverage, "Coverage", covSumFile)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot open coverage summary file." << std::endl); + "Cannot open coverage summary file.\n"); return -1; } covSumFile.setf(std::ios::fixed, std::ios::floatfield); @@ -339,47 +328,41 @@ int cmCTestCoverageHandler::ProcessHandler() long total_untested = 0; // std::string fullSourceDir = sourceDir + "/"; // std::string fullBinaryDir = binaryDir + "/"; - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, '\n'); cmCTestOptionalLog( - this->CTest, HANDLER_OUTPUT, - " Accumulating results (each . represents one file):" << std::endl, - this->Quiet); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet); + this->CTest, HANDLER_OUTPUT, this->Quiet, + " Accumulating results (each . represents one file):\n"); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, " "); std::vector errorsWhileAccumulating; file_count = 0; for (auto const& file : cont.TotalCoverage) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "." << std::flush, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, '.'); file_count++; if (file_count % 50 == 0) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " processed: " << file_count << " out of " - << cont.TotalCoverage.size() - << std::endl, - this->Quiet); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " processed: ", file_count, " out of ", + cont.TotalCoverage.size(), '\n'); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, " "); } std::string const fullFileName = file.first; bool shouldIDoCoverage = this->ShouldIDoCoverage(fullFileName, sourceDir, binaryDir); if (!shouldIDoCoverage) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - ".NoDartCoverage found, so skip coverage check for: " - << fullFileName << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + ".NoDartCoverage found, so skip coverage check for: ", + fullFileName, '\n'); continue; } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Process file: " << fullFileName << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Process file: ", fullFileName, '\n'); if (!cmSystemTools::FileExists(fullFileName)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot find file: " << fullFileName << std::endl); + "Cannot find file: ", fullFileName, '\n'); continue; } @@ -423,10 +406,9 @@ int cmCTestCoverageHandler::ProcessHandler() int branchesuntested = 0; cmCTestCoverageHandlerContainer::SingleFileCoverageVector::size_type cc; std::string line; - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Actually performing coverage for: " << fullFileName - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Actually performing coverage for: ", fullFileName, + '\n'); for (cc = 0; cc < fcov.size(); cc++) { if (!cmSystemTools::GetLineFromStream(ifs, line) && cc != fcov.size() - 1) { @@ -511,9 +493,8 @@ int cmCTestCoverageHandler::ProcessHandler() } int untested = 0; std::string line; - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Actually performing coverage for: " << u << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Actually performing coverage for: ", u, '\n'); while (cmSystemTools::GetLineFromStream(ifs, line)) { covLogXML.StartElement("Line"); covLogXML.Attribute("Number", untested); @@ -542,11 +523,11 @@ int cmCTestCoverageHandler::ProcessHandler() this->EndCoverageLogFile(covLogFile, logFileCount); if (!errorsWhileAccumulating.empty()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, '\n'); cmCTestLog(this->CTest, ERROR_MESSAGE, - "Error(s) while accumulating results:" << std::endl); + "Error(s) while accumulating results:\n"); for (std::string const& er : errorsWhileAccumulating) { - cmCTestLog(this->CTest, ERROR_MESSAGE, " " << er << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, " ", er, '\n'); } } @@ -572,20 +553,19 @@ int cmCTestCoverageHandler::ProcessHandler() covSumXML.EndElement(); // Coverage this->CTest->EndXML(covSumXML); + char percentBuf[8]; + std::snprintf(percentBuf, sizeof(percentBuf), "%.2f", + static_cast(percent_coverage)); cmCTestLog(this->CTest, HANDLER_OUTPUT, - "" << std::endl - << "\tCovered LOC: " << total_tested << std::endl - << "\tNot covered LOC: " << total_untested << std::endl - << "\tTotal LOC: " << total_lines << std::endl - << "\tPercentage Coverage: " - << std::setiosflags(std::ios::fixed) << std::setprecision(2) - << (percent_coverage) << "%" << std::endl); + "\n\tCovered LOC: ", total_tested, + "\n\tNot covered LOC: ", total_untested, + "\n\tTotal LOC: ", total_lines, + "\n\tPercentage Coverage: ", percentBuf, "%\n"); ofs << "\tCovered LOC: " << total_tested << std::endl << "\tNot covered LOC: " << total_untested << std::endl << "\tTotal LOC: " << total_lines << std::endl - << "\tPercentage Coverage: " << std::setiosflags(std::ios::fixed) - << std::setprecision(2) << (percent_coverage) << "%" << std::endl; + << "\tPercentage Coverage: " << percentBuf << "%" << std::endl; if (error) { return -1; @@ -595,22 +575,19 @@ int cmCTestCoverageHandler::ProcessHandler() void cmCTestCoverageHandler::PopulateCustomVectors(cmMakefile* mf) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Add coverage exclude regular expressions." << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Add coverage exclude regular expressions.\n"); this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_COVERAGE_EXCLUDE", this->CustomCoverageExclude); this->CTest->PopulateCustomVector(mf, "CTEST_EXTRA_COVERAGE_GLOB", this->ExtraCoverageGlobs); for (std::string const& cce : this->CustomCoverageExclude) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Add coverage exclude: " << cce << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Add coverage exclude: ", cce, '\n'); } for (std::string const& ecg : this->ExtraCoverageGlobs) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Add coverage glob: " << ecg << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Add coverage glob: ", ecg, '\n'); } } @@ -665,16 +642,13 @@ int cmCTestCoverageHandler::HandleCoberturaCoverage( if (cmSystemTools::FileExists(coverageXMLFile)) { // If file exists, parse it - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Parsing Cobertura XML file: " << coverageXMLFile - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Parsing Cobertura XML file: ", coverageXMLFile, '\n'); cov.ReadCoverageXML(coverageXMLFile.c_str()); } else { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Cannot find Cobertura XML file: " << coverageXMLFile - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Cannot find Cobertura XML file: ", coverageXMLFile, + '\n'); } return static_cast(cont->TotalCoverage.size()); } @@ -687,28 +661,23 @@ int cmCTestCoverageHandler::HandleMumpsCoverage( std::string coverageFile = this->CTest->GetBinaryDir() + "/gtm_coverage.mcov"; if (cmSystemTools::FileExists(coverageFile)) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Parsing Cache Coverage: " << coverageFile << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Parsing Cache Coverage: ", coverageFile, '\n'); cov.ReadCoverageFile(coverageFile.c_str()); return static_cast(cont->TotalCoverage.size()); } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Cannot find GTM coverage file: " << coverageFile - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Cannot find GTM coverage file: ", coverageFile, '\n'); cmParseCacheCoverage ccov(*cont, this->CTest); coverageFile = this->CTest->GetBinaryDir() + "/cache_coverage.cmcov"; if (cmSystemTools::FileExists(coverageFile)) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Parsing Cache Coverage: " << coverageFile << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Parsing Cache Coverage: ", coverageFile, '\n'); ccov.ReadCoverageFile(coverageFile.c_str()); } else { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Cannot find Cache coverage file: " << coverageFile - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Cannot find Cache coverage file: ", coverageFile, + '\n'); } return static_cast(cont->TotalCoverage.size()); } @@ -765,15 +734,13 @@ int cmCTestCoverageHandler::HandleJacocoCoverage( cm::append(files, g2.GetFiles()); if (!files.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Found Jacoco Files, Performing Coverage" << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Found Jacoco Files, Performing Coverage\n"); cov.LoadCoverageData(files); } else { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Cannot find Jacoco coverage files: " << coverageFile - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Cannot find Jacoco coverage files: ", coverageFile, + '\n'); } return static_cast(cont->TotalCoverage.size()); } @@ -792,16 +759,13 @@ int cmCTestCoverageHandler::HandleDelphiCoverage( g.FindFiles(coverageFile); files = g.GetFiles(); if (!files.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Found Delphi HTML Files, Performing Coverage" - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Found Delphi HTML Files, Performing Coverage\n"); cov.LoadCoverageData(files); } else { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Cannot find Delphi coverage files: " << coverageFile - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Cannot find Delphi coverage files: ", coverageFile, + '\n'); } return static_cast(cont->TotalCoverage.size()); } @@ -854,16 +818,13 @@ int cmCTestCoverageHandler::HandleBlanketJSCoverage( } // Take all files with the node-jscoverage string and parse those if (!blanketFiles.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Found BlanketJS output JSON, Performing Coverage" - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Found BlanketJS output JSON, Performing Coverage\n"); cov.LoadCoverageData(files); } else { - cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - " Cannot find BlanketJS coverage files: " << coverageFile << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Cannot find BlanketJS coverage files: ", coverageFile, + '\n'); } return static_cast(cont->TotalCoverage.size()); } @@ -873,8 +834,8 @@ int cmCTestCoverageHandler::HandleGCovCoverage( std::string gcovCommand = this->CTest->GetCTestConfiguration("CoverageCommand"); if (gcovCommand.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Could not find gcov." << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Could not find gcov.\n"); return 0; } std::string gcovExtraFlags = @@ -913,9 +874,8 @@ int cmCTestCoverageHandler::HandleGCovCoverage( this->FindGCovFiles(files); if (files.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Cannot find any GCov coverage files." << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Cannot find any GCov coverage files.\n"); // No coverage files is a valid thing, so the exit code is 0 return 0; } @@ -924,7 +884,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( std::string tempDir = testingDir + "/CoverageInfo"; if (!cmSystemTools::MakeDirectory(tempDir)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unable to make directory: " << tempDir << std::endl); + "Unable to make directory: ", tempDir, '\n'); cont->Error++; return 0; } @@ -935,11 +895,9 @@ int cmCTestCoverageHandler::HandleGCovCoverage( std::set missingFiles; std::string actualSourceFile; - cmCTestOptionalLog( - this->CTest, HANDLER_OUTPUT, - " Processing coverage (each . represents one file):" << std::endl, - this->Quiet); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " Processing coverage (each . represents one file):\n"); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, " "); int file_count = 0; // make sure output from gcov is in English! @@ -956,8 +914,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( // give us text output we can analyze to summarize coverage. // for (std::string const& f : files) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "." << std::flush, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, '.'); // Call gcov to get coverage data for this *.gcda file: // @@ -967,8 +924,8 @@ int cmCTestCoverageHandler::HandleGCovCoverage( covargs.push_back(f); std::string const command = joinCommandLine(covargs); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - command << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + command, '\n'); std::string output; std::string errors; @@ -983,27 +940,25 @@ int cmCTestCoverageHandler::HandleGCovCoverage( *cont->OFS << " Errors: " << errors << std::endl; if (!res) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem running coverage on file: " << f << std::endl); + "Problem running coverage on file: ", f, '\n'); cmCTestLog(this->CTest, ERROR_MESSAGE, - "Command produced error: " << errors << std::endl); + "Command produced error: ", errors, '\n'); cont->Error++; continue; } if (retVal != 0) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Coverage command returned: " - << retVal << " while processing: " << f << std::endl); + "Coverage command returned: ", retVal, + " while processing: ", f, '\n'); cmCTestLog(this->CTest, ERROR_MESSAGE, - "Command produced error: " << cont->Error << std::endl); + "Command produced error: ", cont->Error, '\n'); } cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - "--------------------------------------------------------------" - << std::endl - << output << std::endl - << "--------------------------------------------------------------" - << std::endl, - this->Quiet); + this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "--------------------------------------------------------------\n", + output, + "\n" + "--------------------------------------------------------------\n"); std::vector lines; cmsys::SystemTools::Split(output, lines); @@ -1012,8 +967,8 @@ int cmCTestCoverageHandler::HandleGCovCoverage( std::string sourceFile; std::string gcovFile; - cmCTestOptionalLog(this->CTest, DEBUG, - "Line: [" << line << "]" << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, "Line: [", line, + "]\n"); if (line.empty()) { // Ignore empty line; probably style 2 @@ -1023,7 +978,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( } if (gcovStyle != 1) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unknown gcov output style e1" << std::endl); + "Unknown gcov output style e1\n"); cont->Error++; break; } @@ -1036,7 +991,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( } if (gcovStyle != 1) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unknown gcov output style e2" << std::endl); + "Unknown gcov output style e2\n"); cont->Error++; break; } @@ -1048,7 +1003,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( } if (gcovStyle != 2) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unknown gcov output style e3" << std::endl); + "Unknown gcov output style e3\n"); cont->Error++; break; } @@ -1061,7 +1016,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( } if (gcovStyle != 2) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unknown gcov output style e4" << std::endl); + "Unknown gcov output style e4\n"); cont->Error++; break; } @@ -1071,7 +1026,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( } if (gcovStyle != 2) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unknown gcov output style e5" << std::endl); + "Unknown gcov output style e5\n"); cont->Error++; break; } @@ -1083,54 +1038,49 @@ int cmCTestCoverageHandler::HandleGCovCoverage( } if (gcovStyle != 2) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unknown gcov output style e6" << std::endl); + "Unknown gcov output style e6\n"); cont->Error++; break; } - cmCTestOptionalLog(this->CTest, WARNING, - "Warning: " << st2re4.match(1) - << " had unexpected EOF" << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, WARNING, this->Quiet, + "Warning: ", st2re4.match(1), + " had unexpected EOF\n"); } else if (st2re5.find(line)) { if (gcovStyle == 0) { gcovStyle = 2; } if (gcovStyle != 2) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unknown gcov output style e7" << std::endl); + "Unknown gcov output style e7\n"); cont->Error++; break; } - cmCTestOptionalLog(this->CTest, WARNING, - "Warning: Cannot open file: " << st2re5.match(1) - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, WARNING, this->Quiet, + "Warning: Cannot open file: ", st2re5.match(1), + '\n'); } else if (st2re6.find(line)) { if (gcovStyle == 0) { gcovStyle = 2; } if (gcovStyle != 2) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unknown gcov output style e8" << std::endl); + "Unknown gcov output style e8\n"); cont->Error++; break; } - cmCTestOptionalLog(this->CTest, WARNING, - "Warning: File: " << st2re6.match(1) - << " is newer than " - << st2re6.match(2) << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, WARNING, this->Quiet, + "Warning: File: ", st2re6.match(1), + " is newer than ", st2re6.match(2), '\n'); } else { // gcov 4.7 can have output lines saying "No executable lines" and // "Removing 'filename.gcov'"... Don't log those as "errors." if (line != "No executable lines" && !cmHasLiteralPrefix(line, "Removing ")) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unknown gcov output line: [" << line << "]" - << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output line: [", + line, "]\n"); cont->Error++; // abort(); } @@ -1144,14 +1094,13 @@ int cmCTestCoverageHandler::HandleGCovCoverage( cmCTestCoverageHandlerContainer::SingleFileCoverageVector& vec = cont->TotalCoverage[actualSourceFile]; - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " in gcovFile: " << gcovFile << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " in gcovFile: ", gcovFile, '\n'); cmsys::ifstream ifile(gcovFile.c_str()); if (!ifile) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot open file: " << gcovFile << std::endl); + "Cannot open file: ", gcovFile, '\n'); } else { std::string nl; while (cmSystemTools::GetLineFromStream(ifile, nl)) { @@ -1210,16 +1159,14 @@ int cmCTestCoverageHandler::HandleGCovCoverage( // Is it in the source dir or the binary dir? // if (IsFileInDir(sourceFile, cont->SourceDir)) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " produced s: " << sourceFile << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " produced s: ", sourceFile, '\n'); *cont->OFS << " produced in source dir: " << sourceFile << std::endl; actualSourceFile = cmSystemTools::CollapseFullPath(sourceFile); } else if (IsFileInDir(sourceFile, cont->BinaryDir)) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " produced b: " << sourceFile << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " produced b: ", sourceFile, '\n'); *cont->OFS << " produced in binary dir: " << sourceFile << std::endl; actualSourceFile = cmSystemTools::CollapseFullPath(sourceFile); @@ -1228,20 +1175,16 @@ int cmCTestCoverageHandler::HandleGCovCoverage( if (actualSourceFile.empty()) { if (missingFiles.find(sourceFile) == missingFiles.end()) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Something went wrong" << std::endl, - this->Quiet); + this->Quiet, "Something went wrong\n"); cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Cannot find file: [" << sourceFile << "]" - << std::endl, - this->Quiet); + this->Quiet, "Cannot find file: [", sourceFile, + "]\n"); cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " in source dir: [" << cont->SourceDir << "]" - << std::endl, - this->Quiet); + this->Quiet, " in source dir: [", + cont->SourceDir, "]\n"); cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " or binary dir: [" << cont->BinaryDir.size() - << "]" << std::endl, - this->Quiet); + this->Quiet, " or binary dir: [", + cont->BinaryDir.size(), "]\n"); *cont->OFS << " Something went wrong. Cannot find file: " << sourceFile << " in source dir: " << cont->SourceDir << " or binary dir: " << cont->BinaryDir << std::endl; @@ -1255,11 +1198,10 @@ int cmCTestCoverageHandler::HandleGCovCoverage( file_count++; if (file_count % 50 == 0) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " processed: " << file_count << " out of " - << files.size() << std::endl, - this->Quiet); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " processed: ", file_count, " out of ", files.size(), + '\n'); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, " "); } } @@ -1269,9 +1211,8 @@ int cmCTestCoverageHandler::HandleGCovCoverage( int cmCTestCoverageHandler::HandleClangSourceCodeCoverage( cmCTestCoverageHandlerContainer* cont) { - cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - "Looking for Clang Source Code Coverage data: " << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Looking for Clang Source Code Coverage data: \n"); // find all *.profraw files cmsys::Glob gl; gl.RecurseOn(); @@ -1281,16 +1222,14 @@ int cmCTestCoverageHandler::HandleClangSourceCodeCoverage( dir = this->CTest->GetBinaryDir(); std::string daGlob; daGlob = cmStrCat(dir, "/*.profdata"); - cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - " looking for .profdata files in: " << daGlob << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " looking for .profdata files in: ", daGlob, '\n'); gl.FindFiles(daGlob); // Keep a list of all LCOV files cm::append(profRawFiles, gl.GetFiles()); if (profRawFiles.empty()) { - cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - " Cannot find any profdata coverage files." << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Cannot find any profdata coverage files.\n"); // No coverage files is a valid thing, so the exit code is 0 return 0; } @@ -1330,16 +1269,14 @@ int cmCTestCoverageHandler::HandleClangSourceCodeCoverage( // Loop through object files and export LCOV format for each one std::vector objectFiles; daGlob = cmStrCat(dir, "/*.o"); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " looking for .o files in: " << daGlob << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " looking for .o files in: ", daGlob, '\n'); gl.FindFiles(daGlob); // Keep a list of all LCOV files cm::append(objectFiles, gl.GetFiles()); if (objectFiles.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Cannot find any object files." << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Cannot find any object files.\n"); // No coverage files is a valid thing, so the exit code is 0 return 0; } @@ -1393,9 +1330,8 @@ void cmCTestCoverageHandler::HandleClangSourceCodeCoverageFile( cmsys::ifstream in(coveredFile); if (!in) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Cannot find " << coveredFile << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Cannot find ", coveredFile, '\n'); pauseCollecting = true; } else { while (cmSystemTools::GetLineFromStream(in, line)) { @@ -1443,23 +1379,20 @@ int cmCTestCoverageHandler::HandleLCovCoverage( std::string lcovExtraFlags = this->CTest->GetCTestConfiguration("CoverageExtraFlags"); if (lcovCommand != "codecov") { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Not a valid Intel Coverage command." << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Not a valid Intel Coverage command.\n"); return 0; } // There is only percentage completed output from LCOV std::string st2lcovOutputRex3 = "[0-9]+%"; cmsys::RegularExpression st2re3(st2lcovOutputRex3.c_str()); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " This is coverage command: " << lcovCommand << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " This is coverage command: ", lcovCommand, '\n'); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " These are coverage command flags: " << lcovExtraFlags - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " These are coverage command flags: ", lcovExtraFlags, + '\n'); std::vector files; if (!this->FindLCovFiles(files)) { @@ -1469,9 +1402,8 @@ int cmCTestCoverageHandler::HandleLCovCoverage( } if (files.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Cannot find any LCov coverage files." << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Cannot find any LCov coverage files.\n"); // No coverage files is a valid thing, so the exit code is 0 return 0; } @@ -1480,11 +1412,9 @@ int cmCTestCoverageHandler::HandleLCovCoverage( std::set missingFiles; std::string actualSourceFile; - cmCTestOptionalLog( - this->CTest, HANDLER_OUTPUT, - " Processing coverage (each . represents one file):" << std::endl, - this->Quiet); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " Processing coverage (each . represents one file):\n"); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, " "); int file_count = 0; // make sure output from lcov is in English! @@ -1499,21 +1429,19 @@ int cmCTestCoverageHandler::HandleLCovCoverage( // In intel compiler we have to call codecov only once in each executable // directory. It collects all *.dyn files to generate .dpi file. for (std::string const& f : files) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "." << std::flush, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, '.'); std::string fileDir = cmSystemTools::GetFilenamePath(f); cmWorkingDirectory workdir(fileDir); if (workdir.Failed()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, workdir.GetError() << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, workdir.GetError(), '\n'); cont->Error++; continue; } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Current coverage dir: " << fileDir << std::endl, - this->Quiet); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - command << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Current coverage dir: ", fileDir, '\n'); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + command, '\n'); std::string output; std::string errors; @@ -1528,27 +1456,25 @@ int cmCTestCoverageHandler::HandleLCovCoverage( *cont->OFS << " Errors: " << errors << std::endl; if (!res) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem running coverage on file: " << f << std::endl); + "Problem running coverage on file: ", f, '\n'); cmCTestLog(this->CTest, ERROR_MESSAGE, - "Command produced error: " << errors << std::endl); + "Command produced error: ", errors, '\n'); cont->Error++; continue; } if (retVal != 0) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Coverage command returned: " - << retVal << " while processing: " << f << std::endl); + "Coverage command returned: ", retVal, + " while processing: ", f, '\n'); cmCTestLog(this->CTest, ERROR_MESSAGE, - "Command produced error: " << cont->Error << std::endl); + "Command produced error: ", cont->Error, '\n'); } cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - "--------------------------------------------------------------" - << std::endl - << output << std::endl - << "--------------------------------------------------------------" - << std::endl, - this->Quiet); + this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "--------------------------------------------------------------\n", + output, + "\n" + "--------------------------------------------------------------\n"); std::vector lines; cmsys::SystemTools::Split(output, lines); @@ -1571,9 +1497,8 @@ int cmCTestCoverageHandler::HandleLCovCoverage( dir = this->CTest->GetBinaryDir(); std::string daGlob; daGlob = cmStrCat(dir, "/*.LCOV"); - cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - " looking for LCOV files in: " << daGlob << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " looking for LCOV files in: ", daGlob, '\n'); gl.FindFiles(daGlob); // Keep a list of all LCOV files cm::append(lcovFiles, gl.GetFiles()); @@ -1583,16 +1508,15 @@ int cmCTestCoverageHandler::HandleLCovCoverage( cmsys::ifstream srcead(lcovFile.c_str()); if (!srcead) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot open file: " << lcovFile << std::endl); + "Cannot open file: ", lcovFile, '\n'); } std::string srcname; int success = cmSystemTools::GetLineFromStream(srcead, srcname); if (!success) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Error while parsing lcov file '" - << lcovFile << "':" - << " No source file name found!" << std::endl); + "Error while parsing lcov file '", lcovFile, + "':", " No source file name found!\n"); return 0; } srcname = srcname.substr(18); @@ -1602,37 +1526,33 @@ int cmCTestCoverageHandler::HandleLCovCoverage( actualSourceFile = srcname; for (std::string const& t : lcovFiles) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Found LCOV File: " << t << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Found LCOV File: ", t, '\n'); } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "SourceFile: " << sourceFile << std::endl, - this->Quiet); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "lCovFile: " << lcovFile << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "SourceFile: ", sourceFile, '\n'); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "lCovFile: ", lcovFile, '\n'); // If we have some LCOV files to process if (!lcovFile.empty() && !actualSourceFile.empty()) { cmCTestCoverageHandlerContainer::SingleFileCoverageVector& vec = cont->TotalCoverage[actualSourceFile]; - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " in lcovFile: " << lcovFile << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " in lcovFile: ", lcovFile, '\n'); cmsys::ifstream ifile(lcovFile.c_str()); if (!ifile) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot open file: " << lcovFile << std::endl); + "Cannot open file: ", lcovFile, '\n'); } else { std::string nl; // Skip the first line cmSystemTools::GetLineFromStream(ifile, nl); cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "File is ready, start reading." << std::endl, - this->Quiet); + this->Quiet, "File is ready, start reading.\n"); while (cmSystemTools::GetLineFromStream(ifile, nl)) { // Skip empty lines if (nl.empty()) { @@ -1680,11 +1600,10 @@ int cmCTestCoverageHandler::HandleLCovCoverage( file_count++; if (file_count % 50 == 0) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " processed: " << file_count << " out of " - << files.size() << std::endl, - this->Quiet); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " processed: ", file_count, " out of ", files.size(), + '\n'); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, " "); } } @@ -1705,9 +1624,8 @@ void cmCTestCoverageHandler::FindGCovFiles(std::vector& files) // Coverage files appear next to their object files in the target // support directory. - cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - " globbing for coverage in: " << lm.first << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " globbing for coverage in: ", lm.first, '\n'); std::string daGlob = cmStrCat(lm.first, "/*.da"); gl.FindFiles(daGlob); cm::append(files, gl.GetFiles()); @@ -1726,7 +1644,7 @@ bool cmCTestCoverageHandler::FindLCovFiles(std::vector& files) std::string buildDir = this->CTest->GetCTestConfiguration("BuildDirectory"); cmWorkingDirectory workdir(buildDir); if (workdir.Failed()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, workdir.GetError() << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, workdir.GetError(), '\n'); return false; } @@ -1739,17 +1657,16 @@ bool cmCTestCoverageHandler::FindLCovFiles(std::vector& files) // DPI file should appear in build directory std::string daGlob; daGlob = cmStrCat(buildDir, "/*.dpi"); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " looking for dpi files in: " << daGlob << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " looking for dpi files in: ", daGlob, '\n'); if (!gl.FindFiles(daGlob)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Error while finding files matching " << daGlob << std::endl); + "Error while finding files matching ", daGlob, '\n'); return false; } cm::append(files, gl.GetFiles()); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Now searching in: " << daGlob << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Now searching in: ", daGlob, '\n'); return true; } @@ -1764,10 +1681,8 @@ int cmCTestCoverageHandler::HandleTracePyCoverage( std::vector files = gl.GetFiles(); if (files.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Cannot find any Python Trace.py coverage files." - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Cannot find any Python Trace.py coverage files.\n"); // No coverage files is a valid thing, so the exit code is 0 return 0; } @@ -1781,24 +1696,21 @@ int cmCTestCoverageHandler::HandleTracePyCoverage( std::string fileName = this->FindFile(cont, file); if (fileName.empty()) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot find source Python file corresponding to: " - << file << std::endl); + "Cannot find source Python file corresponding to: ", file, + '\n'); continue; } std::string actualSourceFile = cmSystemTools::CollapseFullPath(fileName); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Check coverage for file: " << actualSourceFile - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Check coverage for file: ", actualSourceFile, '\n'); cmCTestCoverageHandlerContainer::SingleFileCoverageVector* vec = &cont->TotalCoverage[actualSourceFile]; - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " in file: " << file << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " in file: ", file, '\n'); cmsys::ifstream ifile(file.c_str()); if (!ifile) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot open file: " << file << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open file: ", file, '\n'); } else { long cnt = -1; std::string nl; @@ -1834,8 +1746,7 @@ int cmCTestCoverageHandler::HandleTracePyCoverage( } if (pos == 8) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Currently the limit is maximum coverage of 999999" - << std::endl); + "Currently the limit is maximum coverage of 999999\n"); } // Read the line number starting at the 10th character of the gcov // output line @@ -1917,21 +1828,20 @@ int cmCTestCoverageHandler::RunBullseyeCoverageBranch( // for each file run covbr on that file to get the coverage // information for that file std::string outputFile; - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "run covbr: " << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "run covbr: \n"); if (!this->RunBullseyeCommand(cont, "covbr", nullptr, outputFile)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, "error running covbr for." << "\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, "error running covbr for.\n"); return -1; } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "covbr output in " << outputFile << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "covbr output in ", outputFile, '\n'); // open the output file cmsys::ifstream fin(outputFile.c_str()); if (!fin) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot open coverage file: " << outputFile << std::endl); + "Cannot open coverage file: ", outputFile, '\n'); return 0; } std::map fileMap; @@ -1962,9 +1872,8 @@ int cmCTestCoverageHandler::RunBullseyeCoverageBranch( } // only allow 100 files in each log file if (count != 0 && count % 100 == 0) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "start a new log file: " << count << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "start a new log file: ", count, '\n'); this->EndCoverageLogXML(covLogXML); this->EndCoverageLogFile(covLogFile, logFileCount); logFileCount++; @@ -1979,10 +1888,9 @@ int cmCTestCoverageHandler::RunBullseyeCoverageBranch( if (i != fileMap.end()) { // we have a new file so count it in the output count++; - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Produce coverage for file: " << file << " " - << count << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Produce coverage for file: ", file, " ", count, + '\n'); // start the file output covLogXML.StartElement("File"); covLogXML.Attribute("Name", i->first); @@ -2031,17 +1939,17 @@ int cmCTestCoverageHandler::RunBullseyeCommand( { std::string program = cmSystemTools::FindProgram(cmd); if (program.empty()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot find :" << cmd << "\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot find :", cmd, '\n'); return 0; } std::vector args{ cmd }; if (arg) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Run : " << program << " " << arg << "\n", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Run : ", program, " ", arg, '\n'); args.emplace_back(arg); } else { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Run : " << program << "\n", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Run : ", program, '\n'); } // create a process object and start it cmUVProcessChainBuilder builder; @@ -2084,7 +1992,7 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary( if (!this->StartResultingXML(cmCTest::PartCoverage, "Coverage", covSumFile)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot open coverage summary file." << std::endl); + "Cannot open coverage summary file.\n"); return 0; } this->CTest->StartXML(xml, this->CMake, this->AppendXML); @@ -2117,8 +2025,7 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary( cmsys::ifstream fin(outputFile.c_str()); if (!fin) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot open coverage summary file: " << outputFile - << std::endl); + "Cannot open coverage summary file: ", outputFile, '\n'); return 0; } std::set coveredFileNames; @@ -2144,16 +2051,13 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary( this->ShouldIDoCoverage(file, cont->SourceDir, cont->BinaryDir); if (!shouldIDoCoverage) { cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - ".NoDartCoverage found, so skip coverage check for: " << file - << std::endl, - this->Quiet); + this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + ".NoDartCoverage found, so skip coverage check for: ", file, '\n'); continue; } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Doing coverage for: " << file << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Doing coverage for: ", file, '\n'); coveredFiles.push_back(sourceFile); coveredFilesFullPath.push_back(file); @@ -2228,23 +2132,20 @@ int cmCTestCoverageHandler::HandleBullseyeCoverage( { std::string covfile; if (!cmSystemTools::GetEnv("COVFILE", covfile) || covfile.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, " COVFILE environment variable not found, not running " - " bullseye\n", - this->Quiet); + " bullseye\n"); return 0; } - cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - " run covsrc with COVFILE=[" << covfile << "]" << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " run covsrc with COVFILE=[", covfile, "]\n"); if (!this->RunBullseyeSourceSummary(cont)) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Error running bullseye summary.\n"); return 0; } - cmCTestOptionalLog(this->CTest, DEBUG, - "HandleBullseyeCoverage return 1 " << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, + "HandleBullseyeCoverage return 1 \n"); return 1; } @@ -2271,7 +2172,7 @@ bool cmCTestCoverageHandler::ParseBullsEyeCovsrcLine( std::string::size_type pos = inputLine.find(','); if (pos == std::string::npos) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Error parsing string : " << inputLine << "\n"); + "Error parsing string : ", inputLine, '\n'); return false; } // the source file has "" around it so extract out the file name @@ -2297,9 +2198,8 @@ bool cmCTestCoverageHandler::ParseBullsEyeCovsrcLine( } // should be at the end now if (pos != std::string::npos) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Error parsing input : " - << inputLine << " last pos not npos = " << pos << "\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Error parsing input : ", inputLine, + " last pos not npos = ", pos, '\n'); } return true; } @@ -2320,9 +2220,8 @@ void cmCTestCoverageHandler::LoadLabels() { std::string fileList = cmStrCat(this->CTest->GetBinaryDir(), "/CMakeFiles/TargetDirectories.txt"); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " target directory list [" << fileList << "]\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " target directory list [", fileList, "]\n"); cmsys::ifstream finList(fileList.c_str()); std::string line; while (cmSystemTools::GetLineFromStream(finList, line)) { @@ -2339,8 +2238,8 @@ void cmCTestCoverageHandler::LoadLabels(char const* dir) return; } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " loading labels from [" << fname << "]\n", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " loading labels from [", fname, "]\n"); bool inTarget = true; std::string source; std::string line; diff --git a/Source/CTest/cmCTestCurl.cxx b/Source/CTest/cmCTestCurl.cxx index 30f63b91a1..4fe8d7657a 100644 --- a/Source/CTest/cmCTestCurl.cxx +++ b/Source/CTest/cmCTestCurl.cxx @@ -3,7 +3,6 @@ #include "cmCTestCurl.h" #include -#include #include @@ -145,7 +144,7 @@ bool cmCTestCurl::UploadFile(std::string const& local_file, FILE* ftpfile = cmsys::SystemTools::Fopen(local_file, "rb"); if (!ftpfile) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Could not open file for upload: " << local_file << "\n"); + "Could not open file for upload: ", local_file, "\n"); return false; } // set the url @@ -165,9 +164,8 @@ bool cmCTestCurl::UploadFile(std::string const& local_file, ::curl_slist_append(nullptr, "Content-Type: text/xml"); // Add any additional headers that the user specified. for (std::string const& h : this->HttpHeaders) { - cmCTestOptionalLog(this->CTest, DEBUG, - " Add HTTP Header: \"" << h << "\"" << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, + " Add HTTP Header: \"", h, "\"\n"); headers = ::curl_slist_append(headers, h.c_str()); } ::curl_easy_setopt(this->Curl, CURLOPT_HTTPHEADER, headers); @@ -184,19 +182,18 @@ bool cmCTestCurl::UploadFile(std::string const& local_file, if (!responseData.empty()) { response = std::string(responseData.begin(), responseData.end()); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Curl response: [" << response << "]\n", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Curl response: [", response, "]\n"); } std::string curlDebug; if (!debugData.empty()) { curlDebug = std::string(debugData.begin(), debugData.end()); - cmCTestOptionalLog(this->CTest, DEBUG, - "Curl debug: [" << curlDebug << "]\n", this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, "Curl debug: [", + curlDebug, "]\n"); } if (response.empty()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "No response from server.\n" - << curlDebug << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "No response from server.\n", + curlDebug, '\n'); return false; } return true; @@ -206,11 +203,8 @@ bool cmCTestCurl::HttpRequest(std::string const& url, std::string const& fields, std::string& response) { response.clear(); - cmCTestOptionalLog(this->CTest, DEBUG, - "HttpRequest\n" - << "url: " << url << "\n" - << "fields " << fields << "\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, "HttpRequest\n", + "url: ", url, '\n', "fields ", fields, '\n'); if (!this->InitCurl()) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Initialization of curl failed\n"); return false; @@ -233,9 +227,8 @@ bool cmCTestCurl::HttpRequest(std::string const& url, struct curl_slist* headers = nullptr; if (!this->HttpHeaders.empty()) { for (std::string const& h : this->HttpHeaders) { - cmCTestOptionalLog(this->CTest, DEBUG, - " Add HTTP Header: \"" << h << "\"" << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, + " Add HTTP Header: \"", h, "\"\n"); headers = ::curl_slist_append(headers, h.c_str()); } } @@ -246,16 +239,15 @@ bool cmCTestCurl::HttpRequest(std::string const& url, if (!responseData.empty()) { response = std::string(responseData.begin(), responseData.end()); - cmCTestOptionalLog(this->CTest, DEBUG, - "Curl response: [" << response << "]\n", this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, "Curl response: [", + response, "]\n"); } if (!debugData.empty()) { std::string curlDebug = std::string(debugData.begin(), debugData.end()); - cmCTestOptionalLog(this->CTest, DEBUG, - "Curl debug: [" << curlDebug << "]\n", this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, "Curl debug: [", + curlDebug, "]\n"); } - cmCTestOptionalLog(this->CTest, DEBUG, "Curl res: " << res << "\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, "Curl res: ", res, "\n"); return (res == 0); } diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 26930b5b75..73debea8df 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -74,8 +74,7 @@ bool cmCTestGIT::NoteOldRevision() { this->OldRevision = this->GetWorkingRevision(); cmCTestLog(this->CTest, HANDLER_OUTPUT, - " Old revision of repository is: " << this->OldRevision - << "\n"); + " Old revision of repository is: ", this->OldRevision, '\n'); this->PriorRev.Rev = this->OldRevision; return true; } @@ -84,8 +83,7 @@ bool cmCTestGIT::NoteNewRevision() { this->NewRevision = this->GetWorkingRevision(); cmCTestLog(this->CTest, HANDLER_OUTPUT, - " New revision of repository is: " << this->NewRevision - << "\n"); + " New revision of repository is: ", this->NewRevision, '\n'); return true; } diff --git a/Source/CTest/cmCTestGlobalVC.cxx b/Source/CTest/cmCTestGlobalVC.cxx index 04a1a51e51..b38f60ec29 100644 --- a/Source/CTest/cmCTestGlobalVC.cxx +++ b/Source/CTest/cmCTestGlobalVC.cxx @@ -34,7 +34,7 @@ void cmCTestGlobalVC::DoRevision(Revision const& revision, } // Indicate we found a revision. - cmCTestLog(this->CTest, HANDLER_OUTPUT, "." << std::flush); + cmCTestLog(this->CTest, HANDLER_OUTPUT, '.'); // Store the revision. this->Revisions.push_back(revision); @@ -43,8 +43,8 @@ void cmCTestGlobalVC::DoRevision(Revision const& revision, Revision const& rev = this->Revisions.back(); /* clang-format off */ this->Log << "Found revision " << rev.Rev << "\n" - << " author = " << rev.Author << "\n" - << " date = " << rev.Date << "\n"; + " author = " << rev.Author << "\n" + " date = " << rev.Date << '\n'; /* clang-format on */ // Update information about revisions of the changed files. @@ -104,10 +104,9 @@ bool cmCTestGlobalVC::WriteXMLUpdates(cmXMLWriter& xml) bool result = true; cmCTestLog(this->CTest, HANDLER_OUTPUT, " Gathering version information (one . per revision):\n" - " " - << std::flush); + " "); result = this->LoadRevisions() && result; - cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl); + cmCTestLog(this->CTest, HANDLER_OUTPUT, '\n'); result = this->LoadModifications() && result; diff --git a/Source/CTest/cmCTestHG.cxx b/Source/CTest/cmCTestHG.cxx index 04274ea403..06624c8345 100644 --- a/Source/CTest/cmCTestHG.cxx +++ b/Source/CTest/cmCTestHG.cxx @@ -110,8 +110,7 @@ bool cmCTestHG::NoteOldRevision() { this->OldRevision = this->GetWorkingRevision(); cmCTestLog(this->CTest, HANDLER_OUTPUT, - " Old revision of repository is: " << this->OldRevision - << "\n"); + " Old revision of repository is: ", this->OldRevision, '\n'); this->PriorRev.Rev = this->OldRevision; return true; } @@ -120,8 +119,7 @@ bool cmCTestHG::NoteNewRevision() { this->NewRevision = this->GetWorkingRevision(); cmCTestLog(this->CTest, HANDLER_OUTPUT, - " New revision of repository is: " << this->NewRevision - << "\n"); + " New revision of repository is: ", this->NewRevision, '\n'); return true; } diff --git a/Source/CTest/cmCTestHandlerCommand.cxx b/Source/CTest/cmCTestHandlerCommand.cxx index a85386ea75..5fb91bd732 100644 --- a/Source/CTest/cmCTestHandlerCommand.cxx +++ b/Source/CTest/cmCTestHandlerCommand.cxx @@ -4,7 +4,6 @@ #include #include -#include #include @@ -108,8 +107,8 @@ bool cmCTestHandlerCommand::InvokeImpl( } if (!success) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - this->GetName() << ' ' << status.GetError() << '\n'); + cmCTestLog(this->CTest, ERROR_MESSAGE, this->GetName(), ' ', + status.GetError(), '\n'); } cmMakefile& mf = status.GetMakefile(); @@ -146,12 +145,12 @@ bool cmCTestHandlerCommand::ExecuteHandlerCommand( "BuildDirectory", cmSystemTools::CollapseFullPath(bdir), args.Quiet); } else { cmCTestLog(this->CTest, ERROR_MESSAGE, - "CTEST_BINARY_DIRECTORY not set" << std::endl); + "CTEST_BINARY_DIRECTORY not set\n"); } } if (!args.Source.empty()) { - cmCTestLog(this->CTest, DEBUG, - "Set source directory to: " << args.Source << std::endl); + cmCTestLog(this->CTest, DEBUG, "Set source directory to: ", args.Source, + '\n'); this->CTest->SetCTestConfiguration( "SourceDirectory", cmSystemTools::CollapseFullPath(args.Source), args.Quiet); @@ -167,12 +166,11 @@ bool cmCTestHandlerCommand::ExecuteHandlerCommand( this->CTest->SetCTestConfiguration("ChangeId", *changeId, args.Quiet); } - cmCTestLog(this->CTest, DEBUG, "Initialize handler" << std::endl); + cmCTestLog(this->CTest, DEBUG, "Initialize handler\n"); auto handler = this->InitializeHandler(args, status); if (!handler) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot instantiate test handler " << this->GetName() - << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot instantiate test handler ", + this->GetName(), '\n'); return false; } diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index c691c5a598..1568b8bb7f 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -43,9 +43,8 @@ static CatToErrorType cmCTestMemCheckBoundsChecker[] = { static void xmlReportError(int line, char const* msg, void* data) { cmCTest* ctest = static_cast(data); - cmCTestLog(ctest, ERROR_MESSAGE, - "Error parsing XML in stream at line " << line << ": " << msg - << std::endl); + cmCTestLog(ctest, ERROR_MESSAGE, "Error parsing XML in stream at line ", + line, ": ", msg, '\n'); } // parse the xml file containing the results of last BoundsChecker run @@ -106,8 +105,8 @@ public: if (ptr->ErrorCategory) { this->Errors.push_back(cmCTestMemCheckHandler::ABW); // do not know cmCTestLog(this->CTest, ERROR_MESSAGE, - "Found unknown Bounds Checker error " << ptr->ErrorCategory - << std::endl); + "Found unknown Bounds Checker error ", ptr->ErrorCategory, + '\n'); } } cmCTest* CTest; @@ -134,7 +133,7 @@ int cmCTestMemCheckHandler::PreProcessHandler() if (!this->ExecuteCommands(this->CustomPreMemCheck)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem executing pre-memcheck command(s)." << std::endl); + "Problem executing pre-memcheck command(s).\n"); return 0; } return 1; @@ -144,7 +143,7 @@ int cmCTestMemCheckHandler::PostProcessHandler() { if (!this->ExecuteCommands(this->CustomPostMemCheck)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem executing post-memcheck command(s)." << std::endl); + "Problem executing post-memcheck command(s).\n"); return 0; } return 1; @@ -213,9 +212,8 @@ void cmCTestMemCheckHandler::GenerateTestCommand( cmSystemTools::MakeDirectory(dir); } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Memory check command: " << memcheckcommand << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Memory check command: ", memcheckcommand, '\n'); } void cmCTestMemCheckHandler::InitializeResultsVectors() @@ -342,8 +340,8 @@ void cmCTestMemCheckHandler::GenerateCTestXML(cmXMLWriter& xml) xml.Element("Test", this->CTest->GetShortPathToFile(testPath)); } xml.EndElement(); // TestList - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - "-- Processing memory checking output:\n", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + "-- Processing memory checking output:\n"); size_t total = this->TestResults.size(); for (cc = 0; cc < this->TestResults.size(); cc++) { cmCTestTestResult const& result = this->TestResults[cc]; @@ -377,11 +375,9 @@ void cmCTestMemCheckHandler::GenerateCTestXML(cmXMLWriter& xml) size_t const maxTestNameWidth = std::max( this->CTest->GetMaxTestNameWidth(), result.Name.size()); outname.resize(maxTestNameWidth + 4, '.'); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - cc + 1 << "/" << total << " MemCheck: #" - << result.TestCount << ": " << outname - << " Defects: " << memoryErrors << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, cc + 1, '/', + total, " MemCheck: #", result.TestCount, ": ", + outname, " Defects: ", memoryErrors, '\n'); } xml.StartElement("Log"); if (this->CTest->ShouldCompressTestOutput()) { @@ -394,25 +390,21 @@ void cmCTestMemCheckHandler::GenerateCTestXML(cmXMLWriter& xml) this->WriteTestResultFooter(xml, result); } - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, "MemCheck log files can be found here: " - "(<#> corresponds to test number)" - << std::endl, - this->Quiet); + "(<#> corresponds to test number)\n"); std::string output = this->MemoryTesterOutputFile; cmSystemTools::ReplaceString(output, "??", "<#>"); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, output << std::endl, - this->Quiet); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - "Memory checking results:" << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, output, '\n'); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + "Memory checking results:\n"); xml.StartElement("DefectList"); for (cc = 0; cc < this->GlobalResults.size(); cc++) { if (this->GlobalResults[cc]) { std::cerr.width(35); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - this->ResultStringsLong[cc] - << " - " << this->GlobalResults[cc] << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + this->ResultStringsLong[cc], " - ", + this->GlobalResults[cc], '\n'); xml.StartElement("Defect"); xml.Attribute("Type", this->ResultStringsLong[cc]); xml.EndElement(); @@ -530,11 +522,9 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() } } if (this->MemoryTester.empty()) { - cmCTestOptionalLog(this->CTest, WARNING, + cmCTestOptionalLog(this->CTest, WARNING, this->Quiet, "Memory checker (MemoryCheckCommand) " - "not set, or cannot find the specified program." - << std::endl, - this->Quiet); + "not set, or cannot find the specified program.\n"); return false; } @@ -576,11 +566,11 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() .empty()) { if (!cmSystemTools::FileExists(this->CTest->GetCTestConfiguration( "MemoryCheckSuppressionFile"))) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot find memory checker suppression file: " - << this->CTest->GetCTestConfiguration( - "MemoryCheckSuppressionFile") - << std::endl); + cmCTestLog( + this->CTest, ERROR_MESSAGE, + "Cannot find memory checker suppression file: ", + this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile"), + '\n'); return false; } this->MemoryTesterOptions.push_back( @@ -633,11 +623,11 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() .empty()) { if (!cmSystemTools::FileExists(this->CTest->GetCTestConfiguration( "MemoryCheckSuppressionFile"))) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot find memory checker suppression file: " - << this->CTest->GetCTestConfiguration( - "MemoryCheckSuppressionFile") - << std::endl); + cmCTestLog( + this->CTest, ERROR_MESSAGE, + "Cannot find memory checker suppression file: ", + this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile"), + '\n'); return false; } this->MemoryTesterOptions.emplace_back("-suppress"); @@ -658,11 +648,9 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() "MemoryCheckSuppressionFile"))) { cmCTestLog( this->CTest, ERROR_MESSAGE, - "Cannot find memory checker suppression file: " - << this->CTest - ->GetCTestConfiguration("MemoryCheckSuppressionFile") - .c_str() - << std::endl); + "Cannot find memory checker suppression file: ", + this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile"), + '\n'); return false; } std::string filterFiles = "/FilterFiles=" + @@ -752,8 +740,8 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() } default: cmCTestLog(this->CTest, ERROR_MESSAGE, - "Do not understand memory checker: " << this->MemoryTester - << std::endl); + "Do not understand memory checker: ", this->MemoryTester, + '\n'); return false; } @@ -886,8 +874,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput( } if (cc == this->ResultStrings.size()) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unknown Purify memory fault: " << pfW.match(1) - << std::endl); + "Unknown Purify memory fault: ", pfW.match(1), '\n'); ostr << "*** Unknown Purify memory fault: " << pfW.match(1) << std::endl; } @@ -959,17 +946,16 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput( "locked by a different thread"); std::vector nonValGrindOutput; auto sttime = std::chrono::steady_clock::now(); - cmCTestOptionalLog(this->CTest, DEBUG, - "Start test: " << lines.size() << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, + "Start test: ", lines.size(), '\n'); std::string::size_type totalOutputSize = 0; for (cc = 0; cc < lines.size(); cc++) { - cmCTestOptionalLog(this->CTest, DEBUG, - "test line " << lines[cc] << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, "test line ", + lines[cc], '\n'); if (valgrindLine.find(lines[cc])) { - cmCTestOptionalLog(this->CTest, DEBUG, - "valgrind line " << lines[cc] << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, "valgrind line ", + lines[cc], '\n'); int failure = cmCTestMemCheckHandler::NO_MEMORY_FAULT; auto& line = lines[cc]; if (vgFIM.find(line)) { @@ -1021,12 +1007,10 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput( break; // stop the copy of output if we are full } } - cmCTestOptionalLog(this->CTest, DEBUG, - "End test (elapsed: " - << cmDurationTo( - std::chrono::steady_clock::now() - sttime) - << "s)" << std::endl, - this->Quiet); + cmCTestOptionalLog( + this->CTest, DEBUG, this->Quiet, "End test (elapsed: ", + cmDurationTo(std::chrono::steady_clock::now() - sttime), + "s)\n"); log = ostr.str(); this->DefectCount += defects; return defects == 0; @@ -1076,8 +1060,8 @@ bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput( auto sttime = std::chrono::steady_clock::now(); std::vector lines; cmsys::SystemTools::Split(str, lines); - cmCTestOptionalLog(this->CTest, DEBUG, - "Start test: " << lines.size() << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, + "Start test: ", lines.size(), '\n'); std::vector::size_type cc; for (cc = 0; cc < lines.size(); cc++) { if (lines[cc] == BOUNDS_CHECKER_MARKER) { @@ -1095,7 +1079,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput( // skip this because BC gets it wrong and we can't parse it } else if (!parser.ParseChunk(theLine.c_str(), theLine.size())) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Error in ParseChunk: " << theLine << std::endl); + "Error in ParseChunk: ", theLine, '\n'); } } } @@ -1104,12 +1088,10 @@ bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput( results[err]++; defects++; } - cmCTestOptionalLog(this->CTest, DEBUG, - "End test (elapsed: " - << cmDurationTo( - std::chrono::steady_clock::now() - sttime) - << "s)" << std::endl, - this->Quiet); + cmCTestOptionalLog( + this->CTest, DEBUG, this->Quiet, "End test (elapsed: ", + cmDurationTo(std::chrono::steady_clock::now() - sttime), + "s)\n"); if (defects) { // only put the output of Bounds Checker if there were // errors or leaks detected @@ -1171,17 +1153,16 @@ bool cmCTestMemCheckHandler::ProcessMemCheckCudaOutput( std::vector nonMemcheckOutput; auto sttime = std::chrono::steady_clock::now(); - cmCTestOptionalLog(this->CTest, DEBUG, - "Start test: " << lines.size() << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, + "Start test: ", lines.size(), '\n'); std::string::size_type totalOutputSize = 0; for (cc = 0; cc < lines.size(); cc++) { - cmCTestOptionalLog(this->CTest, DEBUG, - "test line " << lines[cc] << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, "test line ", + lines[cc], '\n'); if (memcheckLine.find(lines[cc])) { - cmCTestOptionalLog(this->CTest, DEBUG, - "cuda sanitizer line " << lines[cc] << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, + "cuda sanitizer line ", lines[cc], '\n'); int failure = -1; auto& line = lines[cc]; if (leakExpr.find(line)) { @@ -1235,12 +1216,10 @@ bool cmCTestMemCheckHandler::ProcessMemCheckCudaOutput( break; // stop the copy of output if we are full } } - cmCTestOptionalLog(this->CTest, DEBUG, - "End test (elapsed: " - << cmDurationTo( - std::chrono::steady_clock::now() - sttime) - << "s)" << std::endl, - this->Quiet); + cmCTestOptionalLog( + this->CTest, DEBUG, this->Quiet, "End test (elapsed: ", + cmDurationTo(std::chrono::steady_clock::now() - sttime), + "s)\n"); log = ostr.str(); this->DefectCount += defects; return defects == 0; @@ -1249,10 +1228,9 @@ bool cmCTestMemCheckHandler::ProcessMemCheckCudaOutput( // PostProcessTest memcheck results void cmCTestMemCheckHandler::PostProcessTest(cmCTestTestResult& res, int test) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "PostProcessTest memcheck results for : " << res.Name - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "PostProcessTest memcheck results for : ", res.Name, + '\n'); if (this->MemoryTesterStyle == cmCTestMemCheckHandler::BOUNDS_CHECKER) { this->PostProcessBoundsCheckerTest(res, test); } else if (this->MemoryTesterStyle == cmCTestMemCheckHandler::DRMEMORY) { @@ -1271,10 +1249,8 @@ void cmCTestMemCheckHandler::PostProcessTest(cmCTestTestResult& res, int test) void cmCTestMemCheckHandler::PostProcessBoundsCheckerTest( cmCTestTestResult& res, int test) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "PostProcessBoundsCheckerTest for : " << res.Name - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "PostProcessBoundsCheckerTest for : ", res.Name, '\n'); std::vector files; this->TestOutputFileNames(test, files); if (files.empty()) { @@ -1289,8 +1265,8 @@ void cmCTestMemCheckHandler::PostProcessBoundsCheckerTest( cmsys::ifstream ifs(ofile.c_str()); if (!ifs) { cmCTestLog(this->CTest, ERROR_MESSAGE, - cmStrCat("Cannot read memory tester output file: ", ofile) - << std::endl); + cmStrCat("Cannot read memory tester output file: ", ofile), + '\n'); return; } res.Output = cmStrCat(std::move(res.Output), BOUNDS_CHECKER_MARKER, '\n'); @@ -1301,13 +1277,11 @@ void cmCTestMemCheckHandler::PostProcessBoundsCheckerTest( } cmSystemTools::Delay(1000); cmSystemTools::RemoveFile(this->BoundsCheckerDPBDFile); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Remove: " << this->BoundsCheckerDPBDFile << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Remove: ", this->BoundsCheckerDPBDFile, '\n'); cmSystemTools::RemoveFile(this->BoundsCheckerXMLFile); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Remove: " << this->BoundsCheckerXMLFile << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Remove: ", this->BoundsCheckerXMLFile, '\n'); } void cmCTestMemCheckHandler::PostProcessDrMemoryTest( @@ -1330,7 +1304,7 @@ void cmCTestMemCheckHandler::PostProcessDrMemoryTest( cmsys::ifstream ifs(f.c_str()); if (!ifs) { std::string log = "Cannot read memory tester output file: " + f; - cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, log, '\n'); return; } std::string resultFileLocation; @@ -1352,7 +1326,7 @@ void cmCTestMemCheckHandler::AppendMemTesterOutput(cmCTestTestResult& res, cmsys::ifstream ifs(ofile.c_str()); if (!ifs) { std::string log = "Cannot read memory tester output file: " + ofile; - cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, log, '\n'); return; } std::string line; @@ -1366,10 +1340,8 @@ void cmCTestMemCheckHandler::AppendMemTesterOutput(cmCTestTestResult& res, if (pos != std::string::npos) { auto ofileWithoutPid = ofile.substr(0, pos); cmSystemTools::RenameFile(ofile, ofileWithoutPid); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Renaming: " << ofile << " to: " << ofileWithoutPid - << "\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Renaming: ", ofile, " to: ", ofileWithoutPid, "\n"); } } } @@ -1387,7 +1359,7 @@ void cmCTestMemCheckHandler::TestOutputFileNames( g.FindFiles(ofile); if (g.GetFiles().empty()) { std::string log = "Cannot find memory tester output file: " + ofile; - cmCTestLog(this->CTest, WARNING, log << std::endl); + cmCTestLog(this->CTest, WARNING, log, '\n'); ofile.clear(); } else { files = g.GetFiles(); @@ -1395,7 +1367,7 @@ void cmCTestMemCheckHandler::TestOutputFileNames( } } else if (!cmSystemTools::FileExists(ofile)) { std::string log = "Cannot find memory tester output file: " + ofile; - cmCTestLog(this->CTest, WARNING, log << std::endl); + cmCTestLog(this->CTest, WARNING, log, '\n'); ofile.clear(); } files.push_back(std::move(ofile)); diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index 9b946315c5..7017c4c1fb 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -411,8 +410,7 @@ void cmCTestMultiProcessHandler::InitializeLoop() *this->Loop, /*onToken=*/[this]() { this->JobServerReceivedToken(); }, /*onDisconnect=*/nullptr); if (this->JobServerClient) { - cmCTestLog(this->CTest, OUTPUT, - "Connected to MAKE jobserver" << std::endl); + cmCTestLog(this->CTest, OUTPUT, "Connected to MAKE jobserver\n"); } } @@ -457,8 +455,8 @@ void cmCTestMultiProcessHandler::RunTests() void cmCTestMultiProcessHandler::StartTestProcess(int test) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "test " << test << "\n", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, "test ", + test, "\n"); auto testRun = cm::make_unique(*this, test); @@ -694,8 +692,7 @@ void cmCTestMultiProcessHandler::SetStopTimePassed() if (!this->StopTimePassed) { cmCTestLog(this->CTest, ERROR_MESSAGE, "The stop time has been passed. " - "Stopping all tests." - << std::endl); + "Stopping all tests.\n"); this->StopTimePassed = true; } } @@ -914,10 +911,9 @@ void cmCTestMultiProcessHandler::StartNextTests() // We found a test that fits in the spare load. allTestsFailedTestLoadCheck = false; - cmCTestLog(this->CTest, DEBUG, - "OK to run " - << this->GetName(test) << ", it requires " << processors - << " procs & system load is: " << systemLoad << std::endl); + cmCTestLog(this->CTest, DEBUG, "OK to run ", this->GetName(test), + ", it requires ", processors, + " procs & system load is: ", systemLoad, '\n'); } // Exclude tests that are too big to fit in the concurrency limit. @@ -965,19 +961,19 @@ void cmCTestMultiProcessHandler::StartNextTests() } else if (!testWithMinProcessors.empty()) { /* clang-format off */ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "System Load: " << systemLoad << ", " - "Max Allowed Load: " << this->TestLoad << ", " - "Smallest test " << testWithMinProcessors << - " requires " << minProcessorsRequired); + "System Load: ", systemLoad, ", " + "Max Allowed Load: ", this->TestLoad, ", " + "Smallest test ", testWithMinProcessors, + " requires ", minProcessorsRequired); /* clang-format on */ } else { /* clang-format off */ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "System Load: " << systemLoad << ", " - "Max Allowed Load: " << this->TestLoad); + "System Load: ", systemLoad, ", " + "Max Allowed Load: ", this->TestLoad); /* clang-format on */ } - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "*****" << std::endl); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "*****\n"); // Try again later when the load might be lower. this->StartNextTestsOnTimer(); @@ -1152,11 +1148,9 @@ void cmCTestMultiProcessHandler::RequeueRepeatGroup(RepeatGroup const& group) this->PendingTests[t.first] = std::move(info); this->OrderedTests.push_back(t.first); } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Re-queued " << group.Tests.size() - << " tests to repeat their fixture" - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Re-queued ", group.Tests.size(), + " tests to repeat their fixture\n"); } void cmCTestMultiProcessHandler::UpdateCostData() @@ -1871,45 +1865,40 @@ void cmCTestMultiProcessHandler::PrintTestList() if (!p.Labels.empty()) // print the labels { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Labels:", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Labels:"); } for (std::string const& label : p.Labels) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " " << label, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, " ", + label); } if (!p.Labels.empty()) // print the labels { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + '\n'); } if (this->TestHandler->MemCheck) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " Memory Check", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " Memory Check"); } else { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " Test", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, " Test"); } - std::ostringstream indexStr; - indexStr << " #" << p.Index << ":"; + std::string indexStr = cmStrCat(" #", p.Index, ':'); cmCTestOptionalLog( - this->CTest, HANDLER_OUTPUT, - std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex())) - << indexStr.str(), - this->Quiet); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " " << p.Name, - this->Quiet); + this->CTest, HANDLER_OUTPUT, this->Quiet, + cmPadToWidth(3 + getNumWidth(this->TestHandler->GetMaxIndex()), + std::move(indexStr))); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, ' ', p.Name); if (p.Disabled) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " (Disabled)", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " (Disabled)"); } - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, '\n'); } - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - std::endl - << "Total Tests: " << this->Total << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, '\n', + "Total Tests: ", this->Total, '\n'); } void cmCTestMultiProcessHandler::PrintLabels() @@ -1921,15 +1910,15 @@ void cmCTestMultiProcessHandler::PrintLabels() } if (!allLabels.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "All Labels:" << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + "All Labels:\n"); } else { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - "No Labels Exist" << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + "No Labels Exist\n"); } for (std::string const& label : allLabels) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " " << label << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, " ", label, + '\n'); } } @@ -1986,9 +1975,8 @@ int cmCTestMultiProcessHandler::FindMaxIndex() // Returns true if no cycles exist in the dependency graph bool cmCTestMultiProcessHandler::CheckCycles() { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Checking test dependency graph..." << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Checking test dependency graph...\n"); for (auto const& it : this->PendingTests) { // DFS from each element to itself int root = it.first; @@ -2002,12 +1990,11 @@ bool cmCTestMultiProcessHandler::CheckCycles() for (auto const& d : this->PendingTests[test].Depends) { if (d == root) { // cycle exists - cmCTestLog( - this->CTest, ERROR_MESSAGE, - "Error: a cycle exists in the test dependency graph " - "for the test \"" - << this->Properties[root]->Name - << "\".\nPlease fix the cycle and run ctest again.\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, + "Error: a cycle exists in the test dependency graph " + "for the test \"", + this->Properties[root]->Name, + "\".\nPlease fix the cycle and run ctest again.\n"); return false; } s.push(d); @@ -2015,9 +2002,8 @@ bool cmCTestMultiProcessHandler::CheckCycles() } } } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Checking test dependency graph end" << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Checking test dependency graph end\n"); return true; } @@ -2026,18 +2012,16 @@ bool cmCTestMultiProcessHandler::CheckGeneratedResourceSpec() for (auto& test : this->Properties) { if (!test.second->GeneratedResourceSpecFile.empty()) { if (this->ResourceSpecSetupTest) { - cmCTestLog( - this->CTest, ERROR_MESSAGE, - "Only one test may define the GENERATED_RESOURCE_SPEC_FILE property" - << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, + "Only one test may define the GENERATED_RESOURCE_SPEC_FILE " + "property\n"); return false; } if (test.second->FixturesSetup.size() != 1) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Test that defines GENERATED_RESOURCE_SPEC_FILE must have " - "exactly one FIXTURES_SETUP" - << std::endl); + "exactly one FIXTURES_SETUP\n"); return false; } @@ -2051,10 +2035,10 @@ bool cmCTestMultiProcessHandler::CheckGeneratedResourceSpec() if (!test.second->ResourceGroups.empty() && !test.second->FixturesRequired.count( this->ResourceSpecSetupFixture)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "All tests that have RESOURCE_GROUPS must include the " - "resource spec generator fixture in their FIXTURES_REQUIRED" - << std::endl); + cmCTestLog( + this->CTest, ERROR_MESSAGE, + "All tests that have RESOURCE_GROUPS must include the " + "resource spec generator fixture in their FIXTURES_REQUIRED\n"); return false; } } @@ -2064,13 +2048,12 @@ bool cmCTestMultiProcessHandler::CheckGeneratedResourceSpec() if (this->ResourceSpecSetupTest) { cmCTestLog(this->CTest, ERROR_MESSAGE, "GENERATED_RESOURCE_SPEC_FILE test property cannot be used " - "in conjunction with ResourceSpecFile option" - << std::endl); + "in conjunction with ResourceSpecFile option\n"); return false; } std::string error; if (!this->InitResourceAllocator(error)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, error << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, error, '\n'); return false; } } diff --git a/Source/CTest/cmCTestP4.cxx b/Source/CTest/cmCTestP4.cxx index 97d280a3aa..bf922a842d 100644 --- a/Source/CTest/cmCTestP4.cxx +++ b/Source/CTest/cmCTestP4.cxx @@ -4,7 +4,6 @@ #include #include -#include #include #include @@ -366,8 +365,7 @@ bool cmCTestP4::NoteOldRevision() this->OldRevision = this->GetWorkingRevision(); cmCTestLog(this->CTest, HANDLER_OUTPUT, - " Old revision of repository is: " << this->OldRevision - << "\n"); + " Old revision of repository is: ", this->OldRevision, '\n'); this->PriorRev.Rev = this->OldRevision; return true; } @@ -377,8 +375,7 @@ bool cmCTestP4::NoteNewRevision() this->NewRevision = this->GetWorkingRevision(); cmCTestLog(this->CTest, HANDLER_OUTPUT, - " New revision of repository is: " << this->NewRevision - << "\n"); + " New revision of repository is: ", this->NewRevision, '\n'); return true; } @@ -394,8 +391,8 @@ bool cmCTestP4::LoadRevisions() // Do not process updates if (this->OldRevision == "" || this->NewRevision == "") { cmCTestLog(this->CTest, HANDLER_OUTPUT, - " At least one of the revisions " - << "is unknown. No repository changes will be reported.\n"); + " At least one of the revisions ", + "is unknown. No repository changes will be reported.\n"); return false; } diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 18b5d24e23..1a35d51263 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -7,7 +7,6 @@ #include // IWYU pragma: keep #include #include -#include #include #include #include @@ -49,8 +48,8 @@ cmCTestRunTest::cmCTestRunTest(cmCTestMultiProcessHandler& multiHandler, void cmCTestRunTest::CheckOutput(std::string const& line) { - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->GetIndex() << ": " << line << std::endl); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->GetIndex(), ": ", line, + '\n'); // Check for special CTest XML tags in this line of output. // If any are found, this line is excluded from ProcessOutput. @@ -60,11 +59,9 @@ void cmCTestRunTest::CheckOutput(std::string const& line) ctest_tag_found = true; this->TestResult.CustomCompletionStatus = this->TestHandler->CustomCompletionStatusRegex.match(1); - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->GetIndex() << ": " - << "Test Details changed to '" - << this->TestResult.CustomCompletionStatus - << "'" << std::endl); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->GetIndex(), ": ", + "Test Details changed to '", + this->TestResult.CustomCompletionStatus, "'\n"); } else if (this->TestHandler->CustomLabelRegex.find(line)) { ctest_tag_found = true; auto label = this->TestHandler->CustomLabelRegex.match(1); @@ -72,10 +69,8 @@ void cmCTestRunTest::CheckOutput(std::string const& line) if (std::find(labels.begin(), labels.end(), label) == labels.end()) { labels.push_back(label); std::sort(labels.begin(), labels.end()); - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->GetIndex() - << ": " - << "Test Label added: '" << label << "'" << std::endl); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->GetIndex(), ": ", + "Test Label added: '", label, "'\n"); } } if (ctest_tag_found) { @@ -89,14 +84,12 @@ void cmCTestRunTest::CheckOutput(std::string const& line) if (!this->TestProperties->TimeoutRegularExpressions.empty()) { for (auto& reg : this->TestProperties->TimeoutRegularExpressions) { if (reg.first.find(this->ProcessOutput)) { - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->GetIndex() - << ": " - << "Test timeout changed to " - << std::chrono::duration_cast( - this->TestProperties->AlternateTimeout) - .count() - << std::endl); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->GetIndex(), ": ", + "Test timeout changed to ", + std::chrono::duration_cast( + this->TestProperties->AlternateTimeout) + .count(), + '\n'); this->TestProcess->ResetStartTime(); this->TestProcess->ChangeTimeout( this->TestProperties->AlternateTimeout); @@ -284,17 +277,15 @@ cmCTestRunTest::EndTestResult cmCTestRunTest::EndTest(size_t completed, } if (outputTestErrorsToConsole) { - cmCTestLog(this->CTest, HANDLER_OUTPUT, this->ProcessOutput << std::endl); + cmCTestLog(this->CTest, HANDLER_OUTPUT, this->ProcessOutput, '\n'); } if (!resourceSpecParseError.empty()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - resourceSpecParseError << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, resourceSpecParseError, '\n'); } else if (!this->TestProperties->GeneratedResourceSpecFile.empty()) { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Using generated resource spec file " - << this->TestProperties->GeneratedResourceSpecFile - << std::endl); + "Using generated resource spec file ", + this->TestProperties->GeneratedResourceSpecFile, '\n'); } if (this->TestHandler->LogFile) { @@ -470,10 +461,9 @@ void cmCTestRunTest::MemCheckPostProcess() return; } cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->Index << ": process test output now: " - << this->TestProperties->Name << " " - << this->TestResult.Name << std::endl, - this->TestHandler->GetQuiet()); + this->TestHandler->GetQuiet(), this->Index, + ": process test output now: ", this->TestProperties->Name, + ' ', this->TestResult.Name, '\n'); cmCTestMemCheckHandler* handler = static_cast(this->TestHandler); handler->PostProcessTest(this->TestResult, this->Index); @@ -498,17 +488,16 @@ void cmCTestRunTest::StartFailure(size_t total, std::string const& output, // attempt to start this test if (!this->CTest->GetTestProgressOutput()) { cmCTestLog(this->CTest, HANDLER_OUTPUT, - std::setw(2 * getNumWidth(total) + 8) - << "Start " - << std::setw(getNumWidth(this->TestHandler->GetMaxIndex())) - << this->TestProperties->Index << ": " - << this->TestProperties->Name << std::endl); + cmPadToWidth(2 * getNumWidth(total) + 8, "Start "), + cmPadToWidth(getNumWidth(this->TestHandler->GetMaxIndex()), + std::to_string(this->TestProperties->Index)), + ": ", this->TestProperties->Name, '\n'); } this->ProcessOutput.clear(); if (!output.empty()) { *this->TestHandler->LogFile << output << std::endl; - cmCTestLog(this->CTest, ERROR_MESSAGE, output << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, output, '\n'); } this->TestResult.Properties = this->TestProperties; @@ -527,23 +516,15 @@ void cmCTestRunTest::StartFailure(size_t total, std::string const& output, std::string cmCTestRunTest::GetTestPrefix(size_t completed, size_t total) const { - std::ostringstream outputStream; - outputStream << std::setw(getNumWidth(total)) << completed << "/"; - outputStream << std::setw(getNumWidth(total)) << total << " "; - - if (this->TestHandler->MemCheck) { - outputStream << "MemCheck"; - } else { - outputStream << "Test"; - } - - std::ostringstream indexStr; - indexStr << " #" << this->Index << ":"; - outputStream << std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex())) - << indexStr.str(); - outputStream << " "; - - return outputStream.str(); + int const numWidth = getNumWidth(total); + std::string indexStr = cmStrCat(" #", this->Index, ':'); + return cmStrCat( + cmPadToWidth(numWidth, std::to_string(completed)), '/', + cmPadToWidth(numWidth, std::to_string(total)), ' ', + (this->TestHandler->MemCheck ? "MemCheck" : "Test"), + cmPadToWidth(3 + getNumWidth(this->TestHandler->GetMaxIndex()), + std::move(indexStr)), + ' '); } void cmCTestRunTest::StartTest(std::unique_ptr runner, @@ -569,12 +550,11 @@ bool cmCTestRunTest::StartTest(size_t completed, size_t total) cmStrCat(" (run ", this->RunNumber, '/', this->RunCount, ')'); } if (!this->CTest->GetTestProgressOutput()) { - cmCTestLog( - this->CTest, HANDLER_OUTPUT, - std::setw(2 * getNumWidth(total) + 8) - << "Start " << std::setw(getNumWidth(this->TestHandler->GetMaxIndex())) - << this->TestProperties->Index << ": " << this->TestProperties->Name - << runIterationSuffix << std::endl); + cmCTestLog(this->CTest, HANDLER_OUTPUT, + cmPadToWidth(2 * getNumWidth(total) + 8, "Start "), + cmPadToWidth(getNumWidth(this->TestHandler->GetMaxIndex()), + std::to_string(this->TestProperties->Index)), + ": ", this->TestProperties->Name, runIterationSuffix, '\n'); } else { std::string testName = cmStrCat(this->GetTestPrefix(completed, total), this->TestProperties->Name, '\n'); @@ -595,7 +575,7 @@ bool cmCTestRunTest::StartTest(size_t completed, size_t total) if (this->TestProperties->Error) { std::string const& msg = *this->TestProperties->Error; *this->TestHandler->LogFile << msg << std::endl; - cmCTestLog(this->CTest, HANDLER_OUTPUT, msg << std::endl); + cmCTestLog(this->CTest, HANDLER_OUTPUT, msg, '\n'); this->TestResult.CompletionStatus = "Invalid Test Properties"; this->TestResult.Status = cmCTestTestHandler::NOT_RUN; this->TestResult.Output = msg; @@ -627,7 +607,7 @@ bool cmCTestRunTest::StartTest(size_t completed, size_t total) msg = cmStrCat(std::move(msg), ' ', failedDep); } *this->TestHandler->LogFile << msg << std::endl; - cmCTestLog(this->CTest, HANDLER_OUTPUT, msg << std::endl); + cmCTestLog(this->CTest, HANDLER_OUTPUT, msg, '\n'); this->TestResult.Output = msg; this->TestResult.FullCommandLine.clear(); this->TestResult.Environment.clear(); @@ -648,7 +628,7 @@ bool cmCTestRunTest::StartTest(size_t completed, size_t total) this->CTest->GetConfigType(), "\"."); } *this->TestHandler->LogFile << msg << std::endl; - cmCTestLog(this->CTest, ERROR_MESSAGE, msg << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, msg, '\n'); this->TestResult.Output = msg; this->TestResult.FullCommandLine.clear(); this->TestResult.Environment.clear(); @@ -664,7 +644,7 @@ bool cmCTestRunTest::StartTest(size_t completed, size_t total) *this->TestHandler->LogFile << "Unable to find required file: " << file << std::endl; cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unable to find required file: " << file << std::endl); + "Unable to find required file: ", file, '\n'); this->TestResult.Output = "Unable to find required file: " + file; this->TestResult.FullCommandLine.clear(); this->TestResult.Environment.clear(); @@ -680,7 +660,7 @@ bool cmCTestRunTest::StartTest(size_t completed, size_t total) *this->TestHandler->LogFile << "Unable to find executable: " << args[1] << std::endl; cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unable to find executable: " << args[1] << std::endl); + "Unable to find executable: ", args[1], '\n'); this->TestResult.Output = "Unable to find executable: " + args[1]; this->TestResult.FullCommandLine.clear(); this->TestResult.Environment.clear(); @@ -761,40 +741,33 @@ void cmCTestRunTest::ComputeArguments() this->TestResult.FullCommandLine = testCommand; // Print the test command in verbose mode - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - std::endl - << this->Index << ": " - << (this->TestHandler->MemCheck ? "MemCheck" : "Test") - << " command: " << testCommand << std::endl); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, '\n', this->Index, ": ", + (this->TestHandler->MemCheck ? "MemCheck" : "Test"), + " command: ", testCommand, '\n'); // 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); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index, ": ", + "Working Directory: ", this->TestProperties->Directory, '\n'); } // Print any test-specific env vars in verbose mode if (!this->TestProperties->Environment.empty()) { - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->Index << ": " - << "Environment variables: " << std::endl); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index, ": ", + "Environment variables: \n"); } for (std::string const& env : this->TestProperties->Environment) { - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->Index << ": " << env << std::endl); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index, ": ", env, + '\n'); } if (!this->TestProperties->EnvironmentModification.empty()) { - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->Index << ": " - << "Environment variable modifications: " - << std::endl); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index, ": ", + "Environment variable modifications: \n"); } for (std::string const& envmod : this->TestProperties->EnvironmentModification) { - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->Index << ": " << envmod << std::endl); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index, ": ", envmod, + '\n'); } } @@ -889,19 +862,15 @@ bool cmCTestRunTest::ForkProcess() if (timeout) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->Index << ": " - << "Test timeout computed to be: " - << cmDurationTo(*timeout) - << "\n", - this->TestHandler->GetQuiet()); + this->TestHandler->GetQuiet(), this->Index, ": ", + "Test timeout computed to be: ", + cmDurationTo(*timeout), '\n'); this->TestProcess->SetTimeout(*timeout); } else { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->Index - << ": " - << "Test timeout suppressed by TIMEOUT property.\n", - this->TestHandler->GetQuiet()); + this->TestHandler->GetQuiet(), this->Index, ": ", + "Test timeout suppressed by TIMEOUT property.\n"); } // Record the original environment before modifying it @@ -931,10 +900,9 @@ bool cmCTestRunTest::ForkProcess() std::string profRawPath = this->GenerateLLVMPath("_%p.profraw"); cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - this->Index - << ": Using environment variable LLVM_PROFILE_FILE="_s - << profRawPath << " \n", - this->TestHandler->GetQuiet()); + this->TestHandler->GetQuiet(), this->Index, + ": Using environment variable LLVM_PROFILE_FILE="_s, + profRawPath, " \n"); env.PutEnv(cmStrCat("LLVM_PROFILE_FILE="_s, profRawPath)); // ProcessID -> * to allow for glob to find all // files generated by the test @@ -1000,8 +968,6 @@ void cmCTestRunTest::SetupResourcesEnvironment(cmEnvironment& env) void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total) { - std::ostringstream outputStream; - // Print "completed/total" on the run whose result is the one recorded for // the test, and blanks on its other runs. Which run that is has to be // decided before the run finishes: with until-fail it is the last run, and @@ -1020,34 +986,32 @@ void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total) countThisRun = this->RunNumber == 1; break; } + int const numWidth = getNumWidth(total); + std::string countField; if (countThisRun || this->CTest->GetTestProgressOutput()) { - outputStream << std::setw(getNumWidth(total)) << completed << "/"; - outputStream << std::setw(getNumWidth(total)) << total << " "; + countField = + cmStrCat(cmPadToWidth(numWidth, std::to_string(completed)), '/', + cmPadToWidth(numWidth, std::to_string(total)), ' '); } // if this is one of several runs of a test just print blank space // to keep things neat else { - outputStream << std::setw(getNumWidth(total)) << " "; - outputStream << std::setw(getNumWidth(total)) << " "; + countField = + cmStrCat(cmPadToWidth(numWidth, " "), cmPadToWidth(numWidth, " ")); } - if (this->TestHandler->MemCheck) { - outputStream << "MemCheck"; - } else { - outputStream << "Test"; - } - - std::ostringstream indexStr; - indexStr << " #" << this->Index << ":"; - outputStream << std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex())) - << indexStr.str(); - outputStream << " "; + std::string indexStr = cmStrCat(" #", this->Index, ':'); + std::string output = cmStrCat( + std::move(countField), (this->TestHandler->MemCheck ? "MemCheck" : "Test"), + cmPadToWidth(3 + getNumWidth(this->TestHandler->GetMaxIndex()), + std::move(indexStr)), + ' '); std::string outname = this->TestProperties->Name + " "; size_t const maxTestNameWidth = std::max(this->CTest->GetMaxTestNameWidth(), outname.size() - 1); outname.resize(maxTestNameWidth + 4, '.'); - outputStream << outname; + output += outname; *this->TestHandler->LogFile << this->TestProperties->Index << "/" << this->TestHandler->TotalNumberOfTests @@ -1076,11 +1040,11 @@ void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total) << std::endl; if (!this->CTest->GetTestProgressOutput()) { - cmCTestLog(this->CTest, HANDLER_OUTPUT, outputStream.str()); + cmCTestLog(this->CTest, HANDLER_OUTPUT, output); } - cmCTestLog(this->CTest, DEBUG, - "Testing " << this->TestProperties->Name << " ... "); + cmCTestLog(this->CTest, DEBUG, "Testing ", this->TestProperties->Name, + " ... "); } std::string cmCTestRunTest::GenerateLLVMPath(std::string fileString) @@ -1106,16 +1070,15 @@ void cmCTestRunTest::CollectLLVMCoverage() std::vector profRawFiles; std::string profRawPath = this->GenerateLLVMPath("_*.profraw"); cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " looking for .profraw files in: " << profRawPath - << std::endl, - this->TestHandler->Quiet); + this->TestHandler->Quiet, + " looking for .profraw files in: ", profRawPath, '\n'); gl.FindFiles(profRawPath); // Keep a list of all profraw files profRawFiles = gl.GetFiles(); if (profRawFiles.empty()) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Cannot find any profraw coverage files." << std::endl, - this->TestHandler->Quiet); + this->TestHandler->Quiet, + " Cannot find any profraw coverage files.\n"); // No coverage files is a valid thing, so the exit code is 0 return; } diff --git a/Source/CTest/cmCTestSVN.cxx b/Source/CTest/cmCTestSVN.cxx index 593cd4b665..b9ff93daaa 100644 --- a/Source/CTest/cmCTestSVN.cxx +++ b/Source/CTest/cmCTestSVN.cxx @@ -110,9 +110,8 @@ bool cmCTestSVN::NoteOldRevision() this->Log << "Revision for repository '" << svninfo.LocalPath << "' before update: " << svninfo.OldRevision << "\n"; cmCTestLog(this->CTest, HANDLER_OUTPUT, - " Old revision of external repository '" - << svninfo.LocalPath << "' is: " << svninfo.OldRevision - << "\n"); + " Old revision of external repository '", svninfo.LocalPath, + "' is: ", svninfo.OldRevision, '\n'); } // Set the global old revision to the one of the root @@ -132,9 +131,8 @@ bool cmCTestSVN::NoteNewRevision() this->Log << "Revision for repository '" << svninfo.LocalPath << "' after update: " << svninfo.NewRevision << "\n"; cmCTestLog(this->CTest, HANDLER_OUTPUT, - " New revision of external repository '" - << svninfo.LocalPath << "' is: " << svninfo.NewRevision - << "\n"); + " New revision of external repository '", svninfo.LocalPath, + "' is: ", svninfo.NewRevision, '\n'); // svninfo.Root = ""; // uncomment to test GuessBase this->Log << "Repository '" << svninfo.LocalPath diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index 278d749155..387390b7ab 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -82,8 +82,8 @@ int cmCTestScriptHandler::ExecuteScript(std::string const& total_script_arg) argv.push_back(total_script_arg); cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Executable for CTest is: " << cmSystemTools::GetCTestCommand() - << "\n"); + "Executable for CTest is: ", cmSystemTools::GetCTestCommand(), + '\n'); // now pass through all the other arguments std::vector& initArgs = @@ -112,12 +112,11 @@ int cmCTestScriptHandler::ExecuteScript(std::string const& total_script_arg) while ((pipe = cmSystemTools::WaitForLine( &process.GetLoop(), process.OutputStream(), process.ErrorStream(), line, out, err)) != cmSystemTools::WaitForLineResult::None) { - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Output: " << line << "\n"); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Output: ", line, '\n'); if (pipe == cmSystemTools::WaitForLineResult::STDERR) { - cmCTestLog(this->CTest, ERROR_MESSAGE, line << "\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, line, '\n'); } else if (pipe == cmSystemTools::WaitForLineResult::STDOUT) { - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, line << "\n"); + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, line, '\n'); } } @@ -133,14 +132,14 @@ int cmCTestScriptHandler::ExecuteScript(std::string const& total_script_arg) break; case cmUVProcessChain::ExceptionCode::Spawn: cmCTestLog(this->CTest, ERROR_MESSAGE, - "\tError executing ctest: " << result.second << std::endl); + "\tError executing ctest: ", result.second, '\n'); failed = true; break; default: retVal = status.TermSignal; cmCTestLog(this->CTest, ERROR_MESSAGE, - "\tThere was an exception: " << result.second << " " << retVal - << std::endl); + "\tThere was an exception: ", result.second, ' ', retVal, + '\n'); failed = true; } if (failed) { @@ -150,7 +149,7 @@ int cmCTestScriptHandler::ExecuteScript(std::string const& total_script_arg) for (std::string const& arg : argv) { message << arg << " "; } - cmCTestLog(this->CTest, ERROR_MESSAGE, message.str() << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, message.str(), '\n'); return -1; } return retVal; @@ -179,7 +178,7 @@ void cmCTestScriptHandler::CreateCMake() this->CMake->SetProgressCallback( [this](std::string const& m, float /*unused*/) { if (!m.empty()) { - cmCTestLog(this->CTest, HANDLER_OUTPUT, "-- " << m << std::endl); + cmCTestLog(this->CTest, HANDLER_OUTPUT, "-- ", m, '\n'); } }); @@ -269,8 +268,7 @@ int cmCTestScriptHandler::ReadInScript(std::string const& total_script_arg) this->Makefile->GetModulesFile("CTestScriptMode.cmake"); if (!this->Makefile->ReadListFile(systemFile) || cmSystemTools::GetErrorOccurredFlag()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Error in read:" << systemFile << "\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Error in read:", systemFile, '\n'); return -1; } @@ -310,11 +308,11 @@ int cmCTestScriptHandler::RunConfigurationScript( // read in the script if (pscope) { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Reading Script: " << total_script_arg << std::endl); + "Reading Script: ", total_script_arg, '\n'); result = this->ReadInScript(total_script_arg); } else { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Executing Script: " << total_script_arg << std::endl); + "Executing Script: ", total_script_arg, '\n'); result = this->ExecuteScript(total_script_arg); } diff --git a/Source/CTest/cmCTestStartCommand.cxx b/Source/CTest/cmCTestStartCommand.cxx index e46b4bfc42..c5405895b4 100644 --- a/Source/CTest/cmCTestStartCommand.cxx +++ b/Source/CTest/cmCTestStartCommand.cxx @@ -96,25 +96,28 @@ bool cmCTestStartCommand::InitialPass(std::vector const& args, this->CTest->SetCTestConfiguration("BuildDirectory", binaryDir, quiet); if (smodel) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - "Run dashboard with model " - << smodel << std::endl - << " Source directory: " << *src_dir << std::endl - << " Build directory: " << *bld_dir << std::endl, - quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, quiet, + "Run dashboard with model ", smodel, + "\n" + " Source directory: ", + *src_dir, + "\n" + " Build directory: ", + *bld_dir, '\n'); } else { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, quiet, "Run dashboard with " - "to-be-determined model" - << std::endl - << " Source directory: " << *src_dir << std::endl - << " Build directory: " << *bld_dir << std::endl, - quiet); + "to-be-determined model\n" + " Source directory: ", + *src_dir, + "\n" + " Build directory: ", + *bld_dir, '\n'); } char const* group = this->CTest->GetSpecificGroup(); if (group) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Group: " << group << std::endl, quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, quiet, " Group: ", group, + '\n'); } // Log startup actions. @@ -122,7 +125,7 @@ bool cmCTestStartCommand::InitialPass(std::vector const& args, cmGeneratedFileStream ofs(startLogFile); if (!ofs) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot create log file: LastStart.log" << std::endl); + "Cannot create log file: LastStart.log\n"); return false; } @@ -164,9 +167,8 @@ bool cmCTestStartCommand::InitialPass(std::vector const& args, } if (!fname.empty()) { - cmCTestOptionalLog( - this->CTest, OUTPUT, - " Reading ctest configuration file: " << fname << std::endl, quiet); + cmCTestOptionalLog(this->CTest, OUTPUT, quiet, + " Reading ctest configuration file: ", fname, '\n'); bool readit = mf.ReadDependentFile(fname); if (!readit) { std::string m = cmStrCat("Could not find include file: ", fname); @@ -185,22 +187,18 @@ bool cmCTestStartCommand::InitialPass(std::vector const& args, this->CTest->Initialize(binaryDir); cmCTestOptionalLog( - this->CTest, OUTPUT, - " Site: " << this->CTest->GetCTestConfiguration("Site") << std::endl - << " Build name: " - << cmCTest::SafeBuildIdField( - this->CTest->GetCTestConfiguration("BuildName")) - << std::endl, - quiet); + this->CTest, OUTPUT, quiet, + " Site: ", this->CTest->GetCTestConfiguration("Site"), '\n', + " Build name: ", + cmCTest::SafeBuildIdField(this->CTest->GetCTestConfiguration("BuildName")), + '\n'); if (this->CTest->GetTestModel() == cmCTest::NIGHTLY && this->CTest->GetCTestConfiguration("NightlyStartTime").empty()) { cmCTestOptionalLog( - this->CTest, WARNING, + this->CTest, WARNING, quiet, "WARNING: No nightly start time found please set in CTestConfig.cmake" - " or DartConfig.cmake" - << std::endl, - quiet); + " or DartConfig.cmake\n"); return false; } @@ -216,10 +214,9 @@ bool cmCTestStartCommand::InitialPass(std::vector const& args, } } - cmCTestOptionalLog(this->CTest, OUTPUT, - " Use " << this->CTest->GetTestGroupString() << " tag: " - << this->CTest->GetCurrentTag() << std::endl, - quiet); + cmCTestOptionalLog(this->CTest, OUTPUT, quiet, " Use ", + this->CTest->GetTestGroupString(), + " tag: ", this->CTest->GetCurrentTag(), '\n'); return true; } diff --git a/Source/CTest/cmCTestSubmitCommand.cxx b/Source/CTest/cmCTestSubmitCommand.cxx index 24f5d87628..57973e1a94 100644 --- a/Source/CTest/cmCTestSubmitCommand.cxx +++ b/Source/CTest/cmCTestSubmitCommand.cxx @@ -50,19 +50,17 @@ std::unique_ptr cmCTestSubmitCommand::InitializeHandler( &mf, "TLSVersion", "CTEST_TLS_VERSION", args.Quiet)) { if (cmValue tlsVersionVar = mf.GetDefinition("CMAKE_TLS_VERSION")) { cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - "SetCTestConfiguration from CMAKE_TLS_VERSION:TLSVersion:" - << *tlsVersionVar << std::endl, - args.Quiet); + this->CTest, HANDLER_VERBOSE_OUTPUT, args.Quiet, + "SetCTestConfiguration from CMAKE_TLS_VERSION:TLSVersion:", + *tlsVersionVar, '\n'); this->CTest->SetCTestConfiguration("TLSVersion", *tlsVersionVar, args.Quiet); } else if (cm::optional tlsVersionEnv = cmSystemTools::GetEnvVar("CMAKE_TLS_VERSION")) { cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - "SetCTestConfiguration from ENV{CMAKE_TLS_VERSION}:TLSVersion:" - << *tlsVersionEnv << std::endl, - args.Quiet); + this->CTest, HANDLER_VERBOSE_OUTPUT, args.Quiet, + "SetCTestConfiguration from ENV{CMAKE_TLS_VERSION}:TLSVersion:", + *tlsVersionEnv, '\n'); this->CTest->SetCTestConfiguration("TLSVersion", *tlsVersionEnv, args.Quiet); } @@ -71,19 +69,17 @@ std::unique_ptr cmCTestSubmitCommand::InitializeHandler( &mf, "TLSVerify", "CTEST_TLS_VERIFY", args.Quiet)) { if (cmValue tlsVerifyVar = mf.GetDefinition("CMAKE_TLS_VERIFY")) { cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - "SetCTestConfiguration from CMAKE_TLS_VERIFY:TLSVerify:" - << *tlsVerifyVar << std::endl, - args.Quiet); + this->CTest, HANDLER_VERBOSE_OUTPUT, args.Quiet, + "SetCTestConfiguration from CMAKE_TLS_VERIFY:TLSVerify:", + *tlsVerifyVar, '\n'); this->CTest->SetCTestConfiguration("TLSVerify", *tlsVerifyVar, args.Quiet); } else if (cm::optional tlsVerifyEnv = cmSystemTools::GetEnvVar("CMAKE_TLS_VERIFY")) { cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - "SetCTestConfiguration from ENV{CMAKE_TLS_VERIFY}:TLSVerify:" - << *tlsVerifyEnv << std::endl, - args.Quiet); + this->CTest, HANDLER_VERBOSE_OUTPUT, args.Quiet, + "SetCTestConfiguration from ENV{CMAKE_TLS_VERIFY}:TLSVerify:", + *tlsVerifyEnv, '\n'); this->CTest->SetCTestConfiguration("TLSVerify", *tlsVerifyEnv, args.Quiet); } diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index 38624a61aa..1599a1f56e 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -142,9 +141,8 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( // Add any additional headers that the user specified. for (std::string const& h : this->HttpHeaders) { - cmCTestOptionalLog(this->CTest, DEBUG, - " Add HTTP Header: \"" << h << "\"" << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, + " Add HTTP Header: \"", h, "\"\n"); headers = ::curl_slist_append(headers, h.c_str()); } @@ -159,26 +157,22 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( if (curlOpts.TLSVersionOpt.has_value()) { cm::optional tlsVersionStr = cmCurlPrintTLSVersion(*curlOpts.TLSVersionOpt); - cmCTestOptionalLog( - this->CTest, HANDLER_VERBOSE_OUTPUT, - " Set CURLOPT_SSLVERSION to " - << (tlsVersionStr ? *tlsVersionStr : "unknown value") << "\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Set CURLOPT_SSLVERSION to ", + (tlsVersionStr ? *tlsVersionStr : "unknown value"), + "\n"); curl_easy_setopt(curl, CURLOPT_SSLVERSION, *curlOpts.TLSVersionOpt); } if (curlOpts.TLSVerifyOpt.has_value()) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Set CURLOPT_SSL_VERIFYPEER to " - << (*curlOpts.TLSVerifyOpt ? "on" : "off") - << "\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Set CURLOPT_SSL_VERIFYPEER to ", + (*curlOpts.TLSVerifyOpt ? "on" : "off"), "\n"); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, *curlOpts.TLSVerifyOpt ? 1 : 0); } if (curlOpts.VerifyHostOff) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Set CURLOPT_SSL_VERIFYHOST to off\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Set CURLOPT_SSL_VERIFYHOST to off\n"); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); } @@ -284,7 +278,7 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( if (!cmSystemTools::FileExists(local_file)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - " Cannot find file: " << local_file << std::endl); + " Cannot find file: ", local_file, '\n'); ::curl_easy_cleanup(curl); ::curl_slist_free_all(headers); ::curl_global_cleanup(); @@ -293,11 +287,9 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( unsigned long filelen = cmSystemTools::FileLength(local_file); ftpfile = cmsys::SystemTools::Fopen(local_file, "rb"); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - " Upload file: " << local_file << " to " - << upload_as << " Size: " - << filelen << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + " Upload file: ", local_file, " to ", upload_as, + " Size: ", filelen, '\n'); // specify target ::curl_easy_setopt(curl, CURLOPT_URL, upload_as.c_str()); @@ -334,20 +326,14 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( ::curl_easy_perform(curl); if (!chunk.empty()) { - cmCTestOptionalLog(this->CTest, DEBUG, - "CURL output: [" - << cm::string_view(chunk.data(), chunk.size()) - << "]" << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, "CURL output: [", + cm::string_view(chunk.data(), chunk.size()), "]\n"); this->ParseResponse(chunk); } if (!chunkDebug.empty()) { cmCTestOptionalLog( - this->CTest, DEBUG, - "CURL debug output: [" - << cm::string_view(chunkDebug.data(), chunkDebug.size()) << "]" - << std::endl, - this->Quiet); + this->CTest, DEBUG, this->Quiet, "CURL debug output: [", + cm::string_view(chunkDebug.data(), chunkDebug.size()), "]\n"); } // If curl failed for any reason, or checksum fails, wait and retry @@ -371,20 +357,18 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( : atoi(retryCount.c_str()); for (int i = 0; i < count; i++) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Submit failed, waiting " << delay.count() - << " seconds...\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " Submit failed, waiting ", delay.count(), + " seconds...\n"); auto stop = std::chrono::steady_clock::now() + delay; while (std::chrono::steady_clock::now() < stop) { cmSystemTools::Delay(100); } - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Retry submission: Attempt " - << (i + 1) << " of " << count << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " Retry submission: Attempt ", (i + 1), " of ", + count, '\n'); ::fclose(ftpfile); ftpfile = cmsys::SystemTools::Fopen(local_file, "rb"); @@ -397,11 +381,9 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( ::curl_easy_perform(curl); if (!chunk.empty()) { - cmCTestOptionalLog(this->CTest, DEBUG, - "CURL output: [" - << cm::string_view(chunk.data(), chunk.size()) - << "]" << std::endl, - this->Quiet); + cmCTestOptionalLog( + this->CTest, DEBUG, this->Quiet, "CURL output: [", + cm::string_view(chunk.data(), chunk.size()), "]\n"); this->ParseResponse(chunk); } @@ -416,10 +398,9 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( fclose(ftpfile); if (!successful_submission) { cmCTestLog(this->CTest, ERROR_MESSAGE, - " Error when uploading file: " << local_file - << std::endl); + " Error when uploading file: ", local_file, '\n'); cmCTestLog(this->CTest, ERROR_MESSAGE, - " Error message was: " << error_buffer << std::endl); + " Error message was: ", error_buffer, '\n'); *this->LogFile << " Error when uploading file: " << local_file << std::endl << " Error message was: " << error_buffer @@ -429,10 +410,8 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( *this->LogFile << " Curl output was: " << cm::string_view(chunk.data(), chunk.size()) << std::endl; - cmCTestLog(this->CTest, ERROR_MESSAGE, - "CURL output: [" - << cm::string_view(chunk.data(), chunk.size()) << "]" - << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "CURL output: [", + cm::string_view(chunk.data(), chunk.size()), "]\n"); } ::curl_easy_cleanup(curl); ::curl_slist_free_all(headers); @@ -441,9 +420,8 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP( } // always cleanup ::curl_easy_cleanup(curl); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Uploaded: " + local_file << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " Uploaded: ", local_file, '\n'); } } ::curl_slist_free_all(headers); @@ -463,7 +441,7 @@ void cmCTestSubmitHandler::ParseResponse(std::vector chunk) if (parser.Status != ResponseParser::STATUS_OK) { this->HasErrors = true; cmCTestLog(this->CTest, HANDLER_OUTPUT, - " Submission failed: " << parser.Message << std::endl); + " Submission failed: ", parser.Message, '\n'); return; } this->CTest->SetBuildID(parser.BuildID); @@ -477,9 +455,8 @@ void cmCTestSubmitHandler::ParseResponse(std::vector chunk) } if (this->HasWarnings || this->HasErrors) { - cmCTestLog(this->CTest, HANDLER_OUTPUT, - " Server Response:\n" - << cm::string_view(chunk.data(), chunk.size()) << "\n"); + cmCTestLog(this->CTest, HANDLER_OUTPUT, " Server Response:\n", + cm::string_view(chunk.data(), chunk.size()), '\n'); } } @@ -487,8 +464,8 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file, std::string const& typeString) { if (!cmSystemTools::FileExists(file)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Upload file not found: '" << file << "'\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Upload file not found: '", file, + "'\n"); return -1; } cmCTestCurl curl(this->CTest); @@ -522,8 +499,7 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file, unsigned long retryDelayValue = 0; if (!cmStrToULong(retryDelayString, &retryDelayValue)) { cmCTestLog(this->CTest, WARNING, - "Invalid value for 'RETRY_DELAY' : " << retryDelayString - << std::endl); + "Invalid value for 'RETRY_DELAY' : ", retryDelayString, '\n'); } else { retryDelay = std::chrono::seconds(retryDelayValue); } @@ -532,8 +508,7 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file, if (!retryCountString.empty()) { if (!cmStrToULong(retryCountString, &retryCount)) { cmCTestLog(this->CTest, WARNING, - "Invalid value for 'RETRY_DELAY' : " << retryCountString - << std::endl); + "Invalid value for 'RETRY_DELAY' : ", retryCountString, '\n'); } } @@ -573,30 +548,26 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file, fields += '&'; } fields += str.str(); - cmCTestOptionalLog(this->CTest, DEBUG, - "fields: " << fields << "\nurl:" << url - << "\nfile: " << file << "\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, "fields: ", fields, + "\nurl:", url, "\nfile: ", file, '\n'); std::string response; bool requestSucceeded = curl.HttpRequest(url, fields, response); if (!internalTest && !requestSucceeded) { // If request failed, wait and retry. for (unsigned long i = 0; i < retryCount; i++) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Request failed, waiting " << retryDelay.count() - << " seconds...\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " Request failed, waiting ", retryDelay.count(), + " seconds...\n"); auto stop = std::chrono::steady_clock::now() + retryDelay; while (std::chrono::steady_clock::now() < stop) { cmSystemTools::Delay(100); } - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Retry request: Attempt " - << (i + 1) << " of " << retryCount << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " Retry request: Attempt ", (i + 1), " of ", + retryCount, '\n'); requestSucceeded = curl.HttpRequest(url, fields, response); if (requestSucceeded) { @@ -605,42 +576,36 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file, } } if (!internalTest && !requestSucceeded) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Error in HttpRequest\n" - << response); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Error in HttpRequest\n", response); return -1; } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Request upload response: [" << response << "]\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Request upload response: [", response, "]\n"); Json::Value json; std::istringstream iss(response); cmJSONState parseState(response, &json, cmJSONState::StrictMode::Relaxed); if (!internalTest && !parseState.errors.empty()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "error parsing json string [" << response << "]\n" - << parseState.GetErrorMessage() - << "\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, "error parsing json string [", + response, "]\n", parseState.GetErrorMessage(), '\n'); return -1; } if (!internalTest && json["status"].asInt() != 0) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Bad status returned from CDash: " << json["status"].asInt()); + "Bad status returned from CDash: ", json["status"].asInt()); return -1; } if (!internalTest) { if (json["datafilesmd5"].isArray()) { int datares = json["datafilesmd5"][0].asInt(); if (datares == 1) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "File already exists on CDash, skip upload " - << file << "\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "File already exists on CDash, skip upload ", file, + '\n'); return 0; } } else { cmCTestLog(this->CTest, ERROR_MESSAGE, - "bad datafilesmd5 value in response " << response << "\n"); + "bad datafilesmd5 value in response ", response, '\n'); return -1; } } @@ -660,20 +625,18 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file, if (!uploadSucceeded) { // If upload failed, wait and retry. for (unsigned long i = 0; i < retryCount; i++) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Upload failed, waiting " << retryDelay.count() - << " seconds...\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " Upload failed, waiting ", retryDelay.count(), + " seconds...\n"); auto stop = std::chrono::steady_clock::now() + retryDelay; while (std::chrono::steady_clock::now() < stop) { cmSystemTools::Delay(100); } - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Retry upload: Attempt " - << (i + 1) << " of " << retryCount << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " Retry upload: Attempt ", (i + 1), " of ", + retryCount, '\n'); if (!internalTest) { uploadSucceeded = curl.UploadFile(file, url, fstr.str(), response); @@ -685,22 +648,18 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file, } if (!uploadSucceeded) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "error uploading to CDash. " << file << " " << url << " " - << fstr.str()); + cmCTestLog(this->CTest, ERROR_MESSAGE, "error uploading to CDash. ", file, + " ", url, " ", fstr.str()); return -1; } parseState = cmJSONState(response, &json, cmJSONState::StrictMode::Relaxed); if (!parseState.errors.empty()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "error parsing json string [" << response << "]\n" - << parseState.GetErrorMessage() - << "\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, "error parsing json string [", + response, "]\n", parseState.GetErrorMessage(), "\n"); return -1; } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Upload file response: [" << response << "]\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Upload file response: [", response, "]\n"); return 0; } @@ -714,9 +673,9 @@ int cmCTestSubmitHandler::ProcessHandler() std::string const& buildDirectory = this->CTest->GetCTestConfiguration("BuildDirectory"); if (buildDirectory.empty()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot find BuildDirectory key in the DartConfiguration.tcl" - << std::endl); + cmCTestLog( + this->CTest, ERROR_MESSAGE, + "Cannot find BuildDirectory key in the DartConfiguration.tcl\n"); return -1; } @@ -751,9 +710,8 @@ int cmCTestSubmitHandler::ProcessHandler() } if (!this->HTTPProxy.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Use HTTP Proxy: " << this->HTTPProxy << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " Use HTTP Proxy: ", this->HTTPProxy, '\n'); } std::vector files; @@ -780,17 +738,17 @@ int cmCTestSubmitHandler::ProcessHandler() cmStrCat(buildDirectory, "/Testing/", this->CTest->GetCurrentTag()); std::string::size_type glen = gpath.size() + 1; gpath += "/CoverageLog*"; - cmCTestOptionalLog(this->CTest, DEBUG, - "Globbing for: " << gpath << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, + "Globbing for: ", gpath, '\n'); if (cmSystemTools::SimpleGlob(gpath, gfiles, 1)) { for (std::string& gfile : gfiles) { gfile = gfile.substr(glen); - cmCTestOptionalLog(this->CTest, DEBUG, - "Glob file: " << gfile << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, + "Glob file: ", gfile, '\n'); this->CTest->AddSubmitFile(cmCTest::PartCoverage, gfile); } } else { - cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem globbing" << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem globbing\n"); } } this->CTest->AddIfExists(cmCTest::PartMemCheck, "DynamicAnalysis.xml"); @@ -833,19 +791,18 @@ int cmCTestSubmitHandler::ProcessHandler() cnt++; } } - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Submit files\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + "Submit files\n"); char const* specificGroup = this->CTest->GetSpecificGroup(); if (specificGroup) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Send to group: " << specificGroup << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " Send to group: ", specificGroup, '\n'); } this->LogFile = &ofs; std::string url = this->CTest->GetSubmitURL(); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " SubmitURL: " << url << '\n', this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " SubmitURL: ", url, '\n'); if (!this->SubmitUsingHTTP( cmStrCat(buildDirectory, "/Testing/", this->CTest->GetCurrentTag()), files, prefix, url)) { @@ -859,11 +816,9 @@ int cmCTestSubmitHandler::ProcessHandler() " Errors occurred during submission.\n"); ofs << " Errors occurred during submission.\n"; } else { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Submission successful" - << (this->HasWarnings ? ", with warnings." : "") - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + " Submission successful", + (this->HasWarnings ? ", with warnings." : ""), '\n'); ofs << " Submission successful" << (this->HasWarnings ? ", with warnings." : "") << std::endl; } @@ -900,10 +855,9 @@ int cmCTestSubmitHandler::GetSubmitInactivityTimeout() submitInactivityTimeout = static_cast(timeout); } else { cmCTestLog(this->CTest, ERROR_MESSAGE, - "SubmitInactivityTimeout is invalid: " - << cm::quoted(timeoutStr) << "." - << " Using a default value of " - << SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT << "." << std::endl); + "SubmitInactivityTimeout is invalid: \"", + cmEscapeQuotes(timeoutStr), "\". Using a default value of ", + SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT, ".\n"); } } return submitInactivityTimeout; diff --git a/Source/CTest/cmCTestTestCommand.cxx b/Source/CTest/cmCTestTestCommand.cxx index cfee6c1bfa..767f5fc795 100644 --- a/Source/CTest/cmCTestTestCommand.cxx +++ b/Source/CTest/cmCTestTestCommand.cxx @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -73,9 +72,8 @@ cmCTestTestCommand::ResolveTestPreset(cmMakefile& mf, if (presetCheck == PresetCheckResult::Found) { resolved.EffectivePreset = *v; } else { - cmCTestLog(this->CTest, WARNING, - "No test preset named \"" - << *v << "\" found, ignoring CTEST_PRESET." << std::endl); + cmCTestLog(this->CTest, WARNING, "No test preset named \"", *v, + "\" found, ignoring CTEST_PRESET.\n"); } } } @@ -285,15 +283,14 @@ std::unique_ptr cmCTestTestCommand::InitializeHandler( if (!cmStrToULong(args.TestLoad, &testLoad)) { testLoad = 0; cmCTestLog(this->CTest, WARNING, - "Invalid value for 'TEST_LOAD' : " << args.TestLoad - << std::endl); + "Invalid value for 'TEST_LOAD' : ", args.TestLoad, '\n'); } } else if (cmNonempty(ctestTestLoad)) { if (!cmStrToULong(*ctestTestLoad, &testLoad)) { testLoad = 0; cmCTestLog(this->CTest, WARNING, - "Invalid value for 'CTEST_TEST_LOAD' : " << *ctestTestLoad - << std::endl); + "Invalid value for 'CTEST_TEST_LOAD' : ", *ctestTestLoad, + '\n'); } } else { testLoad = this->CTest->GetTestLoad(); diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index fbeacd063b..225bd141c2 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -444,8 +444,8 @@ void cmCTestTestHandler::PopulateCustomVectors(cmMakefile* mf) if (dval) { if (!SetTruncationMode(this->TestOptions.OutputTruncation, *dval)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Invalid value for CTEST_CUSTOM_TEST_OUTPUT_TRUNCATION: " - << *dval << std::endl); + "Invalid value for CTEST_CUSTOM_TEST_OUTPUT_TRUNCATION: ", + *dval, '\n'); } } } @@ -454,7 +454,7 @@ int cmCTestTestHandler::PreProcessHandler() { if (!this->ExecuteCommands(this->CustomPreTest)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem executing pre-test command(s)." << std::endl); + "Problem executing pre-test command(s).\n"); return 0; } return 1; @@ -464,7 +464,7 @@ int cmCTestTestHandler::PostProcessHandler() { if (!this->ExecuteCommands(this->CustomPostTest)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem executing post-test command(s)." << std::endl); + "Problem executing post-test command(s).\n"); return 0; } return 1; @@ -478,12 +478,9 @@ int cmCTestTestHandler::ProcessHandler() this->TestResults.clear(); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - (this->MemCheck ? "Memory check" : "Test") - << " project " - << cmSystemTools::GetLogicalWorkingDirectory() - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + (this->MemCheck ? "Memory check" : "Test"), " project ", + cmSystemTools::GetLogicalWorkingDirectory(), '\n'); if (!this->CTest->GetShowOnly() && !this->PreProcessHandler()) { return -1; } @@ -508,8 +505,7 @@ int cmCTestTestHandler::ProcessHandler() if (passed.size() + failed.size() == 0) { if (!this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels() && this->CTest->GetNoTestsMode() != cmCTest::NoTests::Ignore) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "No tests were found!!!" << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "No tests were found!!!\n"); if (this->CTest->GetNoTestsMode() == cmCTest::NoTests::Error) { noTestsFoundError = true; } @@ -517,13 +513,11 @@ int cmCTestTestHandler::ProcessHandler() } else { if (this->HandlerVerbose && !passed.empty() && (this->UseIncludeRegExpFlag || this->UseExcludeRegExpFlag)) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - std::endl - << "The following tests passed:" << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "\nThe following tests passed:\n"); for (std::string const& j : passed) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "\t" << j << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + '\t', j, '\n'); } } @@ -615,7 +609,7 @@ bool cmCTestTestHandler::ProcessOptions() } } else { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Repeat option invalid value: " << *repeat << std::endl); + "Repeat option invalid value: ", *repeat, '\n'); return false; } } @@ -628,8 +622,7 @@ bool cmCTestTestHandler::ProcessOptions() unsigned long plevel = 0; if (!cmStrToULong(*parallelLevel, &plevel)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "ParallelLevel invalid value: " << *parallelLevel - << std::endl); + "ParallelLevel invalid value: ", *parallelLevel, '\n'); return false; } this->CTest->SetParallelLevel(plevel); @@ -690,9 +683,8 @@ void cmCTestTestHandler::LogTestSummary(std::vector const& passed, } char realBuf[1024]; snprintf(realBuf, sizeof(realBuf), "%6.2f sec", durationInSecs.count()); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - "\nTotal Test time (real) = " << realBuf << "\n", - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + "\nTotal Test time (real) = ", realBuf, "\n"); } void cmCTestTestHandler::LogDisabledTests( @@ -701,8 +693,7 @@ void cmCTestTestHandler::LogDisabledTests( if (!disabledTests.empty()) { cmGeneratedFileStream ofs; cmCTestLog(this->CTest, HANDLER_OUTPUT, - std::endl - << "The following tests did not run:" << std::endl); + "\nThe following tests did not run:\n"); this->StartLogFile("TestsDisabled", ofs); char const* disabled_reason; @@ -714,10 +705,9 @@ void cmCTestTestHandler::LogDisabledTests( } else { disabled_reason = "Skipped"; } - std::ostringstream msg; - msg << "\t" << std::setw(3) << dt.TestCount << " - " << dt.Name << " (" - << disabled_reason << ")\n"; - cmCTestColorLog(this->CTest, HANDLER_OUTPUT, disabledAttrs, msg.str()); + cmCTestColorLog(this->CTest, HANDLER_OUTPUT, disabledAttrs, '\t', + cmPadToWidth(3, std::to_string(dt.TestCount)), " - ", + dt.Name, " (", disabled_reason, ")\n"); } } } @@ -727,9 +717,7 @@ void cmCTestTestHandler::LogFailedTests(std::vector const& failed, { if (!failed.empty()) { cmGeneratedFileStream ofs; - cmCTestLog(this->CTest, HANDLER_OUTPUT, - std::endl - << "The following tests FAILED:" << std::endl); + cmCTestLog(this->CTest, HANDLER_OUTPUT, "\nThe following tests FAILED:\n"); this->StartLogFile("TestsFailed", ofs); for (cmCTestTestResult const& ft : resultsSet) { @@ -752,10 +740,9 @@ void cmCTestTestHandler::LogFailedTests(std::vector const& failed, : maxLen - ft_name_and_status.size(); labels = cmStrCat(std::string(ns, ' '), cmJoin(p.Labels, " ")); } - std::ostringstream msg; - msg << "\t" << std::setw(3) << ft.TestCount << " - " - << ft_name_and_status << labels << "\n"; - cmCTestColorLog(this->CTest, HANDLER_OUTPUT, testAttrs, msg.str()); + cmCTestColorLog(this->CTest, HANDLER_OUTPUT, testAttrs, '\t', + cmPadToWidth(3, std::to_string(ft.TestCount)), " - ", + ft_name_and_status, labels, "\n"); } } } @@ -768,10 +755,8 @@ bool cmCTestTestHandler::GenerateXML() if (!this->StartResultingXML( (this->MemCheck ? cmCTest::PartMemCheck : cmCTest::PartTest), (this->MemCheck ? "DynamicAnalysis" : "Test"), xmlfile)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot create " - << (this->MemCheck ? "memory check" : "testing") - << " XML file" << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create ", + (this->MemCheck ? "memory check" : "testing"), " XML file\n"); this->LogFile = nullptr; return false; } @@ -790,7 +775,7 @@ bool cmCTestTestHandler::GenerateXML() if (!this->StartResultingXML(cmCTest::PartTest, "DynamicAnalysis-Test", xmlfile)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot create testing XML file" << std::endl); + "Cannot create testing XML file\n"); this->LogFile = nullptr; return false; } @@ -851,11 +836,11 @@ void cmCTestTestHandler::PrintLabelOrSubprojectSummary(bool doSubProject) } // now print times if (doSubProject) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - "\nSubproject Time Summary:", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + "\nSubproject Time Summary:"); } else { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - "\nLabel Time Summary:", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, + "\nLabel Time Summary:"); } for (std::string const& i : labels) { std::string label = i; @@ -870,11 +855,8 @@ void cmCTestTestHandler::PrintLabelOrSubprojectSummary(bool doSubProject) labelCountStr << "s"; } labelCountStr << ")"; - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - "\n" - << label << " = " << buf << " " - << labelCountStr.str(), - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, "\n", label, + " = ", buf, ' ', labelCountStr.str()); if (this->LogFile) { *this->LogFile << "\n" << i << " = " << buf << "\n"; } @@ -882,7 +864,7 @@ void cmCTestTestHandler::PrintLabelOrSubprojectSummary(bool doSubProject) if (this->LogFile) { *this->LogFile << "\n"; } - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n", this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, '\n'); } /** @@ -1118,9 +1100,8 @@ void cmCTestTestHandler::ComputeOutOfDateTests() void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Updating test list for fixtures" << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Updating test list for fixtures\n"); // Prepare regular expression evaluators std::string setupRegExp(this->TestOptions.ExcludeFixtureRegularExpression); @@ -1256,11 +1237,10 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const 1 + static_cast(std::distance(this->TestList.begin(), lotIt)); ++fixtureTestsAdded; - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Added setup test " - << p.Name << " required by fixture " - << requiredFixtureName << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Added setup test ", p.Name, + " required by fixture ", requiredFixtureName, + '\n'); } } @@ -1287,11 +1267,10 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const 1 + static_cast(std::distance(this->TestList.begin(), lotIt)); ++fixtureTestsAdded; - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Added cleanup test " - << p.Name << " required by fixture " - << requiredFixtureName << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Added cleanup test ", p.Name, + " required by fixture ", requiredFixtureName, + '\n'); } } } @@ -1343,11 +1322,9 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const } } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Added " << fixtureTestsAdded - << " tests to meet fixture requirements" - << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Added ", fixtureTestsAdded, + " tests to meet fixture requirements\n"); } void cmCTestTestHandler::UpdateMaxTestNameWidth() @@ -1374,9 +1351,8 @@ bool cmCTestTestHandler::GetValue(char const* tag, int& value, fin >> value; ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line } else { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "parse error: missing tag: " << tag << " found [" << line << "]" - << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "parse error: missing tag: ", tag, + " found [", line, "]\n"); ret = false; } return ret; @@ -1392,9 +1368,8 @@ bool cmCTestTestHandler::GetValue(char const* tag, double& value, fin >> value; ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line } else { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "parse error: missing tag: " << tag << " found [" << line << "]" - << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "parse error: missing tag: ", tag, + " found [", line, "]\n"); ret = false; } return ret; @@ -1419,9 +1394,8 @@ bool cmCTestTestHandler::GetValue(char const* tag, bool& value, #endif ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line } else { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "parse error: missing tag: " << tag << " found [" << line << "]" - << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "parse error: missing tag: ", tag, + " found [", line, "]\n"); ret = false; } return ret; @@ -1437,9 +1411,8 @@ bool cmCTestTestHandler::GetValue(char const* tag, size_t& value, fin >> value; ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line } else { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "parse error: missing tag: " << tag << " found [" << line << "]" - << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "parse error: missing tag: ", tag, + " found [", line, "]\n"); ret = false; } return ret; @@ -1454,9 +1427,8 @@ bool cmCTestTestHandler::GetValue(char const* tag, std::string& value, if (line == tag) { ret = cmSystemTools::GetLineFromStream(fin, value); } else { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "parse error: missing tag: " << tag << " found [" << line << "]" - << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "parse error: missing tag: ", tag, + " found [", line, "]\n"); ret = false; } return ret; @@ -1760,14 +1732,14 @@ int cmCTestTestHandler::ExecuteCommands(std::vector& vec) { for (std::string const& it : vec) { int retVal = 0; - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Run command: " << it << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Run command: ", it, '\n'); if (!cmSystemTools::RunSingleCommand(it, nullptr, nullptr, &retVal, nullptr, cmSystemTools::OUTPUT_MERGE /*this->Verbose*/) || retVal != 0) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem running command: " << it << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem running command: ", it, + '\n'); return 0; } } @@ -1902,12 +1874,10 @@ std::string cmCTestTestHandler::FindExecutable( } } if (fullPath.empty()) { - cmCTestLog(ctest, HANDLER_OUTPUT, - "Could not find executable " - << testCommand << "\n" - << "Looked in the following places:\n"); + cmCTestLog(ctest, HANDLER_OUTPUT, "Could not find executable ", + testCommand, "\nLooked in the following places:\n"); for (std::string const& f : failed) { - cmCTestLog(ctest, HANDLER_OUTPUT, f << "\n"); + cmCTestLog(ctest, HANDLER_OUTPUT, f, '\n'); } } @@ -1932,8 +1902,8 @@ bool cmCTestTestHandler::GetListOfTests() this->ExcludeTestsRegularExpression.compile( this->TestOptions.ExcludeRegularExpression); } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Constructing a list of tests" << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Constructing a list of tests\n"); cmake cm(cmState::Role::CTest); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator gg(&cm); @@ -1990,8 +1960,8 @@ bool cmCTestTestHandler::GetListOfTests() auto action = cmCTestTypes::GetResourceErrorAction(*specErrorAction); if (!action) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Invalid value for CTEST_RESOURCE_ERROR_ACTION: " - << *specErrorAction << std::endl); + "Invalid value for CTEST_RESOURCE_ERROR_ACTION: ", + *specErrorAction, '\n'); } else { this->TestOptions.ResourceErrorAction = *action; } @@ -2012,9 +1982,8 @@ bool cmCTestTestHandler::GetListOfTests() } } - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Done constructing a list of tests" << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Done constructing a list of tests\n"); return true; } @@ -2112,8 +2081,8 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed() cmsys::Directory directory; if (!directory.Load(dirName)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Unable to read the contents of " << dirName << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to read the contents of ", + dirName, '\n'); return; } @@ -2144,8 +2113,8 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed() if (!cmSystemTools::FileExists(lastTestsFailedLog)) { if (!this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - lastTestsFailedLog << " does not exist!" << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, lastTestsFailedLog, + " does not exist!\n"); } return; } @@ -2169,10 +2138,8 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed() } else if (!this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels()) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem reading file: " - << lastTestsFailedLog - << " while generating list of previously failed tests." - << std::endl); + "Problem reading file: ", lastTestsFailedLog, + " while generating list of previously failed tests.\n"); } } @@ -2192,9 +2159,8 @@ cm::optional> cmCTestTestHandler::ReadTestListFile( result = std::move(testNames); } else { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem reading test list file: " - << testListFileName - << " while generating list of tests to run." << std::endl); + "Problem reading test list file: ", testListFileName, + " while generating list of tests to run.\n"); } return result; } @@ -2224,9 +2190,8 @@ void cmCTestTestHandler::RecordCustomTestMeasurements(cmXMLWriter& xml, xml.Attribute("text", "text/string"); xml.Element("Value", cmStrCat("File ", filename, " not found")); xml.EndElement(); - cmCTestOptionalLog( - this->CTest, HANDLER_OUTPUT, - "File \"" << filename << "\" not found." << std::endl, this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->Quiet, "File \"", + filename, "\" not found.\n"); } else { long len = cmSystemTools::FileLength(filename); if (len == 0) { @@ -2565,9 +2530,9 @@ bool cmCTestTestHandler::SetTestsProperties( rt.RawProperties[key] = val; rt.ResourceErrorAction = cmCTestTypes::GetResourceErrorAction(val); if (!rt.ResourceErrorAction) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Invalid value for CTEST_RESOURCE_ERROR_ACTION: " - << val << std::endl); + cmCTestLog( + this->CTest, ERROR_MESSAGE, + "Invalid value for CTEST_RESOURCE_ERROR_ACTION: ", val, '\n'); return false; } @@ -2619,8 +2584,8 @@ bool cmCTestTestHandler::SetTestsProperties( cmList propArgs{ val }; if (propArgs.size() != 2) { cmCTestLog(this->CTest, WARNING, - "TIMEOUT_AFTER_MATCH expects two arguments, found " - << propArgs.size() << std::endl); + "TIMEOUT_AFTER_MATCH expects two arguments, found ", + propArgs.size(), '\n'); } else { rt.AlternateTimeout = cmDuration(atof(propArgs[0].c_str())); cmList lval{ propArgs[1] }; @@ -2690,8 +2655,8 @@ bool cmCTestTestHandler::SetDirectoryProperties( bool cmCTestTestHandler::AddTest(std::vector const& args) { std::string const& testname = args[0]; - cmCTestOptionalLog(this->CTest, DEBUG, "Add test: " << args[0] << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, "Add test: ", args[0], + '\n'); if (this->UseExcludeRegExpFlag && this->UseExcludeRegExpFirst && this->ExcludeTestsRegularExpression.find(testname)) { @@ -2699,10 +2664,9 @@ bool cmCTestTestHandler::AddTest(std::vector const& args) } if (cm::contains(this->CustomTestsIgnore, testname)) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Ignore " << (this->MemCheck ? "memcheck" : "test") - << ": " << testname << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Quiet, + "Ignore ", (this->MemCheck ? "memcheck" : "test"), ": ", + testname, '\n'); return true; } @@ -2712,9 +2676,8 @@ bool cmCTestTestHandler::AddTest(std::vector const& args) test.CTestDirectory = cmSystemTools::GetLogicalWorkingDirectory(); test.Directory = test.CTestDirectory; test.RawProperties["WORKING_DIRECTORY"] = test.CTestDirectory; - cmCTestOptionalLog(this->CTest, DEBUG, - "Set test directory: " << test.Directory << std::endl, - this->Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, this->Quiet, + "Set test directory: ", test.Directory, '\n'); if (this->UseIncludeRegExpFlag && (!this->IncludeTestsRegularExpression.find(testname) || @@ -2757,8 +2720,8 @@ bool cmCTestTestHandler::WriteJUnitXML() xmlfile.Open(this->TestOptions.JUnitXMLFileName); if (!xmlfile) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Problem opening file: " << this->TestOptions.JUnitXMLFileName - << std::endl); + "Problem opening file: ", this->TestOptions.JUnitXMLFileName, + '\n'); return false; } cmXMLWriter xml(xmlfile); diff --git a/Source/CTest/cmCTestUpdateCommand.cxx b/Source/CTest/cmCTestUpdateCommand.cxx index 397715e3db..646e23f5d5 100644 --- a/Source/CTest/cmCTestUpdateCommand.cxx +++ b/Source/CTest/cmCTestUpdateCommand.cxx @@ -216,10 +216,9 @@ bool cmCTestUpdateCommand::ExecuteUpdate(UpdateArguments& args, this->CTest->AddSubmitFile(cmCTest::PartUpdate, "Update.xml"); - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Updating " << TypeToString(updateType) - << " repository: " << source_dir << '\n', - args.Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, args.Quiet, " Updating ", + TypeToString(updateType), " repository: ", source_dir, + '\n'); // Make sure VCS tool messages are in English so we can parse them. cmCLocaleEnvironmentScope fixLocale; @@ -277,24 +276,21 @@ bool cmCTestUpdateCommand::ExecuteUpdate(UpdateArguments& args, int localModifications = 0; int numUpdated = vc->GetPathCount(cmCTestVC::PathUpdated); if (numUpdated) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Found " << numUpdated << " updated files\n", - args.Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, args.Quiet, " Found ", + numUpdated, " updated files\n"); } if (int numModified = vc->GetPathCount(cmCTestVC::PathModified)) { - cmCTestOptionalLog( - this->CTest, HANDLER_OUTPUT, - " Found " << numModified << " locally modified files\n", args.Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, args.Quiet, " Found ", + numModified, " locally modified files\n"); localModifications += numModified; } if (int numConflicting = vc->GetPathCount(cmCTestVC::PathConflicting)) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - " Found " << numConflicting << " conflicting files\n", - args.Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, args.Quiet, " Found ", + numConflicting, " conflicting files\n"); localModifications += numConflicting; } - cmCTestOptionalLog(this->CTest, DEBUG, "End" << std::endl, args.Quiet); + cmCTestOptionalLog(this->CTest, DEBUG, args.Quiet, "End\n"); std::string end_time = this->CTest->CurrentTime(); xml.Element("EndDateTime", end_time); xml.Element("EndTime", std::chrono::system_clock::now()); @@ -307,16 +303,15 @@ bool cmCTestUpdateCommand::ExecuteUpdate(UpdateArguments& args, if (localModifications) { xml.Content("Update error: " "There are modified or conflicting files in the repository"); - cmCTestLog(this->CTest, WARNING, - " There are modified or conflicting files in the repository" - << std::endl); + cmCTestLog( + this->CTest, WARNING, + " There are modified or conflicting files in the repository\n"); } if (!updated) { xml.Content("Update command failed:\n"); xml.Content(vc->GetUpdateCommandLine()); cmCTestLog(this->CTest, HANDLER_OUTPUT, - " Update command failed: " << vc->GetUpdateCommandLine() - << "\n"); + " Update command failed: ", vc->GetUpdateCommandLine(), '\n'); } xml.EndElement(); // UpdateReturnStatus xml.EndElement(); // Update diff --git a/Source/CTest/cmCTestUploadCommand.cxx b/Source/CTest/cmCTestUploadCommand.cxx index 10ab4badb0..d5874c6fcc 100644 --- a/Source/CTest/cmCTestUploadCommand.cxx +++ b/Source/CTest/cmCTestUploadCommand.cxx @@ -44,8 +44,7 @@ bool cmCTestUploadCommand::ExecuteUpload(UploadArguments& args, cmGeneratedFileStream ofs; if (!this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(), "Upload.xml", ofs)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot open Upload.xml file" << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open Upload.xml file\n"); return false; } std::string buildname = @@ -70,8 +69,8 @@ bool cmCTestUploadCommand::ExecuteUpload(UploadArguments& args, xml.Element("Time", std::chrono::system_clock::now()); for (std::string const& file : args.Files) { - cmCTestOptionalLog(this->CTest, OUTPUT, - "\tUpload file: " << file << std::endl, args.Quiet); + cmCTestOptionalLog(this->CTest, OUTPUT, args.Quiet, + "\tUpload file: ", file, '\n'); xml.StartElement("File"); xml.Attribute("filename", file); xml.StartElement("Content"); diff --git a/Source/CTest/cmCTestVC.cxx b/Source/CTest/cmCTestVC.cxx index b8e465dbba..07c70bb739 100644 --- a/Source/CTest/cmCTestVC.cxx +++ b/Source/CTest/cmCTestVC.cxx @@ -41,15 +41,15 @@ void cmCTestVC::SetSourceDirectory(std::string const& dir) bool cmCTestVC::InitialCheckout(std::string const& command) { cmCTestLog(this->CTest, HANDLER_OUTPUT, - " First perform the initial checkout: " << command << "\n"); + " First perform the initial checkout: ", command, "\n"); // Make the parent directory in which to perform the checkout. std::string parent = cmSystemTools::GetFilenamePath(this->SourceDirectory); cmCTestLog(this->CTest, HANDLER_OUTPUT, - " Perform checkout in directory: " << parent << "\n"); + " Perform checkout in directory: ", parent, "\n"); if (!cmSystemTools::MakeDirectory(parent)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot create directory: " << parent << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create directory: ", parent, + '\n'); return false; } @@ -63,8 +63,7 @@ bool cmCTestVC::InitialCheckout(std::string const& command) bool result = this->RunChild(args, &out, &err, parent); this->Log << "--- End Initial Checkout ---\n"; if (!result) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Initial checkout failed!" << std::endl); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Initial checkout failed!\n"); } return result; } @@ -177,7 +176,7 @@ void cmCTestVC::SetNewRevision(std::string const& /*unused*/) bool cmCTestVC::UpdateImpl() { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "* Unknown VCS tool, not updating!" << std::endl); + "* Unknown VCS tool, not updating!\n"); return true; } diff --git a/Source/CTest/cmParseBlanketJSCoverage.cxx b/Source/CTest/cmParseBlanketJSCoverage.cxx index 5810b7df29..1241fdd597 100644 --- a/Source/CTest/cmParseBlanketJSCoverage.cxx +++ b/Source/CTest/cmParseBlanketJSCoverage.cxx @@ -2,6 +2,7 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmParseBlanketJSCoverage.h" +#include #include #include @@ -114,26 +115,22 @@ cmParseBlanketJSCoverage::cmParseBlanketJSCoverage( bool cmParseBlanketJSCoverage::LoadCoverageData( std::vector const& files) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Found " << files.size() << " Files" << std::endl, - this->Coverage.Quiet); - for (std::string const& file : files) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Reading JSON File " << file << std::endl, - this->Coverage.Quiet); - - if (!this->ReadJSONFile(file)) { - return false; - } - } - return true; + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Coverage.Quiet, + "Found ", files.size(), " Files\n"); + return std::all_of(files.begin(), files.end(), + [this](std::string const& file) { + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, + this->Coverage.Quiet, + "Reading JSON File ", file, '\n'); + return this->ReadJSONFile(file); + }); } bool cmParseBlanketJSCoverage::ReadJSONFile(std::string const& file) { cmParseBlanketJSCoverage::JSONParser parser(this->Coverage); - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Parsing " << file << std::endl, this->Coverage.Quiet); + cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Coverage.Quiet, + "Parsing ", file, '\n'); parser.ParseFile(file); return true; } diff --git a/Source/CTest/cmParseCacheCoverage.cxx b/Source/CTest/cmParseCacheCoverage.cxx index 44dcc6b1b4..def1bbb202 100644 --- a/Source/CTest/cmParseCacheCoverage.cxx +++ b/Source/CTest/cmParseCacheCoverage.cxx @@ -61,8 +61,8 @@ void cmParseCacheCoverage::RemoveUnCoveredFiles() } if (nothing) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "No coverage found in: " << ci->first << std::endl, - this->Coverage.Quiet); + this->Coverage.Quiet, + "No coverage found in: ", ci->first, '\n'); this->Coverage.TotalCoverage.erase(ci++); } else { ++ci; @@ -74,16 +74,15 @@ bool cmParseCacheCoverage::ReadCMCovFile(char const* file) { cmsys::ifstream in(file); if (!in) { - cmCTestLog(this->CTest, ERROR_MESSAGE, "Can not open : " << file << "\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Can not open : ", file, '\n'); return false; } std::string line; if (!cmSystemTools::GetLineFromStream(in, line)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Empty file : " << file - << " referenced in this line of cmcov data:\n" - "[" - << line << "]\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Empty file : ", file, + " referenced in this line of cmcov data:\n" + "[", + line, "]\n"); return false; } std::vector separateLine = @@ -92,10 +91,10 @@ bool cmParseCacheCoverage::ReadCMCovFile(char const* file) separateLine[1] != "Line" || separateLine[2] != "RtnLine" || separateLine[3] != "Code") { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Bad first line of cmcov file : " << file - << " line:\n" - "[" - << line << "]\n"); + "Bad first line of cmcov file : ", file, + " line:\n" + "[", + line, "]\n"); } std::string routine; std::string filepath; @@ -106,13 +105,13 @@ bool cmParseCacheCoverage::ReadCMCovFile(char const* file) // but we only care about the first 3 args anyway if (separateLine.size() < 4) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Bad line of cmcov file expected at least 4 found: " - << separateLine.size() << " " << file - << " line:\n" - "[" - << line << "]\n"); + "Bad line of cmcov file expected at least 4 found: ", + separateLine.size(), ' ', file, + " line:\n" + "[", + line, "]\n"); for (std::string::size_type i = 0; i < separateLine.size(); ++i) { - cmCTestLog(this->CTest, ERROR_MESSAGE, "" << separateLine[1] << " "); + cmCTestLog(this->CTest, ERROR_MESSAGE, separateLine[1], ' '); } cmCTestLog(this->CTest, ERROR_MESSAGE, "\n"); return false; @@ -124,8 +123,7 @@ bool cmParseCacheCoverage::ReadCMCovFile(char const* file) // Find the full path to the file if (!this->FindMumpsFile(routine, filepath)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Could not find mumps file for routine: " << routine - << "\n"); + "Could not find mumps file for routine: ", routine, '\n'); filepath.clear(); continue; // move to next line } @@ -153,8 +151,8 @@ bool cmParseCacheCoverage::ReadCMCovFile(char const* file) int count = atoi(separateLine[2].c_str()); if (linenumber > coverageVector.size()) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Parse error line is greater than number of lines in file: " - << linenumber << " " << filepath << "\n"); + "Parse error line is greater than number of lines in file: ", + linenumber, ' ', filepath, '\n'); continue; // skip setting count to avoid crash } // now add to count for linenumber diff --git a/Source/CTest/cmParseCoberturaCoverage.cxx b/Source/CTest/cmParseCoberturaCoverage.cxx index 8f608d6016..0ce4199034 100644 --- a/Source/CTest/cmParseCoberturaCoverage.cxx +++ b/Source/CTest/cmParseCoberturaCoverage.cxx @@ -40,8 +40,7 @@ protected: if (this->InSources && this->InSource) { this->FilePaths.push_back(tmp); cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Adding Source: " << tmp << std::endl, - this->Coverage.Quiet); + this->Coverage.Quiet, "Adding Source: ", tmp, '\n'); } } @@ -58,9 +57,8 @@ protected: while (true) { if (strcmp(atts[tagCount], "filename") == 0) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Reading file: " << atts[tagCount + 1] - << std::endl, - this->Coverage.Quiet); + this->Coverage.Quiet, + "Reading file: ", atts[tagCount + 1], '\n'); std::string filename = atts[tagCount + 1]; this->CurFileName.clear(); @@ -92,9 +90,8 @@ protected: fin.open(this->CurFileName.c_str()); if (!fin) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Skipping system file " << filename - << std::endl, - this->Coverage.Quiet); + this->Coverage.Quiet, "Skipping system file ", + filename, '\n'); this->SkipThisClass = true; break; diff --git a/Source/CTest/cmParseDelphiCoverage.cxx b/Source/CTest/cmParseDelphiCoverage.cxx index d74e02a677..6347f2c5fa 100644 --- a/Source/CTest/cmParseDelphiCoverage.cxx +++ b/Source/CTest/cmParseDelphiCoverage.cxx @@ -111,18 +111,16 @@ public: lastoffset = line.find('(', pos); if (lastoffset == std::string::npos) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - endnamepos << "File not found " << lastoffset - << std::endl, - this->Coverage.Quiet); + this->Coverage.Quiet, endnamepos, + "File not found ", lastoffset, '\n'); return false; } endnamepos = line.find(')', lastoffset); filename = line.substr(lastoffset + 1, (endnamepos - 1) - lastoffset); if (filename.find(".pas") != std::string::npos) { cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Coverage found for file: " << filename - << std::endl, - this->Coverage.Quiet); + this->Coverage.Quiet, + "Coverage found for file: ", filename, '\n'); break; } pos = lastoffset + 1; @@ -143,8 +141,8 @@ public: * return a failure. */ cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Unable to find file matching" << glob << std::endl, - this->Coverage.Quiet); + this->Coverage.Quiet, "Unable to find file matching", + glob, '\n'); return false; } FileLinesType& coverageVector = this->Coverage.TotalCoverage[files[0]]; @@ -214,8 +212,7 @@ bool cmParseDelphiCoverage::LoadCoverageData( path = files[i]; cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Reading HTML File " << path << std::endl, - this->Coverage.Quiet); + this->Coverage.Quiet, "Reading HTML File ", path, '\n'); if (cmSystemTools::GetFilenameLastExtension(path) == ".html") { if (!this->ReadDelphiHTML(path.c_str())) { return false; diff --git a/Source/CTest/cmParseGTMCoverage.cxx b/Source/CTest/cmParseGTMCoverage.cxx index 7ca5fe809d..d62237de41 100644 --- a/Source/CTest/cmParseGTMCoverage.cxx +++ b/Source/CTest/cmParseGTMCoverage.cxx @@ -75,11 +75,10 @@ bool cmParseGTMCoverage::ReadMCovFile(char const* file) count; } else { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Can not find mumps file : " - << lastroutine - << " referenced in this line of mcov data:\n" - "[" - << line << "]\n"); + "Can not find mumps file : ", lastroutine, + " referenced in this line of mcov data:\n" + "[", + line, "]\n"); } continue; } @@ -107,11 +106,10 @@ bool cmParseGTMCoverage::ReadMCovFile(char const* file) } } else { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Can not find mumps file : " - << routine - << " referenced in this line of mcov data:\n" - "[" - << line << "]\n"); + "Can not find mumps file : ", routine, + " referenced in this line of mcov data:\n" + "[", + line, "]\n"); } lastfunction = function; lastroutine = routine; @@ -151,8 +149,8 @@ bool cmParseGTMCoverage::FindFunctionInMumpsFile(std::string const& filepath, } lineoffset = 0; cmCTestLog(this->CTest, ERROR_MESSAGE, - "Could not find entry point : " << function << " in " << filepath - << "\n"); + "Could not find entry point : ", function, " in ", filepath, + '\n'); return false; } @@ -228,8 +226,8 @@ bool cmParseGTMCoverage::ParseMCOVLine(std::string const& line, } // less then two arguments is an error if (args.size() < 2) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Error parsing mcov line: [" << line << "]\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Error parsing mcov line: [", line, + "]\n"); return false; } routine = args[0]; // the routine is the first argument diff --git a/Source/CTest/cmParseJacocoCoverage.cxx b/Source/CTest/cmParseJacocoCoverage.cxx index 3411b7a341..9de6e02f24 100644 --- a/Source/CTest/cmParseJacocoCoverage.cxx +++ b/Source/CTest/cmParseJacocoCoverage.cxx @@ -1,5 +1,6 @@ #include "cmParseJacocoCoverage.h" +#include #include #include @@ -37,23 +38,22 @@ protected: if (this->PackagePath.empty()) { if (!this->FindPackagePath(fileName)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Cannot find file: " << this->PackageName << "/" - << fileName << std::endl); + "Cannot find file: ", this->PackageName, '/', fileName, + '\n'); this->Coverage.Error++; return; } } cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Reading file: " << fileName << std::endl, - this->Coverage.Quiet); + this->Coverage.Quiet, "Reading file: ", fileName, + '\n'); this->FilePath = cmStrCat(this->PackagePath, '/', fileName); cmsys::ifstream fin(this->FilePath.c_str()); if (!fin) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Jacoco Coverage: Error opening " << this->FilePath - << std::endl); + "Jacoco Coverage: Error opening ", this->FilePath, '\n'); } std::string line; FileLinesType& curFileLines = @@ -116,18 +116,18 @@ protected: } // Check if any of the locations found match our package. - for (std::string const& f : files) { - std::string dir = cmsys::SystemTools::GetParentDirectory(f); - if (cmHasSuffix(dir, this->PackageName)) { - cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Found package directory for " << fileName << ": " - << dir << std::endl, - this->Coverage.Quiet); - this->PackagePath = dir; - return true; - } - } - return false; + return std::any_of( + files.begin(), files.end(), [this, &fileName](std::string const& f) { + std::string dir = cmsys::SystemTools::GetParentDirectory(f); + if (cmHasSuffix(dir, this->PackageName)) { + cmCTestOptionalLog( + this->CTest, HANDLER_VERBOSE_OUTPUT, this->Coverage.Quiet, + "Found package directory for ", fileName, ": ", dir, '\n'); + this->PackagePath = dir; + return true; + } + return false; + }); } private: @@ -159,8 +159,7 @@ bool cmParseJacocoCoverage::LoadCoverageData( path = files[i]; cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, - "Reading XML File " << path << std::endl, - this->Coverage.Quiet); + this->Coverage.Quiet, "Reading XML File ", path, '\n'); if (cmSystemTools::GetFilenameLastExtension(path) == ".xml") { if (!this->ReadJacocoXML(path.c_str())) { return false; diff --git a/Source/CTest/cmParseMumpsCoverage.cxx b/Source/CTest/cmParseMumpsCoverage.cxx index 6829d8558b..5f513552b3 100644 --- a/Source/CTest/cmParseMumpsCoverage.cxx +++ b/Source/CTest/cmParseMumpsCoverage.cxx @@ -44,11 +44,11 @@ bool cmParseMumpsCoverage::ReadCoverageFile(char const* file) this->LoadCoverageData(path); } else { cmCTestLog(this->CTest, ERROR_MESSAGE, - "Parse Error in Mumps coverage file :\n" - << file << "\ntype: [" << type << "]\npath:[" << path - << "]\n" - "input line: [" - << line << "]\n"); + "Parse Error in Mumps coverage file :\n", file, "\ntype: [", + type, "]\npath:[", path, + "]\n" + "input line: [", + line, "]\n"); } } } diff --git a/Source/CTest/cmParsePHPCoverage.cxx b/Source/CTest/cmParsePHPCoverage.cxx index 0bc98d7ac3..b5ddc188b0 100644 --- a/Source/CTest/cmParsePHPCoverage.cxx +++ b/Source/CTest/cmParsePHPCoverage.cxx @@ -50,8 +50,7 @@ bool cmParsePHPCoverage::ReadCoverageArray(std::istream& in, buf[3] = 0; if (strcmp(buf, ";a:") != 0) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "failed to read start of coverage array, found : " << buf - << "\n"); + "failed to read start of coverage array, found : ", buf, '\n'); return false; } int size = 0; @@ -137,7 +136,7 @@ bool cmParsePHPCoverage::ReadFileInformation(std::istream& in) buf[2] = 0; if (strcmp(buf, "s:") != 0) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "failed to read start of file info found: [" << buf << "]\n"); + "failed to read start of file info found: [", buf, "]\n"); return false; } char c; @@ -155,15 +154,13 @@ bool cmParsePHPCoverage::ReadFileInformation(std::istream& in) std::string fileName = s.get(); // read close quote if (in.get(c) && c != '"') { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "failed to read close quote\n" - << "read [" << c << "]\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, "failed to read close quote\n", + "read [", c, "]\n"); return false; } if (!this->ReadCoverageArray(in, fileName)) { cmCTestLog(this->CTest, ERROR_MESSAGE, - "failed to read coverage array for file: " << fileName - << "\n"); + "failed to read coverage array for file: ", fileName, "\n"); return false; } return true; @@ -187,8 +184,7 @@ bool cmParsePHPCoverage::ReadPHPData(char const* file) } for (int i = 0; i < size; i++) { if (!this->ReadFileInformation(in)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Failed to read file #" << i << "\n"); + cmCTestLog(this->CTest, ERROR_MESSAGE, "Failed to read file #", i, "\n"); return false; } in.get(c); diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx index d0e3d0cd14..ed6a445d9a 100644 --- a/Source/CTest/cmProcess.cxx +++ b/Source/CTest/cmProcess.cxx @@ -3,7 +3,6 @@ #include "cmProcess.h" #include -#include #include #include #include @@ -76,8 +75,7 @@ bool cmProcess::StartProcess(uv_loop_t& loop, std::vector* affinity) int status = timer.init(loop, this); if (status != 0) { cmCTestLog(this->Runner->GetCTest(), ERROR_MESSAGE, - "Error initializing timer: " << uv_strerror(status) - << std::endl); + "Error initializing timer: ", uv_strerror(status), '\n'); return false; } @@ -91,8 +89,7 @@ bool cmProcess::StartProcess(uv_loop_t& loop, std::vector* affinity) status = cmGetPipes(fds); if (status != 0) { cmCTestLog(this->Runner->GetCTest(), ERROR_MESSAGE, - "Error initializing pipe: " << uv_strerror(status) - << std::endl); + "Error initializing pipe: ", uv_strerror(status), '\n'); return false; } @@ -148,16 +145,15 @@ bool cmProcess::StartProcess(uv_loop_t& loop, std::vector* affinity) if (status != 0) { cmCTestLog(this->Runner->GetCTest(), ERROR_MESSAGE, - "Error starting read events: " << uv_strerror(status) - << std::endl); + "Error starting read events: ", uv_strerror(status), '\n'); return false; } status = this->Process.spawn(loop, options, this); if (status != 0) { cmCTestLog(this->Runner->GetCTest(), ERROR_MESSAGE, - "Process not started\n " << this->Command << "\n[" - << uv_strerror(status) << "]\n"); + "Process not started\n ", this->Command, "\n[", + uv_strerror(status), "]\n"); return false; } @@ -257,7 +253,7 @@ void cmProcess::OnRead(ssize_t nread, uv_buf_t const* buf) if (nread != UV_EOF) { auto error = static_cast(nread); cmCTestLog(this->Runner->GetCTest(), ERROR_MESSAGE, - "Error reading stream: " << uv_strerror(error) << std::endl); + "Error reading stream: ", uv_strerror(error), '\n'); } // Look for partial last lines. diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 8740980b7a..5d532d326a 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -223,9 +223,9 @@ struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag) time_t tctime = time(nullptr); lctime = gmtime(&tctime); cmCTestLog(this, OUTPUT, - "Determine Nightly Start Time" << std::endl - << " Specified time: " << str - << std::endl); + "Determine Nightly Start Time\n" + " Specified time: ", + str, '\n'); // Convert the nightly start time to seconds. The current date of // the local machine is assumed. Consequently, nightlySeconds // is the time at which the nightly dashboard was opened or @@ -235,13 +235,12 @@ struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag) std::snprintf(buf, sizeof(buf), "%d%02d%02d %s", lctime->tm_year + 1900, lctime->tm_mon + 1, lctime->tm_mday, str.c_str()); time_t ntime = cm_parse_date(tctime, buf); - cmCTestLog(this, DEBUG, - " Get the nightly start time: " << ntime << std::endl); + cmCTestLog(this, DEBUG, " Get the nightly start time: ", ntime, '\n'); tctime = time(nullptr); - cmCTestLog(this, DEBUG, " Get the current time: " << tctime << std::endl); + cmCTestLog(this, DEBUG, " Get the current time: ", tctime, '\n'); int const dayLength = 24 * 60 * 60; - cmCTestLog(this, DEBUG, "Seconds: " << tctime << std::endl); + cmCTestLog(this, DEBUG, "Seconds: ", tctime, '\n'); while (ntime > tctime) { // If nightlySeconds is in the past, this is the current // open dashboard, then return nightlySeconds. If @@ -249,20 +248,18 @@ struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag) // dashboard to be opened, so subtract 24 hours to get the // time of the current open dashboard ntime -= dayLength; - cmCTestLog(this, DEBUG, "Pick yesterday" << std::endl); - cmCTestLog(this, DEBUG, - " Future time, subtract day: " << ntime << std::endl); + cmCTestLog(this, DEBUG, "Pick yesterday\n"); + cmCTestLog(this, DEBUG, " Future time, subtract day: ", ntime, '\n'); } while (tctime > (ntime + dayLength)) { ntime += dayLength; - cmCTestLog(this, DEBUG, " Past time, add day: " << ntime << std::endl); + cmCTestLog(this, DEBUG, " Past time, add day: ", ntime, '\n'); } - cmCTestLog(this, DEBUG, "nightlySeconds: " << ntime << std::endl); - cmCTestLog(this, DEBUG, - " Current time: " << tctime << " Nightly time: " << ntime - << std::endl); + cmCTestLog(this, DEBUG, "nightlySeconds: ", ntime, '\n'); + cmCTestLog(this, DEBUG, " Current time: ", tctime, + " Nightly time: ", ntime, '\n'); if (tomorrowtag) { - cmCTestLog(this, OUTPUT, " Use future tag, Add a day" << std::endl); + cmCTestLog(this, OUTPUT, " Use future tag, Add a day\n"); ntime += dayLength; } lctime = gmtime(&ntime); @@ -299,7 +296,7 @@ std::string cmCTest::CurrentTime() } else { strftime(current_time, 1000, "%a %b %d %H:%M:%S %Z %Y", t); } - cmCTestLog(this, DEBUG, " Current_Time: " << current_time << std::endl); + cmCTestLog(this, DEBUG, " Current_Time: ", current_time, '\n'); return cmCTest::CleanString(current_time); } @@ -408,8 +405,7 @@ bool cmCTest::UpdateStateFromEnvironment() this->Impl->NoTestsMode = cmCTest::NoTests::Ignore; } else { cmCTestLog(this, ERROR_MESSAGE, - "Unknown value for CTEST_NO_TESTS_ACTION: '" << action - << '\''); + "Unknown value for CTEST_NO_TESTS_ACTION: '", action, '\''); return false; } } @@ -470,17 +466,15 @@ bool cmCTest::CreateNewTag(bool quiet) auto const result = cmSystemTools::MakeDirectory(testingDir); if (!result.IsSuccess()) { - cmCTestLog(this, ERROR_MESSAGE, - "Cannot create directory \"" - << testingDir << "\": " << result.GetString() << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Cannot create directory \"", testingDir, + "\": ", result.GetString(), '\n'); return false; } - cmCTestOptionalLog(this, DEBUG, - "TestModel: " << this->GetTestGroupString() << std::endl, - quiet); - cmCTestOptionalLog( - this, DEBUG, "TestModel: " << this->Impl->TestModel << std::endl, quiet); + cmCTestOptionalLog(this, DEBUG, quiet, + "TestModel: ", this->GetTestGroupString(), '\n'); + cmCTestOptionalLog(this, DEBUG, quiet, "TestModel: ", this->Impl->TestModel, + '\n'); struct tm* lctime = [this]() -> tm* { if (this->Impl->TestModel == cmCTest::NIGHTLY) { @@ -531,9 +525,8 @@ bool cmCTest::ReadExistingTag(bool quiet) if (tag.empty()) { if (!quiet) { - cmCTestLog(this, ERROR_MESSAGE, - "Cannot read existing TAG file in " << testingDir - << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Cannot read existing TAG file in ", + testingDir, '\n'); } return false; } @@ -542,8 +535,7 @@ bool cmCTest::ReadExistingTag(bool quiet) if (model == cmCTest::UNKNOWN) { cmCTestLog(this, ERROR_MESSAGE, "TAG file does not contain model and " - "no model specified in start command" - << std::endl); + "no model specified in start command\n"); return false; } @@ -552,29 +544,22 @@ bool cmCTest::ReadExistingTag(bool quiet) if (model != this->Impl->TestModel && model != cmCTest::UNKNOWN && this->Impl->TestModel != cmCTest::UNKNOWN) { - cmCTestOptionalLog(this, WARNING, + cmCTestOptionalLog(this, WARNING, quiet, "Model given in TAG does not match " - "model given in ctest_start()" - << std::endl, - quiet); + "model given in ctest_start()\n"); } if (!this->Impl->SpecificGroup.empty() && group != this->Impl->SpecificGroup) { - cmCTestOptionalLog(this, WARNING, + cmCTestOptionalLog(this, WARNING, quiet, "Group given in TAG does not match " - "group given in ctest_start()" - << std::endl, - quiet); + "group given in ctest_start()\n"); } else { this->Impl->SpecificGroup = group; } - cmCTestOptionalLog(this, OUTPUT, - " Use existing tag: " << tag << " - " - << this->GetTestGroupString() - << std::endl, - quiet); + cmCTestOptionalLog(this, OUTPUT, quiet, " Use existing tag: ", tag, " - ", + this->GetTestGroupString(), '\n'); this->Impl->CurrentTag = tag; return true; @@ -587,17 +572,17 @@ bool cmCTest::UpdateCTestConfiguration() fileName = this->Impl->BinaryDir + "/DartConfiguration.tcl"; } cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, - "UpdateCTestConfiguration from :" << fileName << "\n"); + "UpdateCTestConfiguration from :", fileName, '\n'); if (!cmSystemTools::FileExists(fileName)) { // No need to exit if we are not producing XML if (this->Impl->ProduceXML) { - cmCTestLog(this, WARNING, "Cannot find file: " << fileName << std::endl); + cmCTestLog(this, WARNING, "Cannot find file: ", fileName, '\n'); this->ApplyDefinitionsToCTestConfig(); return false; } } else { - cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, - "Parse Config file:" << fileName << "\n"); + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Parse Config file:", fileName, + '\n'); // parse the dart test file cmsys::ifstream fin(fileName.c_str()); @@ -648,8 +633,8 @@ bool cmCTest::UpdateCTestConfiguration() if (cmStrToULong(testLoad, &load)) { this->SetTestLoad(load); } else { - cmCTestLog(this, WARNING, - "Invalid value for 'Test Load' : " << testLoad << std::endl); + cmCTestLog(this, WARNING, "Invalid value for 'Test Load' : ", testLoad, + '\n'); } } if (this->Impl->ProduceXML) { @@ -697,9 +682,8 @@ bool cmCTest::SetTest(std::string const& ttype, bool report) return true; } if (report) { - cmCTestLog(this, ERROR_MESSAGE, - "Don't know about test \"" << ttype << "\" yet..." - << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Don't know about test \"", ttype, + "\" yet...\n"); } return false; } @@ -713,24 +697,21 @@ bool cmCTest::OpenOutputFile(std::string const& path, std::string const& name, } if (cmSystemTools::FileExists(testingDir)) { if (!cmSystemTools::FileIsDirectory(testingDir)) { - cmCTestLog(this, ERROR_MESSAGE, - "File " << testingDir - << " is in the place of the testing directory" - << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "File ", testingDir, + " is in the place of the testing directory\n"); return false; } } else { if (!cmSystemTools::MakeDirectory(testingDir)) { - cmCTestLog(this, ERROR_MESSAGE, - "Cannot create directory " << testingDir << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Cannot create directory ", testingDir, + '\n'); return false; } } std::string filename = cmStrCat(testingDir, '/', name); stream.Open(filename); if (!stream) { - cmCTestLog(this, ERROR_MESSAGE, - "Problem opening file: " << filename << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Problem opening file: ", filename, '\n'); return false; } if (compress) { @@ -825,11 +806,9 @@ int cmCTest::ProcessSteps() cmCMakePresetsGraph presetsGraph; if (!sourceDir.empty()) { if (!presetsGraph.ReadProjectPresets(sourceDir, presetsFile)) { - cmCTestLog(this, ERROR_MESSAGE, - "Could not read presets from \"" - << sourceDir << "\":\n " - << presetsGraph.parseState.GetErrorMessage() - << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Could not read presets from \"", + sourceDir, "\":\n ", + presetsGraph.parseState.GetErrorMessage(), '\n'); return 12; } cmCMakePresetsGraph::PresetResolveResult< @@ -842,7 +821,7 @@ int cmCTest::ProcessSteps() resolveResult.StatusCode, resolveResult.ErrorPresetName, sourceDir); if (resolveError) { - cmCTestLog(this, ERROR_MESSAGE, *resolveError << std::endl); + cmCTestLog(this, ERROR_MESSAGE, *resolveError, '\n'); return 12; } if (resolveResult.Preset && !resolveResult.Preset->BinaryDir.empty()) { @@ -880,8 +859,7 @@ int cmCTest::ProcessSteps() return 12; } } else if (!this->ReadExistingTag(true) && !this->CreateNewTag(false)) { - cmCTestLog(this, ERROR_MESSAGE, - "Problem initializing the dashboard." << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Problem initializing the dashboard.\n"); return 12; } @@ -1056,9 +1034,9 @@ bool cmCTest::RunMakeCommand(std::string const& command, std::string& output, output.clear(); cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Run command:"); for (auto const& arg : args) { - cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, " \"" << arg << "\""); + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, " \"", arg, "\""); } - cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, std::endl); + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, '\n'); // Now create process object cmUVProcessChainBuilder builder; @@ -1075,11 +1053,9 @@ bool cmCTest::RunMakeCommand(std::string const& command, std::string& output, std::string::size_type tick_line_len = 50; cmProcessOutput processOutput(encoding); - cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, - " Each . represents " << tick_len - << " bytes of output\n" - " " - << std::flush); + cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, " Each . represents ", tick_len, + " bytes of output\n" + " "); auto outputHandle = cmUVStreamRead( outputStream, [this, &processOutput, &output, &tick, &tick_len, &tick_line_len, @@ -1094,11 +1070,11 @@ bool cmCTest::RunMakeCommand(std::string const& command, std::string& output, output.append(strdata); while (output.size() > (tick * tick_len)) { tick++; - cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, "." << std::flush); + cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, '.'); if (tick % tick_line_len == 0 && tick > 0) { cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, - " Size: " << int((double(output.size()) / 1024.0) + 1) - << "K\n " << std::flush); + " Size: ", int((double(output.size()) / 1024.0) + 1), + "K\n "); } } cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, strdata); @@ -1120,8 +1096,7 @@ bool cmCTest::RunMakeCommand(std::string const& command, std::string& output, bool finished = chain.Wait(static_cast(timeout.count() * 1000.0)); cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, - " Size of output: " << int(double(output.size()) / 1024.0) << "K" - << std::endl); + " Size of output: ", int(double(output.size()) / 1024.0), "K\n"); if (finished) { auto const& status = chain.GetStatus(0); @@ -1130,24 +1105,23 @@ bool cmCTest::RunMakeCommand(std::string const& command, std::string& output, case cmUVProcessChain::ExceptionCode::None: *retVal = static_cast(status.ExitStatus); cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, - "Command exited with the value: " << *retVal << std::endl); + "Command exited with the value: ", *retVal, '\n'); break; case cmUVProcessChain::ExceptionCode::Spawn: output += "\n*** ERROR executing: "; output += exception.second; output += "\n***The build process failed."; cmCTestLog(this, ERROR_MESSAGE, - "There was an error: " << exception.second << std::endl); + "There was an error: ", exception.second, '\n'); break; default: *retVal = static_cast(exception.first); - cmCTestLog(this, WARNING, - "There was an exception: " << *retVal << std::endl); + cmCTestLog(this, WARNING, "There was an exception: ", *retVal, '\n'); break; } } else { chain.Terminate(); - cmCTestLog(this, WARNING, "There was a timeout" << std::endl); + cmCTestLog(this, WARNING, "There was a timeout\n"); } return true; @@ -1163,8 +1137,7 @@ void cmCTest::StartXML(cmXMLWriter& xml, cmake* cm, bool append) if (this->Impl->CurrentTag.empty()) { cmCTestLog(this, ERROR_MESSAGE, "Current Tag empty, this may mean" - " NightlStartTime was not set correctly." - << std::endl); + " NightlStartTime was not set correctly.\n"); cmSystemTools::SetFatalErrorOccurred(); } @@ -1304,7 +1277,7 @@ int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml, cmake* cm, xml.StartElement("Notes"); for (std::string const& file : files) { - cmCTestLog(this, OUTPUT, "\tAdd file: " << file << std::endl); + cmCTestLog(this, OUTPUT, "\tAdd file: ", file, '\n'); std::string note_time = this->CurrentTime(); xml.StartElement("Note"); xml.Attribute("Name", file); @@ -1321,9 +1294,8 @@ int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml, cmake* cm, ifs.close(); } else { xml.Content(cmStrCat("Problem reading file: ", file, '\n')); - cmCTestLog(this, ERROR_MESSAGE, - "Problem reading file: " << file << " while creating notes" - << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Problem reading file: ", file, + " while creating notes\n"); } xml.EndElement(); // Text xml.EndElement(); // Note @@ -1339,7 +1311,7 @@ int cmCTest::GenerateNotesFile(cmake* cm, { cmGeneratedFileStream ofs; if (!this->OpenOutputFile(this->Impl->CurrentTag, "Notes.xml", ofs)) { - cmCTestLog(this, ERROR_MESSAGE, "Cannot open notes file" << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Cannot open notes file\n"); return 1; } cmXMLWriter xml(ofs); @@ -1353,7 +1325,7 @@ int cmCTest::GenerateNotesFile(cmake* cm, std::string const& cfiles) return 1; } - cmCTestLog(this, OUTPUT, "Create notes file" << std::endl); + cmCTestLog(this, OUTPUT, "Create notes file\n"); std::vector const files = cmSystemTools::SplitString(cfiles, ';'); @@ -1368,7 +1340,7 @@ int cmCTest::GenerateDoneFile() { cmGeneratedFileStream ofs; if (!this->OpenOutputFile(this->Impl->CurrentTag, "Done.xml", ofs)) { - cmCTestLog(this, ERROR_MESSAGE, "Cannot open done file" << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Cannot open done file\n"); return 1; } cmXMLWriter xml(ofs); @@ -1388,7 +1360,7 @@ std::string cmCTest::Base64GzipEncodeFile(std::string const& file) // with a flat directory structure. cmWorkingDirectory workdir(cmSystemTools::GetParentDirectory(file)); if (workdir.Failed()) { - cmCTestLog(this, ERROR_MESSAGE, workdir.GetError() << std::endl); + cmCTestLog(this, ERROR_MESSAGE, workdir.GetError(), '\n'); return ""; } @@ -1401,8 +1373,8 @@ std::string cmCTest::Base64GzipEncodeFile(std::string const& file) false)) { cmCTestLog(this, ERROR_MESSAGE, "Error creating tar while " - "encoding file: " - << file << std::endl); + "encoding file: ", + file, '\n'); return ""; } std::string base64 = this->Base64EncodeFile(tarFile); @@ -1434,16 +1406,16 @@ std::string cmCTest::Base64EncodeFile(std::string const& file) bool cmCTest::SubmitExtraFiles(std::vector const& files) { - for (std::string const& file : files) { - if (!cmSystemTools::FileExists(file)) { - cmCTestLog(this, ERROR_MESSAGE, - "Cannot find extra file: " << file << " to submit." - << std::endl); - return false; - } - this->AddSubmitFile(PartExtraFiles, file); - } - return true; + return std::all_of( + files.begin(), files.end(), [this](std::string const& file) { + if (!cmSystemTools::FileExists(file)) { + cmCTestLog(this, ERROR_MESSAGE, "Cannot find extra file: ", file, + " to submit.\n"); + return false; + } + this->AddSubmitFile(PartExtraFiles, file); + return true; + }); } bool cmCTest::SubmitExtraFiles(std::string const& cfiles) @@ -1452,7 +1424,7 @@ bool cmCTest::SubmitExtraFiles(std::string const& cfiles) return true; } - cmCTestLog(this, OUTPUT, "Submit extra files" << std::endl); + cmCTestLog(this, OUTPUT, "Submit extra files\n"); std::vector const files = cmSystemTools::SplitString(cfiles, ';'); @@ -1591,7 +1563,7 @@ bool cmCTest::AddTestsForDashboardType(std::string const& targ) void cmCTest::ErrorMessageUnknownDashDValue(std::string const& val) { cmCTestLog(this, ERROR_MESSAGE, - "CTest -D called with incorrect option: " << val << '\n'); + "CTest -D called with incorrect option: ", val, '\n'); cmCTestLog(this, ERROR_MESSAGE, "Available options are:\n" @@ -1908,20 +1880,23 @@ int cmCTest::Run(std::vector const& args) ctestExec](std::string const& action) -> bool { if (!this->SetTest(action, false)) { cmCTestLog(this, ERROR_MESSAGE, - "CTest -T called with incorrect option: " << action << '\n'); + "CTest -T called with incorrect option: ", action, '\n'); /* clang-format off */ - cmCTestLog(this, ERROR_MESSAGE, - "Available options are:\n" - " " << ctestExec << " -T all\n" - " " << ctestExec << " -T start\n" - " " << ctestExec << " -T update\n" - " " << ctestExec << " -T configure\n" - " " << ctestExec << " -T build\n" - " " << ctestExec << " -T test\n" - " " << ctestExec << " -T coverage\n" - " " << ctestExec << " -T memcheck\n" - " " << ctestExec << " -T notes\n" - " " << ctestExec << " -T submit\n"); + cmCTestLog( + this, + ERROR_MESSAGE, + "Available options are:\n" + " ", ctestExec, " -T all\n" + " ", ctestExec, " -T start\n" + " ", ctestExec, " -T update\n" + " ", ctestExec, " -T configure\n" + " ", ctestExec, " -T build\n" + " ", ctestExec, " -T test\n" + " ", ctestExec, " -T coverage\n" + " ", ctestExec, " -T memcheck\n" + " ", ctestExec, " -T notes\n" + " ", ctestExec, " -T submit\n" + ); /* clang-format on */ return false; } @@ -1938,13 +1913,16 @@ int cmCTest::Run(std::vector const& args) this->SetTestModel(cmCTest::EXPERIMENTAL); } else { cmCTestLog(this, ERROR_MESSAGE, - "CTest -M called with incorrect option: " << model << '\n'); + "CTest -M called with incorrect option: ", model, '\n'); /* clang-format off */ - cmCTestLog(this, ERROR_MESSAGE, - "Available options are:\n" - " " << ctestExec << " -M Continuous\n" - " " << ctestExec << " -M Experimental\n" - " " << ctestExec << " -M Nightly\n"); + cmCTestLog( + this, + ERROR_MESSAGE, + "Available options are:\n" + " ", ctestExec, " -M Continuous\n" + " ", ctestExec, " -M Experimental\n" + " ", ctestExec, " -M Nightly\n" + ); /* clang-format on */ return false; } @@ -2300,9 +2278,9 @@ int cmCTest::Run(std::vector const& args) if (cmStrToULong(l, &load)) { this->SetTestLoad(load); } else { - cmCTestLog( - this, WARNING, - "Invalid value for 'Test Load' : " << l << '\n'); + cmCTestLog(this, WARNING, + "Invalid value for 'Test Load' : ", l, + '\n'); } return true; } }, @@ -2381,34 +2359,34 @@ int cmCTest::Run(std::vector const& args) this->Impl->OutputTestOutputOnTestFailure = true; return true; } }, - CommandArgument{ "--test-output-size-passed", CommandArgument::Values::One, - [this](std::string const& sz) -> bool { - long outputSize; - if (cmStrToLong(sz, &outputSize)) { - this->Impl->TestOptions.OutputSizePassed = - static_cast(outputSize); - } else { - cmCTestLog( - this, WARNING, - "Invalid value for '--test-output-size-passed': " - << sz << "\n"); - } - return true; - } }, - CommandArgument{ "--test-output-size-failed", CommandArgument::Values::One, - [this](std::string const& sz) -> bool { - long outputSize; - if (cmStrToLong(sz, &outputSize)) { - this->Impl->TestOptions.OutputSizeFailed = - static_cast(outputSize); - } else { - cmCTestLog( - this, WARNING, - "Invalid value for '--test-output-size-failed': " - << sz << "\n"); - } - return true; - } }, + CommandArgument{ + "--test-output-size-passed", CommandArgument::Values::One, + [this](std::string const& sz) -> bool { + long outputSize; + if (cmStrToLong(sz, &outputSize)) { + this->Impl->TestOptions.OutputSizePassed = + static_cast(outputSize); + } else { + cmCTestLog(this, WARNING, + "Invalid value for '--test-output-size-passed': ", sz, + "\n"); + } + return true; + } }, + CommandArgument{ + "--test-output-size-failed", CommandArgument::Values::One, + [this](std::string const& sz) -> bool { + long outputSize; + if (cmStrToLong(sz, &outputSize)) { + this->Impl->TestOptions.OutputSizeFailed = + static_cast(outputSize); + } else { + cmCTestLog(this, WARNING, + "Invalid value for '--test-output-size-failed': ", sz, + "\n"); + } + return true; + } }, CommandArgument{ "--test-output-truncation", CommandArgument::Values::One, [this](std::string const& mode) -> bool { @@ -2581,8 +2559,7 @@ int cmCTest::Run(std::vector const& args) static_cast(seed_value); } else { cmCTestLog(this, WARNING, - "Invalid value for '--schedule-random-seed': " << sz - << "\n"); + "Invalid value for '--schedule-random-seed': ", sz, "\n"); } return true; } }, @@ -2740,15 +2717,15 @@ int cmCTest::Run(std::vector const& args) this->Impl->CTestConfigurationOverwrites["SourceDirectory"] = cmSystemTools::ToNormalizedPathOnDisk(this->Impl->SourceDir); if (!cmSystemTools::MakeDirectory(workDir)) { - cmCTestLog(this, ERROR_MESSAGE, - "Failed to create directory: " << workDir << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Failed to create directory: ", workDir, + '\n'); return 1; } } cmWorkingDirectory changeDir(workDir); if (changeDir.Failed()) { - cmCTestLog(this, ERROR_MESSAGE, changeDir.GetError() << std::endl); + cmCTestLog(this, ERROR_MESSAGE, changeDir.GetError(), '\n'); return 1; } this->Impl->BinaryDir = workDir; @@ -2765,7 +2742,7 @@ int cmCTest::RunScripts( std::vector> const& scripts) { if (this->Impl->ExtraVerbose) { - cmCTestLog(this, OUTPUT, "* Extra verbosity turned on" << std::endl); + cmCTestLog(this, OUTPUT, "* Extra verbosity turned on\n"); } auto ch = cm::make_unique(this); @@ -2775,8 +2752,7 @@ int cmCTest::RunScripts( int res = ch->ProcessHandler(); if (res != 0) { - cmCTestLog(this, DEBUG, - "running script failing returning: " << res << std::endl); + cmCTestLog(this, DEBUG, "running script failing returning: ", res, '\n'); } return res; @@ -2787,7 +2763,7 @@ int cmCTest::ExecuteTests(std::vector const& args) this->Impl->ExtraVerbose = this->Impl->Verbose; this->Impl->Verbose = true; - cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl); + cmCTestLog(this, DEBUG, "Here: ", __LINE__, '\n'); if (!this->GetInteractiveDebugMode()) { this->BlockTestErrorDiagnostics(); } else { @@ -2796,7 +2772,7 @@ int cmCTest::ExecuteTests(std::vector const& args) this->UpdateCTestConfiguration(); - cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl); + cmCTestLog(this, DEBUG, "Here: ", __LINE__, '\n'); cmCTestTestHandler handler(this); @@ -2858,7 +2834,7 @@ int cmCTest::ExecuteTests(std::vector const& args) std::string const lastTestLog = this->GetBinaryDir() + "/Testing/Temporary/LastTest.log"; cmCTestLog(this, ERROR_MESSAGE, - "Output from these tests are in: " << lastTestLog << '\n'); + "Output from these tests are in: ", lastTestLog, '\n'); cmCTestLog(this, ERROR_MESSAGE, "Use \"--rerun-failed --output-on-failure\" to re-run the " "failed cases verbosely.\n"); @@ -2948,14 +2924,13 @@ void cmCTest::SetScheduleType(std::string const& type) void cmCTest::ReadCustomConfigurationFileTree(std::string const& dir, cmMakefile* mf) { - cmCTestLog(this, DEBUG, - "* Read custom CTest configuration directory: " << dir - << std::endl); + cmCTestLog(this, DEBUG, "* Read custom CTest configuration directory: ", dir, + '\n'); auto const fname = [this, &dir]() -> std::string { for (char const* ext : { ".cmake", ".ctest" }) { std::string path = cmStrCat(dir, "/CTestCustom", ext); - cmCTestLog(this, DEBUG, "* Check for file: " << path << std::endl); + cmCTestLog(this, DEBUG, "* Check for file: ", path, '\n'); if (cmSystemTools::FileExists(path)) { return path; } @@ -2964,16 +2939,14 @@ void cmCTest::ReadCustomConfigurationFileTree(std::string const& dir, }(); if (!fname.empty()) { - cmCTestLog(this, DEBUG, - "* Read custom CTest configuration file: " << fname - << std::endl); + cmCTestLog(this, DEBUG, "* Read custom CTest configuration file: ", fname, + '\n'); bool erroroc = cmSystemTools::GetErrorOccurredFlag(); cmSystemTools::ResetErrorOccurredFlag(); if (!mf->ReadListFile(fname) || cmSystemTools::GetErrorOccurredFlag()) { cmCTestLog(this, ERROR_MESSAGE, - "Problem reading custom configuration: " << fname - << std::endl); + "Problem reading custom configuration: ", fname, '\n'); } if (erroroc) { cmSystemTools::SetErrorOccurred(); @@ -2988,12 +2961,12 @@ void cmCTest::PopulateCustomVector(cmMakefile* mf, std::string const& def, if (!dval) { return; } - cmCTestLog(this, DEBUG, "PopulateCustomVector: " << def << std::endl); + cmCTestLog(this, DEBUG, "PopulateCustomVector: ", def, '\n'); cmList::assign(vec, *dval); for (std::string const& it : vec) { - cmCTestLog(this, DEBUG, " -- " << it << std::endl); + cmCTestLog(this, DEBUG, " -- ", it, '\n'); } } @@ -3073,9 +3046,8 @@ void cmCTest::EmptyCTestConfiguration() void cmCTest::SetCTestConfiguration(char const* name, std::string const& value, bool suppress) { - cmCTestOptionalLog(this, HANDLER_VERBOSE_OUTPUT, - "SetCTestConfiguration:" << name << ":" << value << "\n", - suppress); + cmCTestOptionalLog(this, HANDLER_VERBOSE_OUTPUT, suppress, + "SetCTestConfiguration:", name, ":", value, "\n"); if (!name) { return; @@ -3333,8 +3305,8 @@ void cmCTest::AddCTestConfigurationOverwrite(std::string const& overStr) cmCTestLog(this, ERROR_MESSAGE, "CTest configuration overwrite specified in the wrong format.\n" "Valid format is: --overwrite key=value\n" - "The specified was: --overwrite " - << overStr << '\n'); + "The specified was: --overwrite ", + overStr, '\n'); return; } std::string key = overStr.substr(0, epos); @@ -3358,10 +3330,9 @@ bool cmCTest::SetCTestConfigurationFromCMakeVariable( if (!ctvar) { return false; } - cmCTestOptionalLog(this, HANDLER_VERBOSE_OUTPUT, - "SetCTestConfigurationFromCMakeVariable:" - << dconfig << ":" << cmake_var << std::endl, - suppress); + cmCTestOptionalLog(this, HANDLER_VERBOSE_OUTPUT, suppress, + "SetCTestConfigurationFromCMakeVariable:", dconfig, ':', + cmake_var, '\n'); this->SetCTestConfiguration(dconfig, *ctvar, suppress); return true; } @@ -3473,9 +3444,8 @@ void cmCTest::SetCMakeVariables(cmMakefile& mf) for (auto const& entry : kCTestVarConfigMap) { std::string val = this->GetCTestConfiguration(entry.Config); if (!val.empty()) { - cmCTestOptionalLog( - this, HANDLER_VERBOSE_OUTPUT, - "SetCMakeVariable:" << entry.Var << ":" << val << std::endl, false); + cmCTestOptionalLog(this, HANDLER_VERBOSE_OUTPUT, false, + "SetCMakeVariable:", entry.Var, ':', val, '\n'); mf.AddDefinition(entry.Var, val); } } @@ -3589,7 +3559,7 @@ bool cmCTest::RunCommand(std::vector const& args, if (timedOut) { chain.Terminate(); char const* error_str = "Process terminated due to timeout\n"; - cmCTestLog(this, ERROR_MESSAGE, error_str << std::endl); + cmCTestLog(this, ERROR_MESSAGE, error_str, '\n'); stdErr->append(error_str, strlen(error_str)); result = false; } else { @@ -3606,7 +3576,7 @@ bool cmCTest::RunCommand(std::vector const& args, } break; default: { - cmCTestLog(this, ERROR_MESSAGE, exception.second << std::endl); + cmCTestLog(this, ERROR_MESSAGE, exception.second, '\n'); stdErr->append(exception.second); result = false; } break; @@ -3794,8 +3764,7 @@ bool cmCTest::CompressString(std::string& str) ret = deflate(&strm, Z_FINISH); if (ret != Z_STREAM_END) { - cmCTestLog(this, ERROR_MESSAGE, - "Error during gzip compression." << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Error during gzip compression.\n"); return false; } @@ -3841,7 +3810,7 @@ bool cmCTest::StartResultingXML(Part part, char const* name, int submitIndex, } if (!this->OpenOutputFile(this->Impl->CurrentTag, ostr.str(), xofs, true)) { cmCTestLog(this, ERROR_MESSAGE, - "Cannot create resulting XML file: " << ostr.str() << '\n'); + "Cannot create resulting XML file: ", ostr.str(), '\n'); return false; } this->AddSubmitFile(part, ostr.str()); @@ -3869,8 +3838,8 @@ bool cmCTest::StartLogFile(char const* name, int submitIndex, } ostr << ".log"; if (!this->OpenOutputFile("Temporary", ostr.str(), xofs)) { - cmCTestLog(this, ERROR_MESSAGE, - "Cannot create log file: " << ostr.str() << '\n'); + cmCTestLog(this, ERROR_MESSAGE, "Cannot create log file: ", ostr.str(), + '\n'); return false; } return true; @@ -3924,14 +3893,13 @@ bool cmCTest::ConvertInstrumentationJSONFileToXML(std::string const& fpath, this->Impl->parseState = cmJSONState(fpath, &root); if (!this->Impl->parseState.errors.empty()) { cmCTestLog(this, ERROR_MESSAGE, - this->Impl->parseState.GetErrorMessage(true) << std::endl); + this->Impl->parseState.GetErrorMessage(true), '\n'); return false; } if (root.type() != Json::objectValue) { - cmCTestLog(this, ERROR_MESSAGE, - "Expected object, found " << root.type() << " for " - << root.asString() << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Expected object, found ", root.type(), + " for ", root.asString(), '\n'); return false; } @@ -3942,9 +3910,8 @@ bool cmCTest::ConvertInstrumentationJSONFileToXML(std::string const& fpath, }; for (std::string const& required_member : required_members) { if (!root.isMember(required_member)) { - cmCTestLog(this, ERROR_MESSAGE, - fpath << " is missing the '" << required_member << "' key" - << std::endl); + cmCTestLog(this, ERROR_MESSAGE, fpath, " is missing the '", + required_member, "' key\n"); return false; } } diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 649765d2aa..fb04c7deea 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -6,9 +6,9 @@ #include #include +#include #include #include -#include #include #include #include @@ -19,6 +19,7 @@ #include "cmDuration.h" #include "cmProcessOutput.h" #include "cmStdIoTerminal.h" +#include "cmStringAlgorithms.h" class cmake; class cmCMakePresetsArgs; @@ -485,23 +486,11 @@ private: std::unique_ptr Impl; }; -#define cmCTestLog(ctSelf, logType, msg) \ - do { \ - std::ostringstream cmCTestLog_msg; \ - cmCTestLog_msg << msg; \ - (ctSelf)->Log(cmCTest::logType, cmCTestLog_msg.str()); \ - } while (false) +#define cmCTestLog(ctSelf, logType, ...) \ + (ctSelf)->Log(cmCTest::logType, cmStrCat("", __VA_ARGS__)) -#define cmCTestOptionalLog(ctSelf, logType, msg, suppress) \ - do { \ - std::ostringstream cmCTestLog_msg; \ - cmCTestLog_msg << msg; \ - (ctSelf)->Log(cmCTest::logType, cmCTestLog_msg.str(), suppress); \ - } while (false) +#define cmCTestOptionalLog(ctSelf, logType, suppress, ...) \ + (ctSelf)->Log(cmCTest::logType, cmStrCat("", __VA_ARGS__), suppress) -#define cmCTestColorLog(ctSelf, logType, attrs, msg) \ - do { \ - std::ostringstream cmCTestLog_msg; \ - cmCTestLog_msg << msg; \ - (ctSelf)->Log(cmCTest::logType, cmCTestLog_msg.str(), attrs); \ - } while (false) +#define cmCTestColorLog(ctSelf, logType, attrs, ...) \ + (ctSelf)->Log(cmCTest::logType, cmStrCat("", __VA_ARGS__), attrs) diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx index c570b7784f..43ebeae402 100644 --- a/Source/cmExportCommand.cxx +++ b/Source/cmExportCommand.cxx @@ -3,6 +3,7 @@ #include "cmExportCommand.h" #include +#include #include #include diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h index 23b6b82601..0c0749c931 100644 --- a/Source/cmStringAlgorithms.h +++ b/Source/cmStringAlgorithms.h @@ -382,6 +382,19 @@ inline void cmStripSuffixIfExists(std::string& str, cm::string_view suffix) } } +/** Pad a string to a given width. */ +inline std::string cmPadToWidth(int width, std::string text) +{ + if (width <= 0) { + return text; + } + std::size_t width_size = static_cast(width); + if (width_size > text.size()) { + text.insert(0, width_size - text.size(), ' '); + } + return text; +} + /** Converts a string to long. Expects that the whole string is an integer. */ bool cmStrToLong(char const* str, long* value); bool cmStrToLong(std::string const& str, long* value);