From 843f5a2dbb48c3330e8d041a58a6115ebef79889 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 8 Jul 2023 14:08:57 -0700 Subject: [PATCH] feat: --report switch --- include/mrdox/Support/Error.hpp | 2 +- lib/Support/Error.cpp | 7 +++++++ lib/Tool/ToolArgs.cpp | 26 ++++++++++++++++---------- lib/Tool/ToolArgs.hpp | 4 +++- test/TestArgs.cpp | 33 +++++++++++++++++++-------------- test/TestArgs.hpp | 5 +++-- test/TestMain.cpp | 3 +++ tool/ToolMain.cpp | 3 +++ 8 files changed, 55 insertions(+), 28 deletions(-) diff --git a/include/mrdox/Support/Error.hpp b/include/mrdox/Support/Error.hpp index df29c73ca..de7a367d2 100644 --- a/include/mrdox/Support/Error.hpp +++ b/include/mrdox/Support/Error.hpp @@ -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. diff --git a/lib/Support/Error.cpp b/lib/Support/Error.cpp index 43a26b321..b3cfc12c9 100644 --- a/lib/Support/Error.cpp +++ b/lib/Support/Error.cpp @@ -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, diff --git a/lib/Tool/ToolArgs.cpp b/lib/Tool/ToolArgs.cpp index a6e98e0c3..6a9117944 100644 --- a/lib/Tool/ToolArgs.cpp +++ b/lib/Tool/ToolArgs.cpp @@ -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", @@ -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.")) { } diff --git a/lib/Tool/ToolArgs.hpp b/lib/Tool/ToolArgs.hpp index ee4822a1e..70f5e61a5 100644 --- a/lib/Tool/ToolArgs.hpp +++ b/lib/Tool/ToolArgs.hpp @@ -32,11 +32,13 @@ class ToolArgs llvm::cl::extrahelp extraHelp; llvm::cl::opt addonsDir; + llvm::cl::opt reportLevel; + llvm::cl::opt configPath; llvm::cl::opt outputPath; - llvm::cl::list inputPaths; llvm::cl::opt formatType; llvm::cl::opt ignoreMappingFailures; + llvm::cl::list inputPaths; // Hide all options which don't belong to us void hideForeignOptions(); diff --git a/test/TestArgs.cpp b/test/TestArgs.cpp index 9525b6e08..1ad2e244c 100644 --- a/test/TestArgs.cpp +++ b/test/TestArgs.cpp @@ -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."), @@ -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)) { } diff --git a/test/TestArgs.hpp b/test/TestArgs.hpp index 68bdd933b..96f68e9b5 100644 --- a/test/TestArgs.hpp +++ b/test/TestArgs.hpp @@ -39,13 +39,14 @@ class TestArgs llvm::cl::extrahelp extraHelp; // Common options - llvm::cl::opt action; llvm::cl::opt addonsDir; - llvm::cl::list inputPaths; + llvm::cl::opt reportLevel; // Test options + llvm::cl::opt action; llvm::cl::opt badOption; llvm::cl::opt unitOption; + llvm::cl::list inputPaths; // Hide all options which don't belong to us void hideForeignOptions(); diff --git a/test/TestMain.cpp b/test/TestMain.cpp index d87657fd7..a2e8c97d0 100644 --- a/test/TestMain.cpp +++ b/test/TestMain.cpp @@ -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(); diff --git a/tool/ToolMain.cpp b/tool/ToolMain.cpp index 2c0ee6b0b..221183e66 100644 --- a/tool/ToolMain.cpp +++ b/tool/ToolMain.cpp @@ -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(&main))) return EXIT_FAILURE;