]> granicus.if.org Git - llvm/commitdiff
[llvm-cov] Hide files with no coverage from the index when filtering by name
authorSean Eveson <eveson.sean@gmail.com>
Tue, 3 Oct 2017 11:05:28 +0000 (11:05 +0000)
committerSean Eveson <eveson.sean@gmail.com>
Tue, 3 Oct 2017 11:05:28 +0000 (11:05 +0000)
Differential Revision: https://reviews.llvm.org/D38457

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314782 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-cov/dir-with-filtering.test
tools/llvm-cov/CoverageReport.cpp
tools/llvm-cov/CoverageReport.h
tools/llvm-cov/SourceCoverageView.h
tools/llvm-cov/SourceCoverageViewHTML.cpp
tools/llvm-cov/SourceCoverageViewHTML.h
tools/llvm-cov/SourceCoverageViewText.cpp
tools/llvm-cov/SourceCoverageViewText.h

index f3b68ddf7633f32f9cc9c3230a4a82954f797779..92494232b9b7b1c2c98e47692f1006c228d4c491 100644 (file)
@@ -32,6 +32,14 @@ TEXT-INDEX-ONE-FILE-NOT: dir-with-filtering2.cpp
 \r
 RUN: FileCheck -input-file=%t.text_one_file/coverage/tmp/dir-with-filtering1.cpp.txt %s -check-prefix=TEXT-FILE1\r
 \r
+// Test TEXT index file with all functions in one file filtered out\r
+\r
+RUN: llvm-cov show %S/Inputs/dir-with-filtering.covmapping -o %t.text_one_func -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs -name=main\r
+RUN: FileCheck -input-file=%t.text_one_func/index.txt %s -check-prefix=TEXT-INDEX-ONE-FUNC\r
+\r
+TEXT-INDEX-ONE-FUNC-NOT: Files which contain no functions\r
+TEXT-INDEX-ONE-FUNC-NOT: dir-with-filtering2.cpp\r
+\r
 // Test HTML both files\r
 \r
 RUN: llvm-profdata merge %S/Inputs/dir-with-filtering.proftext -o %t.profdata\r
