From 32242affea45eb3c3ffa2691657e970eaac49799 Mon Sep 17 00:00:00 2001 From: Zach Mullen Date: Tue, 31 Aug 2010 10:41:23 -0400 Subject: [PATCH] Added CTest command --print-labels This command allows a user to quickly see the list of all available test labels. The labels are also printed in verbose show only mode, alongside their corresponding tests. --- Source/CTest/cmCTestMultiProcessHandler.cxx | 42 +++++++++++++++++++++ Source/CTest/cmCTestMultiProcessHandler.h | 1 + Source/CTest/cmCTestTestHandler.cxx | 9 ++++- Source/cmCTest.cxx | 6 +++ Source/cmCTest.h | 3 ++ Source/ctest.cxx | 5 ++- Tests/CMakeLists.txt | 5 +++ 7 files changed, 68 insertions(+), 3 deletions(-) diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index d50eaaa81f..0d14c2d74b 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -516,11 +516,13 @@ void cmCTestMultiProcessHandler::PrintTestList() { this->TestHandler->SetMaxIndex(this->FindMaxIndex()); int count = 0; + for (PropertiesMap::iterator it = this->Properties.begin(); it != this->Properties.end(); ++it) { count++; cmCTestTestHandler::cmCTestTestProperties& p = *it->second; + //push working dir std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory(); cmSystemTools::ChangeDirectory(p.Directory.c_str()); @@ -530,6 +532,20 @@ void cmCTestMultiProcessHandler::PrintTestList() testRun.SetTestProperties(&p); testRun.ComputeArguments(); //logs the command in verbose mode + if(p.Labels.size()) //print the labels + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Labels:"); + } + for(std::vector::iterator label = p.Labels.begin(); + label != p.Labels.end(); ++label) + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " " << *label); + } + if(p.Labels.size()) //print the labels + { + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl); + } + if (this->TestHandler->MemCheck) { cmCTestLog(this->CTest, HANDLER_OUTPUT, " Memory Check"); @@ -548,10 +564,36 @@ void cmCTestMultiProcessHandler::PrintTestList() //pop working dir cmSystemTools::ChangeDirectory(current_dir.c_str()); } + cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl << "Total Tests: " << this->Total << std::endl); } +void cmCTestMultiProcessHandler::PrintLabels() +{ + std::set allLabels; + for (PropertiesMap::iterator it = this->Properties.begin(); + it != this->Properties.end(); ++it) + { + cmCTestTestHandler::cmCTestTestProperties& p = *it->second; + allLabels.insert(p.Labels.begin(), p.Labels.end()); + } + + if(allLabels.size()) + { + cmCTestLog(this->CTest, HANDLER_OUTPUT, "All Labels:" << std::endl); + } + else + { + cmCTestLog(this->CTest, HANDLER_OUTPUT, "No Labels Exist" << std::endl); + } + for(std::set::iterator label = allLabels.begin(); + label != allLabels.end(); ++label) + { + cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << *label << std::endl); + } +} + //--------------------------------------------------------- void cmCTestMultiProcessHandler::CheckResume() { diff --git a/Source/CTest/cmCTestMultiProcessHandler.h b/Source/CTest/cmCTestMultiProcessHandler.h index cc330f7a6d..1483440c60 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.h +++ b/Source/CTest/cmCTestMultiProcessHandler.h @@ -39,6 +39,7 @@ public: void SetParallelLevel(size_t); virtual void RunTests(); void PrintTestList(); + void PrintLabels(); void SetPassFailVectors(std::vector* passed, std::vector* failed) diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index a4a48633e3..6dd348def3 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -567,7 +567,7 @@ int cmCTestTestHandler::ProcessHandler() if (total == 0) { - if ( !this->CTest->GetShowOnly() ) + if ( !this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels() ) { cmCTestLog(this->CTest, ERROR_MESSAGE, "No tests were found!!!" << std::endl); @@ -1079,7 +1079,12 @@ void cmCTestTestHandler::ProcessDirectory(std::vector &passed, parallel->SetPassFailVectors(&passed, &failed); this->TestResults.clear(); parallel->SetTestResults(&this->TestResults); - if(this->CTest->GetShowOnly()) + + if(this->CTest->ShouldPrintLabels()) + { + parallel->PrintLabels(); + } + else if(this->CTest->GetShowOnly()) { parallel->PrintTestList(); } diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index d12fde0f8d..dcdc8e15b2 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -304,6 +304,7 @@ cmCTest::cmCTest() this->ShowOnly = false; this->RunConfigurationScript = false; this->UseHTTP10 = false; + this->PrintLabels = false; this->CompressTestOutput = true; this->ComputedCompressOutput = false; this->TestModel = cmCTest::EXPERIMENTAL; @@ -1877,6 +1878,11 @@ void cmCTest::HandleCommandLineArguments(size_t &i, this->CompressTestOutput = false; } + if(this->CheckArgument(arg, "--print-labels")) + { + this->PrintLabels = true; + } + if(this->CheckArgument(arg, "--http1.0")) { this->UseHTTP10 = true; diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 3d7d1179b8..e54a205c36 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -210,6 +210,8 @@ public: bool ShouldUseHTTP10() { return this->UseHTTP10; } + bool ShouldPrintLabels() { return this->PrintLabels; } + bool ShouldCompressTestOutput(); std::string GetCDashVersion(); @@ -413,6 +415,7 @@ private: bool ProduceXML; bool LabelSummary; bool UseHTTP10; + bool PrintLabels; bool Failover; bool BatchJobs; diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 24921c428f..3937d8d17b 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -152,7 +152,7 @@ static const char * cmDocumentationOptions[][3] = "popups and interactive " "debugging."}, {"--no-label-summary", "Disable timing summary information for labels.", - "This option tells ctest to not print summary information for each label " + "This option tells ctest not to print summary information for each label " "associated with the tests run. If there are no labels on the " "tests, nothing extra is printed."}, {"--build-and-test", "Configure, build and run a test.", @@ -229,6 +229,9 @@ static const char * cmDocumentationOptions[][3] = "This flag will turn off automatic compression of test output. Use this " "to maintain compatibility with an older version of CDash which doesn't " "support compressed test output."}, + {"--print-labels", "Print all available test labels.", + "This option will not run any tests, it will simply print the list of " + "all labels associated with the test set."}, {"--help-command []", "Show help for a single command and exit.", "Prints the help for the command to stdout or to the specified file." }, {"--help-command-list []", "List available commands and exit.", diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 5383bda97b..8e8d0ca6f2 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1315,6 +1315,11 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ --output-log "${CMake_BINARY_DIR}/Tests/CTestTestParallel/testOutput.log" ) + ADD_TEST(CTestTestPrintLabels ${CMAKE_CTEST_COMMAND} --print-labels) + SET_TESTS_PROPERTIES(CTestTestPrintLabels PROPERTIES LABELS "Label1;Label2") + SET_TESTS_PROPERTIES(CTestTestPrintLabels PROPERTIES PASS_REGULAR_EXPRESSION + "All Labels:.* Label1.* Label2") + CONFIGURE_FILE( "${CMake_SOURCE_DIR}/Tests/CTestTestResourceLock/test.cmake.in" "${CMake_BINARY_DIR}/Tests/CTestTestResourceLock/test.cmake"