Skip to content

Commit

Permalink
feat: --report switch
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Jul 8, 2023
1 parent 9a64659 commit 843f5a2
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 28 deletions.
2 changes: 1 addition & 1 deletion include/mrdox/Support/Error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ extern MRDOX_DECL Results results;
that errors will still count as errors even if
they are not displayed.
*/
MRDOX_DECL void setMinimumLevel(unsigned level);
MRDOX_DECL void setMinimumLevel(unsigned level) noexcept;

/** Report a message to the console.
Expand Down
7 changes: 7 additions & 0 deletions lib/Support/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ static unsigned reportLevel_ = 0;

constinit Results results{};

void setMinimumLevel(unsigned level) noexcept
{
if( level > 4)
level = 4;
reportLevel_ = level;
}

void
print_impl(
unsigned level,
Expand Down
26 changes: 16 additions & 10 deletions lib/Tool/ToolArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,23 @@ R"(
llvm::cl::desc("The path to the addons directory."),
llvm::cl::cat(commonCat))

, reportLevel(
"report",
llvm::cl::desc("The minimum reporting level (0 to 4)."),
llvm::cl::cat(commonCat))

//
// Tool options
//

, configPath(
"config",
llvm::cl::desc(R"(The config filename relative to the repository root.)"),
llvm::cl::cat(commonCat))
llvm::cl::desc(R"(The config filename relative to the repository root.)"))

, outputPath(
"output",
llvm::cl::desc("Directory or file for generating output."),
llvm::cl::init("."),
llvm::cl::cat(commonCat))

, inputPaths(
"inputs",
llvm::cl::Sink,
llvm::cl::desc("The path to the compilation database."),
llvm::cl::cat(commonCat))
llvm::cl::init("."))

, formatType(
"format",
Expand All @@ -76,6 +77,11 @@ R"(
"ignore-map-errors",
llvm::cl::desc("Continue if files are not mapped correctly."),
llvm::cl::init(true))

, inputPaths(
"inputs",
llvm::cl::Sink,
llvm::cl::desc("The path to the compilation database."))
{
}

Expand Down
4 changes: 3 additions & 1 deletion lib/Tool/ToolArgs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ class ToolArgs
llvm::cl::extrahelp extraHelp;

llvm::cl::opt<std::string> addonsDir;
llvm::cl::opt<unsigned> reportLevel;

llvm::cl::opt<std::string> configPath;
llvm::cl::opt<std::string> outputPath;
llvm::cl::list<std::string> inputPaths;
llvm::cl::opt<std::string> formatType;
llvm::cl::opt<bool> ignoreMappingFailures;
llvm::cl::list<std::string> inputPaths;

// Hide all options which don't belong to us
void hideForeignOptions();
Expand Down
33 changes: 19 additions & 14 deletions test/TestArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,30 @@ R"(
// Common options
//

, action(
"action",
llvm::cl::desc(R"(Which action should be performed:)"),
llvm::cl::init(test),
llvm::cl::values(
clEnumVal(test, "Compare output against expected."),
clEnumVal(create, "Create missing expected xml files."),
clEnumVal(update, "Update all expected xml files.")),
llvm::cl::cat(commonCat))

, addonsDir(
"addons",
llvm::cl::desc("The path to the addons directory."),
llvm::cl::cat(commonCat))

, inputPaths(
"inputs",
llvm::cl::Sink,
llvm::cl::desc("A list of directories and/or .cpp files to test."),
, reportLevel(
"report",
llvm::cl::desc("The minimum reporting level (0 to 4)."),
llvm::cl::cat(commonCat))

//
// Test options
//

, action(
"action",
llvm::cl::desc(R"(Which action should be performed:)"),
llvm::cl::init(test),
llvm::cl::values(
clEnumVal(test, "Compare output against expected."),
clEnumVal(create, "Create missing expected xml files."),
clEnumVal(update, "Update all expected xml files.")),
llvm::cl::cat(commonCat))

, badOption(
"bad",
llvm::cl::desc("Write a .bad.xml file for each test failure."),
Expand All @@ -82,6 +81,12 @@ R"(
"unit",
llvm::cl::desc("Run all or selected unit test suites."),
llvm::cl::init(true))

, inputPaths(
"inputs",
llvm::cl::Sink,
llvm::cl::desc("A list of directories and/or .cpp files to test."),
llvm::cl::cat(commonCat))
{
}

Expand Down
5 changes: 3 additions & 2 deletions test/TestArgs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ class TestArgs
llvm::cl::extrahelp extraHelp;

// Common options
llvm::cl::opt<Action> action;
llvm::cl::opt<std::string> addonsDir;
llvm::cl::list<std::string> inputPaths;
llvm::cl::opt<unsigned> reportLevel;

// Test options
llvm::cl::opt<Action> action;
llvm::cl::opt<bool> badOption;
llvm::cl::opt<bool> unitOption;
llvm::cl::list<std::string> inputPaths;

// Hide all options which don't belong to us
void hideForeignOptions();
Expand Down
3 changes: 3 additions & 0 deletions test/TestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ int test_main(int argc, char const* const* argv)
argc, argv, testArgs.usageText))
return EXIT_FAILURE;

// Apply reportLevel
report::setMinimumLevel(testArgs.reportLevel.getValue());

if(! testArgs.inputPaths.empty())
DoTestAction();

Expand Down
3 changes: 3 additions & 0 deletions tool/ToolMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ int mrdox_main(int argc, char const** argv)
argc, argv, toolArgs.usageText))
return EXIT_FAILURE;

// Apply reportLevel
report::setMinimumLevel(toolArgs.reportLevel.getValue());

if(! setupAddonsDir(toolArgs.addonsDir, argv[0],
reinterpret_cast<void*>(&main)))
return EXIT_FAILURE;
Expand Down

0 comments on commit 843f5a2

Please sign in to comment.