From 3a22947aac39caed577e8c9f67e2739d0afec06c Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Thu, 24 Oct 2024 00:22:14 -0300 Subject: [PATCH] refactor(TestArgs): reuse public config args --- CMakeLists.txt | 14 +++++++++---- src/test/TestArgs.cpp | 46 +++-------------------------------------- src/test/TestArgs.hpp | 14 ++----------- src/test/TestMain.cpp | 20 +++++++++--------- src/test/TestRunner.cpp | 12 +++-------- src/test/TestRunner.hpp | 2 +- 6 files changed, 29 insertions(+), 79 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 847afce51..1cee48d51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -338,11 +338,15 @@ if (MRDOCS_BUILD_TESTS) include(CTest) file(GLOB_RECURSE TEST_SUITE_FILES CONFIGURE_DEPENDS src/test_suite/*.cpp src/test_suite/*.hpp) file(GLOB_RECURSE UNIT_TEST_SOURCES CONFIGURE_DEPENDS src/test/*.cpp src/test/*.hpp) - add_executable(mrdocs-test ${TEST_SUITE_FILES} ${UNIT_TEST_SOURCES}) + add_executable(mrdocs-test ${TEST_SUITE_FILES} ${UNIT_TEST_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/src/tool/PublicToolArgs.cpp) target_include_directories(mrdocs-test + PUBLIC + "$" + "$" + "$" PRIVATE - "${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/src" + "${PROJECT_BINARY_DIR}/src" ) target_link_libraries(mrdocs-test PUBLIC mrdocs-core) if (MRDOCS_CLANG) @@ -358,9 +362,10 @@ if (MRDOCS_BUILD_TESTS) --action=test "${PROJECT_SOURCE_DIR}/test-files/golden-tests" "--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons" - --generator=${testgenerator} + --generate=${testgenerator} "--stdlib-includes=${LIBCXX_DIR}" "--stdlib-includes=${STDLIB_INCLUDE_DIR}" + --report=2 ) foreach (action IN ITEMS test create update) add_custom_target( @@ -371,9 +376,10 @@ if (MRDOCS_BUILD_TESTS) --action=${action} "${PROJECT_SOURCE_DIR}/test-files/golden-tests" "--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons" - --generator=${testgenerator} + --generate=${testgenerator} "--stdlib-includes=${LIBCXX_DIR}" "--stdlib-includes=${STDLIB_INCLUDE_DIR}" + --report=2 DEPENDS mrdocs-test ) endforeach () diff --git a/src/test/TestArgs.cpp b/src/test/TestArgs.cpp index cc3f89a69..84c3c069d 100644 --- a/src/test/TestArgs.cpp +++ b/src/test/TestArgs.cpp @@ -9,8 +9,6 @@ // #include "TestArgs.hpp" -#include -#include #include namespace clang { @@ -22,12 +20,9 @@ TestArgs TestArgs::instance_; TestArgs:: TestArgs() - : commonCat("COMMON") - - , usageText( -R"(MrDocs Test Program -)") + : PublicToolArgs() + , usageText("MrDocs Test Program") , extraHelp( R"( EXAMPLES: @@ -36,20 +31,9 @@ R"( mrdocs-test --action test friend.cpp )") -// -// Common options -// - -, reportLevel( - "report", - llvm::cl::desc("The minimum reporting level (0 to 4)."), - llvm::cl::init(2), - llvm::cl::cat(commonCat)) - // // Test options // - , action( "action", llvm::cl::desc(R"(Which action should be performed:)"), @@ -57,8 +41,7 @@ R"( llvm::cl::values( clEnumVal(test, "Compare output against expected."), clEnumVal(create, "Create missing expected documentation files."), - clEnumVal(update, "Update all expected documentation files.")), - llvm::cl::cat(commonCat)) + clEnumVal(update, "Update all expected documentation files."))) , badOption( "bad", @@ -69,28 +52,6 @@ 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)) - -, generator( - "generator", - llvm::cl::desc("The generator to use for tests."), - llvm::cl::init("xml")) - -, addons( - "addons", - llvm::cl::desc("The directory with the addons."), - llvm::cl::cat(commonCat)) - -, stdlibIncludes( - "stdlib-includes", - llvm::cl::desc("A list of paths to std library headers."), - llvm::cl::cat(commonCat)) - { } @@ -104,7 +65,6 @@ hideForeignOptions() std::vector ours({ &action, - std::addressof(inputPaths), &badOption, &unitOption }); diff --git a/src/test/TestArgs.hpp b/src/test/TestArgs.hpp index 01e49562d..4dc148d2b 100644 --- a/src/test/TestArgs.hpp +++ b/src/test/TestArgs.hpp @@ -12,6 +12,7 @@ #define MRDOCS_TEST_TESTARGS_HPP #include +#include #include namespace clang { @@ -26,31 +27,20 @@ enum Action : int /** Command line options and test settings. */ -class TestArgs +class TestArgs : public PublicToolArgs { TestArgs(); - llvm::cl::OptionCategory commonCat; - public: static TestArgs instance_; char const* usageText; llvm::cl::extrahelp extraHelp; - // Common options - llvm::cl::opt reportLevel; - // Test options llvm::cl::opt action; llvm::cl::opt badOption; llvm::cl::opt unitOption; - llvm::cl::list inputPaths; - - // Options replication public settings - llvm::cl::opt generator; - llvm::cl::opt addons; - llvm::cl::list stdlibIncludes; // Hide all options that don't belong to us void hideForeignOptions(); diff --git a/src/test/TestMain.cpp b/src/test/TestMain.cpp index 3c4d971fe..20b4d295c 100644 --- a/src/test/TestMain.cpp +++ b/src/test/TestMain.cpp @@ -23,18 +23,18 @@ #include #include -int main(int argc, char** argv); +int main(int argc, char const** argv); namespace clang { namespace mrdocs { -void DoTestAction() +void DoTestAction(char const** argv) { using namespace clang::mrdocs; - TestRunner runner(testArgs.generator); - for(auto const& inputPath : testArgs.inputPaths) - runner.checkPath(inputPath); + TestRunner runner(testArgs.generate); + for(auto const& inputPath : testArgs.inputs) + runner.checkPath(inputPath, argv); auto const& results = runner.results; std::stringstream os; @@ -63,7 +63,7 @@ void DoTestAction() report::print(os.str()); } -int test_main(int argc, char const* const* argv) +int test_main(int argc, char const** argv) { // VFALCO this heap checking is too strong for // a clang tool's model of what is actually a leak. @@ -80,10 +80,10 @@ int test_main(int argc, char const* const* argv) // Apply reportLevel report::setMinimumLevel(report::getLevel( - testArgs.reportLevel.getValue())); + testArgs.report.getValue())); - if(! testArgs.inputPaths.empty()) - DoTestAction(); + if(!testArgs.inputs.empty()) + DoTestAction(argv); if(testArgs.unitOption.getValue()) test_suite::unit_test_main(argc, argv); @@ -106,7 +106,7 @@ static void reportUnhandledException( } // mrdocs } // clang -int main(int argc, char** argv) +int main(int argc, char const** argv) { try { diff --git a/src/test/TestRunner.cpp b/src/test/TestRunner.cpp index 87e887b87..344360430 100644 --- a/src/test/TestRunner.cpp +++ b/src/test/TestRunner.cpp @@ -264,7 +264,8 @@ handleDir( void TestRunner:: checkPath( - std::string inputPath) + std::string inputPath, + char const** argv) { namespace fs = llvm::sys::fs; namespace path = llvm::sys::path; @@ -274,14 +275,6 @@ checkPath( // Set the reference directories for the test dirs_.configDir = inputPath; dirs_.cwd = dirs_.configDir; - if (testArgs.addons.getValue() != "") - { - dirs_.mrdocsRoot = files::getParentDir(files::normalizePath(testArgs.addons.getValue()), 3); - } - else - { - report::warn("No addons directory specified to mrdocs tests"); - } // See if inputPath references a file or directory auto fileType = files::getFileType(inputPath); @@ -291,6 +284,7 @@ checkPath( // Check for a directory-wide config Config::Settings dirSettings; + testArgs.apply(dirSettings, dirs_, argv); dirSettings.sourceRoot = files::appendPath(inputPath, "."); dirSettings.stdlibIncludes.insert( dirSettings.stdlibIncludes.end(), diff --git a/src/test/TestRunner.hpp b/src/test/TestRunner.hpp index 29ff9eba9..ed988aa6d 100644 --- a/src/test/TestRunner.hpp +++ b/src/test/TestRunner.hpp @@ -79,7 +79,7 @@ class TestRunner This function checks the specified path and blocks until completed. */ - void checkPath(std::string inputPath); + void checkPath(std::string inputPath, char const** argv); }; } // mrdocs