diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 18d9346c43..24c1857b08 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -535,14 +535,13 @@ int cmCTestTestHandler::ProcessHandler() << static_cast(percent + .5f) << "% tests passed, " << failed.size() << " tests failed out of " << total << std::endl); - - if (!this->CTest->GetLabelsForSubprojects().empty() && - this->CTest->GetSubprojectSummary()) { - this->PrintSubprojectSummary(); - } else if (this->CTest->GetLabelSummary()) { - this->PrintLabelSummary(); + if ((!this->CTest->GetLabelsForSubprojects().empty() && + this->CTest->GetSubprojectSummary())) { + this->PrintLabelOrSubprojectSummary(true); + } + if (this->CTest->GetLabelSummary()) { + this->PrintLabelOrSubprojectSummary(false); } - char realBuf[1024]; sprintf(realBuf, "%6.2f sec", clock_finish - clock_start); cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, @@ -620,19 +619,32 @@ int cmCTestTestHandler::ProcessHandler() return 0; } -void cmCTestTestHandler::PrintLabelSummary() +void cmCTestTestHandler::PrintLabelOrSubprojectSummary(bool doSubProject) { - cmCTestTestHandler::ListOfTests::iterator it = this->TestList.begin(); + // collect subproject labels + std::vector subprojects = + this->CTest->GetLabelsForSubprojects(); std::map labelTimes; std::map labelCounts; std::set labels; - // initialize maps std::string::size_type maxlen = 0; - for (; it != this->TestList.end(); ++it) { + // initialize maps + for (cmCTestTestHandler::ListOfTests::iterator it = this->TestList.begin(); + it != this->TestList.end(); ++it) { cmCTestTestProperties& p = *it; - if (!p.Labels.empty()) { - for (std::vector::iterator l = p.Labels.begin(); - l != p.Labels.end(); ++l) { + for (std::vector::iterator l = p.Labels.begin(); + l != p.Labels.end(); ++l) { + // first check to see if the current label is a subproject label + bool isSubprojectLabel = false; + std::vector::iterator subproject = + std::find(subprojects.begin(), subprojects.end(), *l); + if (subproject != subprojects.end()) { + isSubprojectLabel = true; + } + // if we are doing sub projects and this label is one, then use it + // if we are not doing sub projects and the label is not one use it + if ((doSubProject && isSubprojectLabel) || + (!doSubProject && !isSubprojectLabel)) { if ((*l).size() > maxlen) { maxlen = (*l).size(); } @@ -642,22 +654,30 @@ void cmCTestTestHandler::PrintLabelSummary() } } } - cmCTestTestHandler::TestResultsVector::iterator ri = - this->TestResults.begin(); // fill maps - for (; ri != this->TestResults.end(); ++ri) { + for (cmCTestTestHandler::TestResultsVector::iterator ri = + this->TestResults.begin(); + ri != this->TestResults.end(); ++ri) { cmCTestTestResult& result = *ri; cmCTestTestProperties& p = *result.Properties; - if (!p.Labels.empty()) { - for (std::vector::iterator l = p.Labels.begin(); - l != p.Labels.end(); ++l) { + for (std::vector::iterator l = p.Labels.begin(); + l != p.Labels.end(); ++l) { + // only use labels found in labels + if (labels.find(*l) != labels.end()) { labelTimes[*l] += result.ExecutionTime; ++labelCounts[*l]; } } } + // if no labels are found return and print nothing + if (labels.empty()) { + return; + } // now print times - if (!labels.empty()) { + if (doSubProject) { + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, + "\nSubproject Time Summary:", this->Quiet); + } else { cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\nLabel Time Summary:", this->Quiet); } @@ -675,7 +695,6 @@ void cmCTestTestHandler::PrintLabelSummary() labelCountStr << "s"; } labelCountStr << ")"; - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n" << label << " = " << buf << " " << labelCountStr.str(), @@ -684,92 +703,12 @@ void cmCTestTestHandler::PrintLabelSummary() *this->LogFile << "\n" << *i << " = " << buf << "\n"; } } - if (!labels.empty()) { - if (this->LogFile) { - *this->LogFile << "\n"; - } - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n", this->Quiet); + if (this->LogFile) { + *this->LogFile << "\n"; } + cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n", this->Quiet); } -void cmCTestTestHandler::PrintSubprojectSummary() -{ - std::vector subprojects = - this->CTest->GetLabelsForSubprojects(); - - cmCTestTestHandler::ListOfTests::iterator it = this->TestList.begin(); - std::map labelTimes; - std::map labelCounts; - std::set labels; - // initialize maps - std::string::size_type maxlen = 0; - for (; it != this->TestList.end(); ++it) { - cmCTestTestProperties& p = *it; - for (std::vector::iterator l = p.Labels.begin(); - l != p.Labels.end(); ++l) { - std::vector::iterator subproject = - std::find(subprojects.begin(), subprojects.end(), *l); - if (subproject != subprojects.end()) { - if ((*l).size() > maxlen) { - maxlen = (*l).size(); - } - labels.insert(*l); - labelTimes[*l] = 0; - labelCounts[*l] = 0; - } - } - } - cmCTestTestHandler::TestResultsVector::iterator ri = - this->TestResults.begin(); - // fill maps - for (; ri != this->TestResults.end(); ++ri) { - cmCTestTestResult& result = *ri; - cmCTestTestProperties& p = *result.Properties; - for (std::vector::iterator l = p.Labels.begin(); - l != p.Labels.end(); ++l) { - std::vector::iterator subproject = - std::find(subprojects.begin(), subprojects.end(), *l); - if (subproject != subprojects.end()) { - labelTimes[*l] += result.ExecutionTime; - ++labelCounts[*l]; - } - } - } - // now print times - if (!labels.empty()) { - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, - "\nSubproject Time Summary:", this->Quiet); - } - for (std::set::const_iterator i = labels.begin(); - i != labels.end(); ++i) { - std::string label = *i; - label.resize(maxlen + 3, ' '); - - char buf[1024]; - sprintf(buf, "%6.2f sec", labelTimes[*i]); - - std::ostringstream labelCountStr; - labelCountStr << "(" << labelCounts[*i] << " test"; - if (labelCounts[*i] > 1) { - labelCountStr << "s"; - } - labelCountStr << ")"; - - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n" - << label << " = " << buf << " " - << labelCountStr.str(), - this->Quiet); - if (this->LogFile) { - *this->LogFile << "\n" << *i << " = " << buf << "\n"; - } - } - if (!labels.empty()) { - if (this->LogFile) { - *this->LogFile << "\n"; - } - cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n", this->Quiet); - } -} void cmCTestTestHandler::CheckLabelFilterInclude(cmCTestTestProperties& it) { // if not using Labels to filter then return diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 965552c035..4c5b55fb3f 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -232,8 +232,7 @@ private: */ virtual void GenerateDartOutput(cmXMLWriter& xml); - void PrintLabelSummary(); - void PrintSubprojectSummary(); + void PrintLabelOrSubprojectSummary(bool isSubProject); /** * Run the tests for a directory and any subdirectories diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestConfigCTestScript-stdout.txt b/Tests/RunCMake/ctest_labels_for_subprojects/CTestConfigCTestScript-stdout.txt index ae00e51b7a..e3be144648 100644 --- a/Tests/RunCMake/ctest_labels_for_subprojects/CTestConfigCTestScript-stdout.txt +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestConfigCTestScript-stdout.txt @@ -4,4 +4,7 @@ Subproject Time Summary: MyExperimentalFeature += +[0-9.]+ sec \(5 tests\) MyProductionCode += +[0-9.]+ sec \(1 test\) + +Label Time Summary: +NotASubproject += +[0-9.]+ sec \(6 tests\) ++ Total Test time \(real\) = +[0-9.]+ sec diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariable-stdout.txt b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariable-stdout.txt index ae00e51b7a..e3be144648 100644 --- a/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariable-stdout.txt +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariable-stdout.txt @@ -4,4 +4,7 @@ Subproject Time Summary: MyExperimentalFeature += +[0-9.]+ sec \(5 tests\) MyProductionCode += +[0-9.]+ sec \(1 test\) + +Label Time Summary: +NotASubproject += +[0-9.]+ sec \(6 tests\) ++ Total Test time \(real\) = +[0-9.]+ sec diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-stdout.txt b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-stdout.txt index a78a99a4f1..20c6c860fb 100644 --- a/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-stdout.txt +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLine-stdout.txt @@ -3,4 +3,7 @@ Subproject Time Summary: MyThirdPartyDependency += +[0-9.]+ sec \(1 test\) + +Label Time Summary: +NotASubproject += +[0-9.]+ sec \(1 test\) ++ Total Test time \(real\) = +[0-9.]+ sec diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfig-stdout.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfig-stdout.txt index 01851fd7a0..bec6b14d0b 100644 --- a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfig-stdout.txt +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfig-stdout.txt @@ -3,4 +3,7 @@ Subproject Time Summary: MySubproject += +[0-9.]+ sec \(2 tests\) + +Label Time Summary: +NotASubproject += +[0-9.]+ sec \(1 test\) ++ Total Test time \(real\) = +[0-9.]+ sec diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfigNoSummary-stdout.txt b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfigNoSummary-stdout.txt index 0209bfe54f..1ac5530fd9 100644 --- a/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfigNoSummary-stdout.txt +++ b/Tests/RunCMake/ctest_labels_for_subprojects/ModuleVariableCTestConfigNoSummary-stdout.txt @@ -1,7 +1,6 @@ 67% tests passed, 1 tests failed out of 3 + Label Time Summary: -MySubproject += +[0-9.]+ sec \(2 tests\) NotASubproject += +[0-9.]+ sec \(1 test\) + Total Test time \(real\) = +[0-9.]+ sec