llvm-cov: Actually use the command line arguments when reporting
authorJustin Bogner <mail@justinbogner.com>
Sat, 14 Feb 2015 02:05:05 +0000 (02:05 +0000)
committerJustin Bogner <mail@justinbogner.com>
Sat, 14 Feb 2015 02:05:05 +0000 (02:05 +0000)
This code didn't really make sense as is. If a filename is passed in,
the user obviously wants the coverage *for that file*, not *for
everything*.

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

test/tools/llvm-cov/Inputs/report.covmapping
test/tools/llvm-cov/report.cpp
tools/llvm-cov/CodeCoverage.cpp
tools/llvm-cov/CoverageReport.cpp
tools/llvm-cov/CoverageReport.h

index 32d84bc7273adbe5264467ac5991e518cfda38ce..5d0bfc116816488ed3f75b5346441c0011d3b7ad 100644 (file)
Binary files a/test/tools/llvm-cov/Inputs/report.covmapping and b/test/tools/llvm-cov/Inputs/report.covmapping differ
index 297322a775d7266d024ac94cf04ef7e790d8590c..570012e4e4067c80290a795db028b27fee241b08 100644 (file)
@@ -1,7 +1,21 @@
-// RUN: llvm-cov report %S/Inputs/report.covmapping -instr-profile %S/Inputs/report.profdata -no-colors 2>&1 | FileCheck %s
+// RUN: llvm-cov report %S/Inputs/report.covmapping -instr-profile %S/Inputs/report.profdata -no-colors -filename-equivalence 2>&1 | FileCheck %s
+// RUN: llvm-cov report %S/Inputs/report.covmapping -instr-profile %S/Inputs/report.profdata -no-colors -filename-equivalence report.cpp 2>&1 | FileCheck -check-prefix=FILT-NEXT %s
 
 
-// CHECK: Filename                    Regions    Miss   Cover Functions  Executed
-// CHECK: TOTAL                             5       2  60.00%         4    75.00%
+// CHECK:      Filename   Regions  Miss   Cover  Functions  Executed
+// CHECK-NEXT: ---
+// CHECK-NEXT: report.cpp       5     2  60.00%          4    75.00%
+// CHECK-NEXT: ---
+// CHECK-NEXT: TOTAL            5     2  60.00%          4    75.00%
+
+// FILT: File 'report.cpp':
+// FILT-NEXT: Name        Regions  Miss   Cover  Lines  Miss   Cover
+// FILT-NEXT: ---
+// FILT-NEXT: _Z3foob           2     1  50.00%      4     2  50.00%
+// FILT-NEXT: _Z3barv           1     0 100.00%      2     0 100.00%
+// FILT-NEXT: _Z4funcv          1     1   0.00%      2     2   0.00%
+// FILT-NEXT: main              1     0 100.00%      5     0 100.00%
+// FILT-NEXT: ---
+// FILT-NEXT: TOTAL             5     2  60.00%     13     4  69.23%
 
 void foo(bool cond) {
   if (cond) {
 
 void foo(bool cond) {
   if (cond) {
index feaa3fcd857213a5b412ba2e749be78417989442..cf8ab3377979aab5bf2886fca7e69aecfb1863e3 100644 (file)
@@ -324,10 +324,11 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
 
     for (const auto &File : InputSourceFiles) {
       SmallString<128> Path(File);
 
     for (const auto &File : InputSourceFiles) {
       SmallString<128> Path(File);
-      if (std::error_code EC = sys::fs::make_absolute(Path)) {
-        errs() << "error: " << File << ": " << EC.message();
-        return 1;
-      }
+      if (!CompareFilenamesOnly)
+        if (std::error_code EC = sys::fs::make_absolute(Path)) {
+          errs() << "error: " << File << ": " << EC.message();
+          return 1;
+        }
       SourceFiles.push_back(Path.str());
     }
     return 0;
       SourceFiles.push_back(Path.str());
     }
     return 0;
@@ -459,12 +460,10 @@ int CodeCoverageTool::report(int argc, const char **argv,
     return 1;
 
   CoverageReport Report(ViewOpts, std::move(Coverage));
     return 1;
 
   CoverageReport Report(ViewOpts, std::move(Coverage));
-  if (SourceFiles.empty() && Filters.empty()) {
+  if (SourceFiles.empty())
     Report.renderFileReports(llvm::outs());
     Report.renderFileReports(llvm::outs());
-    return 0;
-  }
-
-  Report.renderFunctionReports(llvm::outs());
+  else
+    Report.renderFunctionReports(SourceFiles, llvm::outs());
   return 0;
 }
 
   return 0;
 }
 
index db0754268c30b1fc360259023c17a1678256ddd5..497c2f88f2689465d48bff343162b206f7eca96d 100644 (file)
@@ -155,9 +155,10 @@ void CoverageReport::render(const FunctionCoverageSummary &Function,
   OS << "\n";
 }
 
   OS << "\n";
 }
 
-void CoverageReport::renderFunctionReports(raw_ostream &OS) {
+void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
+                                           raw_ostream &OS) {
   bool isFirst = true;
   bool isFirst = true;
-  for (StringRef Filename : Coverage->getUniqueSourceFiles()) {
+  for (StringRef Filename : Files) {
     if (isFirst)
       isFirst = false;
     else
     if (isFirst)
       isFirst = false;
     else
index 78e49d9b7140a86be51184ef233ea6217653c903..7ec3df90b8f92d32dc10cceef06bfbbec75896fd 100644 (file)
@@ -32,7 +32,7 @@ public:
                  std::unique_ptr<coverage::CoverageMapping> Coverage)
       : Options(Options), Coverage(std::move(Coverage)) {}
 
                  std::unique_ptr<coverage::CoverageMapping> Coverage)
       : Options(Options), Coverage(std::move(Coverage)) {}
 
-  void renderFunctionReports(raw_ostream &OS);
+  void renderFunctionReports(ArrayRef<std::string> Files, raw_ostream &OS);
 
   void renderFileReports(raw_ostream &OS);
 };
 
   void renderFileReports(raw_ostream &OS);
 };