[llvm-cov] Add a format option for the 'show' sub-command (mostly NFC)

llvm-svn: 273968
This commit is contained in:
Vedant Kumar 2016-06-28 00:15:54 +00:00
parent 3264fdd3ca
commit 635c83c1b4
5 changed files with 23 additions and 3 deletions

View File

@ -236,6 +236,10 @@ OPTIONS
Show code coverage only for functions that match the given regular expression. Show code coverage only for functions that match the given regular expression.
.. option:: -format=<FORMAT>
Use the specified output format. The supported formats are: "text".
.. option:: -line-coverage-gt=<N> .. option:: -line-coverage-gt=<N>
Show code coverage only for functions with line coverage greater than the Show code coverage only for functions with line coverage greater than the

View File

@ -4,7 +4,7 @@
// NAN-NOT: 0{{[ \t]+}}nan%{{[ \t]+}}0{{[ \t]+}}nan% // NAN-NOT: 0{{[ \t]+}}nan%{{[ \t]+}}0{{[ \t]+}}nan%
// RUN: llvm-profdata merge %S/Inputs/prevent_false_instantiations.proftext -o %t.profdata // RUN: llvm-profdata merge %S/Inputs/prevent_false_instantiations.proftext -o %t.profdata
// RUN: llvm-cov show %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %t.profdata -filename-equivalence %s | FileCheck %s -check-prefix=INSTANTIATION // RUN: llvm-cov show -format text %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %t.profdata -filename-equivalence %s | FileCheck %s -check-prefix=INSTANTIATION
// RUN: llvm-cov report %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %t.profdata | FileCheck %s -check-prefix=NAN // RUN: llvm-cov report %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %t.profdata | FileCheck %s -check-prefix=NAN
#define DO_SOMETHING() \ #define DO_SOMETHING() \

View File

@ -399,6 +399,13 @@ int CodeCoverageTool::show(int argc, const char **argv,
cl::desc("Show function instantiations"), cl::desc("Show function instantiations"),
cl::cat(ViewCategory)); cl::cat(ViewCategory));
cl::opt<CoverageViewOptions::OutputFormat> ShowFormat(
"format", cl::desc("Output format for line-based coverage reports"),
cl::values(clEnumValN(CoverageViewOptions::OutputFormat::Text, "text",
"Text output"),
clEnumValEnd),
cl::init(CoverageViewOptions::OutputFormat::Text));
auto Err = commandLineParser(argc, argv); auto Err = commandLineParser(argc, argv);
if (Err) if (Err)
return Err; return Err;
@ -410,6 +417,7 @@ int CodeCoverageTool::show(int argc, const char **argv,
ViewOpts.ShowLineStatsOrRegionMarkers = ShowBestLineRegionsCounts; ViewOpts.ShowLineStatsOrRegionMarkers = ShowBestLineRegionsCounts;
ViewOpts.ShowExpandedRegions = ShowExpansions; ViewOpts.ShowExpandedRegions = ShowExpansions;
ViewOpts.ShowFunctionInstantiations = ShowInstantiations; ViewOpts.ShowFunctionInstantiations = ShowInstantiations;
ViewOpts.ShowFormat = ShowFormat;
auto Coverage = load(); auto Coverage = load();
if (!Coverage) if (!Coverage)

View File

@ -16,6 +16,10 @@ namespace llvm {
/// \brief The options for displaying the code coverage information. /// \brief The options for displaying the code coverage information.
struct CoverageViewOptions { struct CoverageViewOptions {
enum class OutputFormat {
Text
};
bool Debug; bool Debug;
bool Colors; bool Colors;
bool ShowLineNumbers; bool ShowLineNumbers;
@ -25,6 +29,7 @@ struct CoverageViewOptions {
bool ShowExpandedRegions; bool ShowExpandedRegions;
bool ShowFunctionInstantiations; bool ShowFunctionInstantiations;
bool ShowFullFilenames; bool ShowFullFilenames;
OutputFormat ShowFormat;
/// \brief Change the output's stream color if the colors are enabled. /// \brief Change the output's stream color if the colors are enabled.
ColoredRawOstream colored_ostream(raw_ostream &OS, ColoredRawOstream colored_ostream(raw_ostream &OS,

View File

@ -50,8 +50,11 @@ std::unique_ptr<SourceCoverageView>
SourceCoverageView::create(StringRef SourceName, const MemoryBuffer &File, SourceCoverageView::create(StringRef SourceName, const MemoryBuffer &File,
const CoverageViewOptions &Options, const CoverageViewOptions &Options,
coverage::CoverageData &&CoverageInfo) { coverage::CoverageData &&CoverageInfo) {
return llvm::make_unique<SourceCoverageViewText>(SourceName, File, Options, switch (Options.ShowFormat) {
std::move(CoverageInfo)); case CoverageViewOptions::OutputFormat::Text:
return llvm::make_unique<SourceCoverageViewText>(SourceName, File, Options,
std::move(CoverageInfo));
}
} }
void SourceCoverageView::print(raw_ostream &OS, bool WholeFile, void SourceCoverageView::print(raw_ostream &OS, bool WholeFile,