@@ -67,3 +75,11 @@ HTML-INDEX-ONE-FILE: dir-with-filtering1.cpp{{.*}}100.00% (1/1){{.*}}100.00% (4/
 HTML-INDEX-ONE-FILE-NOT: dir-with-filtering2.cpp\r
 \r
 RUN: FileCheck -input-file=%t.html_one_file/coverage/tmp/dir-with-filtering1.cpp.html %s -check-prefix=HTML-FILE1\r
+\r
+// Test HTML index file with all functions in one file filtered out\r
+\r
+RUN: llvm-cov show %S/Inputs/dir-with-filtering.covmapping -format html -o %t.html_one_func -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs -name=main\r
+RUN: FileCheck -input-file=%t.html_one_func/index.html %s -check-prefix=HTML-INDEX-ONE-FUNC\r
+\r
+HTML-INDEX-ONE-FUNC-NOT: Files which contain no functions\r
+HTML-INDEX-ONE-FUNC-NOT: dir-with-filtering2.cpp\r
index 5c8ffe1216d00b0a13391bc304dce7e56e49b0bc..56745308b79a58924dda43d7abcd47ed98f0de87 100644 (file)
@@ -367,9 +367,9 @@ void CoverageReport::renderFileReports(raw_ostream &OS) const {
   renderFileReports(OS, UniqueSourceFiles, CoverageFiltersMatchAll());
 }
 
-void CoverageReport::renderFileReports(raw_ostream &OS,
-                                       ArrayRef<std::string> Files,
-                                       const CoverageFilter &Filters) const {
+void CoverageReport::renderFileReports(
+    raw_ostream &OS, ArrayRef<std::string> Files,
+    const CoverageFiltersMatchAll &Filters) const {
   FileCoverageSummary Totals("TOTAL");
   auto FileReports =
       prepareFileReports(Coverage, Totals, Files, Options, Filters);
@@ -405,7 +405,7 @@ void CoverageReport::renderFileReports(raw_ostream &OS,
       EmptyFiles = true;
   }
 
-  if (EmptyFiles) {
+  if (EmptyFiles && Filters.empty()) {
     OS << "\n"
        << "Files which contain no functions:\n";
 
index d78f2e4c2bdd5fad5f1b61e23e538bf4bab13760..4126c319f4355e7657a16efb8ffe189404dc9447 100644 (file)
@@ -50,7 +50,7 @@ public:
   /// Render file reports for the files specified in \p Files and the functions
   /// in \p Filters.
   void renderFileReports(raw_ostream &OS, ArrayRef<std::string> Files,
-                         const CoverageFilter &Filters) const;
+                         const CoverageFiltersMatchAll &Filters) const;
 };
 
 } // end namespace llvm
index 7c7e8781364242efaa20a3769af5cbac8e124740..24080284d8b43d6c6dbad7380d6a607a32735805 100644 (file)
@@ -22,7 +22,7 @@
 
 namespace llvm {
 
-class CoverageFilter;
+class CoverageFiltersMatchAll;
 class SourceCoverageView;
 
 /// \brief A view that represents a macro or include expansion.
@@ -113,7 +113,7 @@ public:
   /// \brief Create an index which lists reports for the given source files.
   virtual Error createIndexFile(ArrayRef<std::string> SourceFiles,
                                 const coverage::CoverageMapping &Coverage,
-                                const CoverageFilter &Filters) = 0;
+                                const CoverageFiltersMatchAll &Filters) = 0;
 
   /// @}
 };
index a031f1848252a315b236463630f5315c18d5cec8..b8fdf4483a7d086e736f10a88535f8ac013ec5d4 100644 (file)
@@ -366,7 +366,8 @@ void CoveragePrinterHTML::emitFileSummary(raw_ostream &OS, StringRef SF,
 
 Error CoveragePrinterHTML::createIndexFile(
     ArrayRef<std::string> SourceFiles,
-    const coverage::CoverageMapping &Coverage, const CoverageFilter &Filters) {
+    const coverage::CoverageMapping &Coverage,
+    const CoverageFiltersMatchAll &Filters) {
   // Emit the default stylesheet.
   auto CSSOrErr = createOutputStream("style", "css", /*InToplevel=*/true);
   if (Error E = CSSOrErr.takeError())
@@ -419,7 +420,7 @@ Error CoveragePrinterHTML::createIndexFile(
   // Emit links to files which don't contain any functions. These are normally
   // not very useful, but could be relevant for code which abuses the
   // preprocessor.
-  if (EmptyFiles) {
+  if (EmptyFiles && Filters.empty()) {
     OSRef << tag("p", "Files which contain no functions. (These "
                       "files contain code pulled into other files "
                       "by the preprocessor.)\n");
index e11111a5ad2bc876708011d388e89cbe24542828..978a75aecedf457d2c4a5f1a996b352623cee753 100644 (file)
@@ -30,7 +30,7 @@ public:
 
   Error createIndexFile(ArrayRef<std::string> SourceFiles,
                         const coverage::CoverageMapping &Coverage,
-                        const CoverageFilter &Filters) override;
+                        const CoverageFiltersMatchAll &Filters) override;
 
   CoveragePrinterHTML(const CoverageViewOptions &Opts)
       : CoveragePrinter(Opts) {}
index b2902df185d6ceb69fd5299d53450c2935b7bfc5..261f08d70227780d8db06d62fbda9b15b0e75641 100644 (file)
@@ -30,7 +30,8 @@ void CoveragePrinterText::closeViewFile(OwnedStream OS) {
 
 Error CoveragePrinterText::createIndexFile(
     ArrayRef<std::string> SourceFiles,
-    const coverage::CoverageMapping &Coverage, const CoverageFilter &Filters) {
+    const coverage::CoverageMapping &Coverage,
+    const CoverageFiltersMatchAll &Filters) {
   auto OSOrErr = createOutputStream("index", "txt", /*InToplevel=*/true);
   if (Error E = OSOrErr.takeError())
     return E;
index 3a04070d1acb97287d62acdb90897e91d8b7857b..5cf7caf79da134e6de8def9a7a00b0458dfd04a8 100644 (file)
@@ -28,7 +28,7 @@ public:
 
   Error createIndexFile(ArrayRef<std::string> SourceFiles,
                         const coverage::CoverageMapping &Coverage,
-                        const CoverageFilter &Filters) override;
+                        const CoverageFiltersMatchAll &Filters) override;
 
   CoveragePrinterText(const CoverageViewOptions &Opts)
       : CoveragePrinter(Opts) {}