[llvm-cov] Use less space to describe source names
authorVedant Kumar <vsk@apple.com>
Thu, 8 Sep 2016 00:56:48 +0000 (00:56 +0000)
committerVedant Kumar <vsk@apple.com>
Thu, 8 Sep 2016 00:56:48 +0000 (00:56 +0000)
In r279628, we made SourceCoverageView list the binary associated with a
view and started adding labels (e.g "Source: foo" or "Function: bar") to
everything. Condense this information a bit to unclutter reports.

llvm-svn: 280896

llvm/test/tools/llvm-cov/showProjectSummary.cpp
llvm/test/tools/llvm-cov/showTemplateInstantiations.cpp
llvm/tools/llvm-cov/CodeCoverage.cpp
llvm/tools/llvm-cov/SourceCoverageView.cpp
llvm/tools/llvm-cov/SourceCoverageView.h
llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
llvm/tools/llvm-cov/SourceCoverageViewHTML.h
llvm/tools/llvm-cov/SourceCoverageViewText.cpp
llvm/tools/llvm-cov/SourceCoverageViewText.h

index a2c1dee..b332914 100644 (file)
@@ -36,11 +36,8 @@ int main(int argc, char ** argv) {
 // HTML: <span>Code Coverage Report</span>
 // HTML: <div class='created-time'>
 // HTML: <span>Created:
-// HTML-FILE: <pre>Source:
-// HTML-FILE: showProjectSummary.cpp</pre>
-// HTML-FILE: <pre>Binary:
-// HTML-FILE: showProjectSummary.covmapping</pre>
-// HTML-FUNCTION: <pre>Function: main</pre>
+// HTML-FILE: <pre>Source: {{.*}}showProjectSummary.cpp (Binary: showProjectSummary.covmapping)</pre>
+// HTML-FUNCTION: <pre>main</pre>
 // HTML-UNCOVEREDLINE: <a href='#L8'>Go to first unexecuted line</a>
 // HTML-HEADER: <tr><td><span><pre>Line No.</pre></span></td>
 // HTML-HEADER: <td><span><pre>Count</pre></span></td>
index db9576d..40ac9d3 100644 (file)
@@ -12,7 +12,7 @@ int func(T x) {      // ALL-NEXT:    [[@LINE]]| 2|int func(T x) {
   int j = 1;         // ALL-NEXT:    [[@LINE]]| 0|  int j = 1;
 }                    // ALL-NEXT:    [[@LINE]]| 2|}
 
-                     // SHARED:       {{^ *(\| )?}}Function: _Z4funcIbEiT_:
+                     // SHARED:       {{^ *(\| )?}}_Z4funcIbEiT_:
                      // SHARED:       [[@LINE-9]]| 1|int func(T x) {
                      // SHARED-NEXT:  [[@LINE-9]]| 1|  if(x)
                      // SHARED-NEXT:  [[@LINE-9]]| 1|    return 0;
@@ -21,8 +21,8 @@ int func(T x) {      // ALL-NEXT:    [[@LINE]]| 2|int func(T x) {
                      // SHARED-NEXT:  [[@LINE-9]]| 0|  int j = 1;
                      // SHARED-NEXT:  [[@LINE-9]]| 1|}
 
-                     // ALL:         {{^ *}}| Function: _Z4funcIiEiT_:
-                     // FILTER-NOT:  {{^ *(\| )?}}Function: _Z4funcIiEiT_:
+                     // ALL:         {{^ *}}| _Z4funcIiEiT_:
+                     // FILTER-NOT:  {{^ *(\| )?}} _Z4funcIiEiT_:
                      // ALL:         [[@LINE-19]]| 1|int func(T x) {
                      // ALL-NEXT:    [[@LINE-19]]| 1|  if(x)
                      // ALL-NEXT:    [[@LINE-19]]| 0|    return 0;
@@ -56,7 +56,7 @@ int main() {         // ALL:         [[@LINE]]| 1|int main() {
 // HTML-ALL: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre>
 // HTML-ALL: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>2</pre></td><td class='code'><pre>}
 
-// HTML-SHARED: <div class='source-name-title'><pre>Function: _Z4funcIbEiT_</pre></div>
+// HTML-SHARED: <div class='source-name-title'><pre>_Z4funcIbEiT_</pre></div>
 // HTML-SHARED: <td class='line-number'><a name='L[[@LINE-53]]'><pre>[[@LINE-53]]</pre></a></td><td class='covered-line'><pre>1</pre></td><td class='code'><pre>int func(T x) {
 // HTML-SHARED: <td class='line-number'><a name='L[[@LINE-53]]'><pre>[[@LINE-53]]</pre></a></td><td class='covered-line'><pre>1</pre></td><td class='code'><pre>  if(x)
 // HTML-SHARED: <td class='line-number'><a name='L[[@LINE-53]]'><pre>[[@LINE-53]]</pre></a></td><td class='covered-line'><pre>1</pre></td><td class='code'><pre>    ret
@@ -65,7 +65,7 @@ int main() {         // ALL:         [[@LINE]]| 1|int main() {
 // HTML-SHARED: <td class='line-number'><a name='L[[@LINE-53]]'><pre>[[@LINE-53]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre>
 // HTML-SHARED: <td class='line-number'><a name='L[[@LINE-53]]'><pre>[[@LINE-53]]</pre></a></td><td class='covered-line'><pre>1</pre></td><td class='code'><pre>}
 
-// HTML-ALL: <div class='source-name-title'><pre>Function: _Z4funcIiEiT_</pre></div>
+// HTML-ALL: <div class='source-name-title'><pre>_Z4funcIiEiT_</pre></div>
 // HTML-FILTER-NOT: <div class='source-name-title'><pre>_Z4funcIiEiT_</pre></div><table>
 // HTML-ALL: <td class='line-number'><a name='L[[@LINE-63]]'><pre>[[@LINE-63]]</pre></a></td><td class='covered-line'><pre>1</pre></td><td class='code'><pre>int func(T x) {
 // HTML-ALL: <td class='line-number'><a name='L[[@LINE-63]]'><pre>[[@LINE-63]]</pre></a></td><td class='covered-line'><pre>1</pre></td><td class='code'><pre>  if(x)
index 9755b60..e5b9b69 100644 (file)
@@ -210,9 +210,9 @@ CodeCoverageTool::createFunctionView(const FunctionRecord &Function,
     return nullptr;
 
   auto Expansions = FunctionCoverage.getExpansions();
-  auto View = SourceCoverageView::create(
-      getSymbolForHumans(Function.Name), SourceBuffer.get(), ViewOpts,
-      std::move(FunctionCoverage), /*FunctionView=*/true);
+  auto View = SourceCoverageView::create(getSymbolForHumans(Function.Name),
+                                         SourceBuffer.get(), ViewOpts,
+                                         std::move(FunctionCoverage));
   attachExpansionSubViews(*View, Expansions, Coverage);
 
   return View;
@@ -238,7 +238,7 @@ CodeCoverageTool::createSourceFileView(StringRef SourceFile,
     auto SubViewExpansions = SubViewCoverage.getExpansions();
     auto SubView = SourceCoverageView::create(
         getSymbolForHumans(Function->Name), SourceBuffer.get(), ViewOpts,
-        std::move(SubViewCoverage), /*FunctionView=*/true);
+        std::move(SubViewCoverage));
     attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
 
     if (SubView) {
index 47980ab..cfcaf2e 100644 (file)
@@ -129,26 +129,28 @@ bool SourceCoverageView::hasSubViews() const {
 std::unique_ptr<SourceCoverageView>
 SourceCoverageView::create(StringRef SourceName, const MemoryBuffer &File,
                            const CoverageViewOptions &Options,
-                           coverage::CoverageData &&CoverageInfo,
-                           bool FunctionView) {
+                           coverage::CoverageData &&CoverageInfo) {
   switch (Options.Format) {
   case CoverageViewOptions::OutputFormat::Text:
     return llvm::make_unique<SourceCoverageViewText>(
-        SourceName, File, Options, std::move(CoverageInfo), FunctionView);
+        SourceName, File, Options, std::move(CoverageInfo));
   case CoverageViewOptions::OutputFormat::HTML:
     return llvm::make_unique<SourceCoverageViewHTML>(
-        SourceName, File, Options, std::move(CoverageInfo), FunctionView);
+        SourceName, File, Options, std::move(CoverageInfo));
   }
   llvm_unreachable("Unknown coverage output format!");
 }
 
-std::string SourceCoverageView::getNativeSourceName() const {
-  std::string SourceFile = isFunctionView() ? "Function: " : "Source: ";
-  SourceFile += getSourceName().str();
-  SmallString<128> SourceText(SourceFile);
+std::string SourceCoverageView::getSourceName() const {
+  SmallString<128> SourceText(SourceName);
   sys::path::remove_dots(SourceText, /*remove_dot_dots=*/true);
   sys::path::native(SourceText);
-  return SourceText.c_str();
+  return SourceText.str();
+}
+
+std::string SourceCoverageView::getVerboseSourceName() const {
+  return "Source: " + getSourceName() + " (Binary: " +
+         sys::path::filename(getOptions().ObjectFilename).str() + ")";
 }
 
 void SourceCoverageView::addExpansion(
index 63c5b65..f2d5d61 100644 (file)
@@ -172,9 +172,6 @@ class SourceCoverageView {
   /// on display.
   std::vector<InstantiationView> InstantiationSubViews;
 
-  /// Specifies whether or not the view is a function view.
-  bool FunctionView;
-
   /// Get the first uncovered line number for the source file.
   unsigned getFirstUncoveredLineNo();
 
@@ -264,24 +261,24 @@ protected:
 
   SourceCoverageView(StringRef SourceName, const MemoryBuffer &File,
                      const CoverageViewOptions &Options,
-                     coverage::CoverageData &&CoverageInfo, bool FunctionView)
+                     coverage::CoverageData &&CoverageInfo)
       : SourceName(SourceName), File(File), Options(Options),
-        CoverageInfo(std::move(CoverageInfo)), FunctionView(FunctionView) {}
+        CoverageInfo(std::move(CoverageInfo)) {}
 
 public:
   static std::unique_ptr<SourceCoverageView>
   create(StringRef SourceName, const MemoryBuffer &File,
          const CoverageViewOptions &Options,
-         coverage::CoverageData &&CoverageInfo, bool FucntionView = false);
+         coverage::CoverageData &&CoverageInfo);
 
   virtual ~SourceCoverageView() {}
 
-  StringRef getSourceName() const { return SourceName; }
-
   /// \brief Return the source name formatted for the host OS.
-  std::string getNativeSourceName() const;
+  std::string getSourceName() const;
 
-  bool isFunctionView() const { return FunctionView; }
+  /// \brief Return a verbose description of the source name and the binary it
+  /// corresponds to.
+  std::string getVerboseSourceName() const;
 
   const CoverageViewOptions &getOptions() const { return Options; }
 
index 52e594f..ca3f350 100644 (file)
@@ -341,12 +341,10 @@ void SourceCoverageViewHTML::renderViewFooter(raw_ostream &OS) {
 void SourceCoverageViewHTML::renderSourceName(raw_ostream &OS, bool WholeFile,
                                               unsigned FirstUncoveredLineNo) {
   OS << BeginSourceNameDiv;
-  // Render the source name for the view.
-  OS << tag("pre", escape(getNativeSourceName(), getOptions()));
+  std::string ViewInfo = escape(
+      WholeFile ? getVerboseSourceName() : getSourceName(), getOptions());
+  OS << tag("pre", ViewInfo);
   if (WholeFile) {
-    // Render the object file name for the view.
-    OS << tag("pre",
-              escape("Binary: " + getOptions().ObjectFilename, getOptions()));
     // Render the "Go to first unexecuted line" link for the view.
     if (FirstUncoveredLineNo != 0) { // The file is not fully covered
       std::string LinkText =
index 42fec6f..edbe7c4 100644 (file)
@@ -78,10 +78,9 @@ class SourceCoverageViewHTML : public SourceCoverageView {
 public:
   SourceCoverageViewHTML(StringRef SourceName, const MemoryBuffer &File,
                          const CoverageViewOptions &Options,
-                         coverage::CoverageData &&CoverageInfo,
-                         bool FunctionView)
-      : SourceCoverageView(SourceName, File, Options, std::move(CoverageInfo),
-                           FunctionView) {}
+                         coverage::CoverageData &&CoverageInfo)
+      : SourceCoverageView(SourceName, File, Options, std::move(CoverageInfo)) {
+  }
 };
 
 } // namespace llvm
index 6dec4c7..3d2c067 100644 (file)
@@ -65,12 +65,8 @@ void SourceCoverageViewText::renderViewFooter(raw_ostream &) {}
 
 void SourceCoverageViewText::renderSourceName(raw_ostream &OS, bool WholeFile,
                                               unsigned FirstUncoveredLineNo) {
-  getOptions().colored_ostream(OS, raw_ostream::CYAN) << getNativeSourceName()
-                                                      << ":\n";
-  if (WholeFile) {
-    getOptions().colored_ostream(OS, raw_ostream::CYAN)
-        << "Binary: " << getOptions().ObjectFilename << ":\n";
-  }
+  std::string ViewInfo = WholeFile ? getVerboseSourceName() : getSourceName();
+  getOptions().colored_ostream(OS, raw_ostream::CYAN) << ViewInfo << ":\n";
 }
 
 void SourceCoverageViewText::renderLinePrefix(raw_ostream &OS,
index dd78d3a..fe2642a 100644 (file)
@@ -78,10 +78,9 @@ class SourceCoverageViewText : public SourceCoverageView {
 public:
   SourceCoverageViewText(StringRef SourceName, const MemoryBuffer &File,
                          const CoverageViewOptions &Options,
-                         coverage::CoverageData &&CoverageInfo,
-                         bool FunctionView)
-      : SourceCoverageView(SourceName, File, Options, std::move(CoverageInfo),
-                           FunctionView) {}
+                         coverage::CoverageData &&CoverageInfo)
+      : SourceCoverageView(SourceName, File, Options, std::move(CoverageInfo)) {
+  }
 };
 
 } // namespace llvm