[Cmake-commits] [cmake-commits] king committed cmCTestCoverageCommand.cxx 1.8 1.9 cmCTestCoverageCommand.h 1.7 1.8 cmCTestCoverageHandler.cxx 1.66 1.67 cmCTestCoverageHandler.h 1.18 1.19
cmake-commits at cmake.org
cmake-commits at cmake.org
Mon Mar 2 15:33:20 EST 2009
Update of /cvsroot/CMake/CMake/Source/CTest
In directory public:/mounts/ram/cvs-serv18706/Source/CTest
Modified Files:
cmCTestCoverageCommand.cxx cmCTestCoverageCommand.h
cmCTestCoverageHandler.cxx cmCTestCoverageHandler.h
Log Message:
ENH: Teach ctest_coverage to filter with LABELS
This teaches ctest_coverage() to report only coverage of files labeled
with at least one label given by a new LABELS option.
Index: cmCTestCoverageHandler.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestCoverageHandler.cxx,v
retrieving revision 1.66
retrieving revision 1.67
diff -C 2 -d -r1.66 -r1.67
*** cmCTestCoverageHandler.cxx 2 Mar 2009 20:33:03 -0000 1.66
--- cmCTestCoverageHandler.cxx 2 Mar 2009 20:33:18 -0000 1.67
***************
*** 18,21 ****
--- 18,22 ----
#include "cmCTest.h"
#include "cmake.h"
+ #include "cmMakefile.h"
#include "cmSystemTools.h"
#include "cmGeneratedFileStream.h"
***************
*** 25,28 ****
--- 26,31 ----
#include <cmsys/RegularExpression.hxx>
#include <cmsys/Glob.hxx>
+ #include <cmsys/stl/iterator>
+ #include <cmsys/stl/algorithm>
#include <stdlib.h>
***************
*** 157,160 ****
--- 160,164 ----
this->LabelIdMap.clear();
this->Labels.clear();
+ this->LabelFilter.clear();
}
***************
*** 208,211 ****
--- 212,220 ----
const char* binDir)
{
+ if(this->IsFilteredOut(file))
+ {
+ return false;
+ }
+
std::vector<cmsys::RegularExpression>::iterator sit;
for ( sit = this->CustomCoverageExcludeRegex.begin();
***************
*** 1818,1819 ****
--- 1827,1864 ----
}
}
+
+ //----------------------------------------------------------------------------
+ void
+ cmCTestCoverageHandler::SetLabelFilter(std::set<cmStdString> const& labels)
+ {
+ this->LabelFilter.clear();
+ for(std::set<cmStdString>::const_iterator li = labels.begin();
+ li != labels.end(); ++li)
+ {
+ this->LabelFilter.insert(this->GetLabelId(*li));
+ }
+ }
+
+ //----------------------------------------------------------------------
+ bool cmCTestCoverageHandler::IsFilteredOut(std::string const& source)
+ {
+ // If there is no label filter then nothing is filtered out.
+ if(this->LabelFilter.empty())
+ {
+ return false;
+ }
+
+ // The source is filtered out if it does not have any labels in
+ // common with the filter set.
+ std::vector<int> ids;
+ std::string shortSrc = this->CTest->GetShortPathToFile(source.c_str());
+ LabelMapType::const_iterator li = this->SourceLabels.find(shortSrc);
+ if(li != this->SourceLabels.end() && !li->second.empty())
+ {
+ cmsys_stl::set_intersection
+ (li->second.begin(), li->second.end(),
+ this->LabelFilter.begin(), this->LabelFilter.end(),
+ cmsys_stl::back_inserter(ids));
+ }
+ return ids.empty();
+ }
Index: cmCTestCoverageHandler.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestCoverageHandler.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -C 2 -d -r1.18 -r1.19
*** cmCTestCoverageHandler.h 13 Feb 2009 20:17:06 -0000 1.18
--- cmCTestCoverageHandler.h 2 Mar 2009 20:33:18 -0000 1.19
***************
*** 51,54 ****
--- 51,57 ----
void PopulateCustomVectors(cmMakefile *mf);
+ /** Report coverage only for sources with these labels. */
+ void SetLabelFilter(std::set<cmStdString> const& labels);
+
private:
bool ShouldIDoCoverage(const char* file, const char* srcDir,
***************
*** 154,157 ****
--- 157,164 ----
void LoadLabels(const char* fname);
void WriteXMLLabels(std::ofstream& os, std::string const& source);
+
+ // Label-based filtering.
+ std::set<int> LabelFilter;
+ bool IsFilteredOut(std::string const& source);
};
Index: cmCTestCoverageCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestCoverageCommand.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C 2 -d -r1.7 -r1.8
*** cmCTestCoverageCommand.h 20 Feb 2009 20:51:03 -0000 1.7
--- cmCTestCoverageCommand.h 2 Mar 2009 20:33:18 -0000 1.8
***************
*** 61,69 ****
{
return
! " ctest_coverage([BUILD build_dir] [RETURN_VALUE res] [APPEND])\n"
"Perform the coverage of the given build directory and stores results "
"in Coverage.xml. The second argument is a variable that will hold "
"value."
"\n"
CTEST_COMMAND_APPEND_OPTION_DOCS;
}
--- 61,73 ----
{
return
! " ctest_coverage([BUILD build_dir] [RETURN_VALUE res] [APPEND]\n"
! " [LABELS label1 [label2 [...]]])\n"
"Perform the coverage of the given build directory and stores results "
"in Coverage.xml. The second argument is a variable that will hold "
"value."
"\n"
+ "The LABELS option filters the coverage report to include only "
+ "source files labeled with at least one of the labels specified."
+ "\n"
CTEST_COMMAND_APPEND_OPTION_DOCS;
}
***************
*** 73,76 ****
--- 77,92 ----
protected:
cmCTestGenericHandler* InitializeHandler();
+
+ virtual bool CheckArgumentKeyword(std::string const& arg);
+ virtual bool CheckArgumentValue(std::string const& arg);
+
+ enum
+ {
+ ArgumentDoingLabels = Superclass::ArgumentDoingLast1,
+ ArgumentDoingLast2
+ };
+
+ bool LabelsMentioned;
+ std::set<cmStdString> Labels;
};
Index: cmCTestCoverageCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestCoverageCommand.cxx,v
retrieving revision 1.8
retrieving revision 1.9
diff -C 2 -d -r1.8 -r1.9
*** cmCTestCoverageCommand.cxx 29 Mar 2006 17:33:41 -0000 1.8
--- cmCTestCoverageCommand.cxx 2 Mar 2009 20:33:16 -0000 1.9
***************
*** 18,22 ****
#include "cmCTest.h"
! #include "cmCTestGenericHandler.h"
cmCTestGenericHandler* cmCTestCoverageCommand::InitializeHandler()
--- 18,22 ----
#include "cmCTest.h"
! #include "cmCTestCoverageHandler.h"
cmCTestGenericHandler* cmCTestCoverageCommand::InitializeHandler()
***************
*** 25,30 ****
"CoverageCommand", "CTEST_COVERAGE_COMMAND");
! cmCTestGenericHandler* handler
! = this->CTest->GetInitializedHandler("coverage");
if ( !handler )
{
--- 25,30 ----
"CoverageCommand", "CTEST_COVERAGE_COMMAND");
! cmCTestCoverageHandler* handler = static_cast<cmCTestCoverageHandler*>(
! this->CTest->GetInitializedHandler("coverage"));
if ( !handler )
{
***************
*** 32,38 ****
--- 32,71 ----
return 0;
}
+
+ // If a LABELS option was given, select only files with the labels.
+ if(this->LabelsMentioned)
+ {
+ handler->SetLabelFilter(this->Labels);
+ }
+
return handler;
}
+ //----------------------------------------------------------------------------
+ bool cmCTestCoverageCommand::CheckArgumentKeyword(std::string const& arg)
+ {
+ // Look for arguments specific to this command.
+ if(arg == "LABELS")
+ {
+ this->ArgumentDoing = ArgumentDoingLabels;
+ this->LabelsMentioned = true;
+ return true;
+ }
+ // Look for other arguments.
+ return this->Superclass::CheckArgumentKeyword(arg);
+ }
+ //----------------------------------------------------------------------------
+ bool cmCTestCoverageCommand::CheckArgumentValue(std::string const& arg)
+ {
+ // Handle states specific to this command.
+ if(this->ArgumentDoing == ArgumentDoingLabels)
+ {
+ this->Labels.insert(arg);
+ return true;
+ }
+
+ // Look for other arguments.
+ return this->Superclass::CheckArgumentValue(arg);
+ }
More information about the Cmake-commits
mailing list