diff --git a/CMakeLists.txt b/CMakeLists.txt index 929771fa7..4359f12ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,7 @@ file(GLOB_RECURSE TOOL_SOURCES CONFIGURE_DEPENDS ) file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS + source/tests/*.hpp source/tests/*.cpp ) diff --git a/include/mrdox/Config.hpp b/include/mrdox/Config.hpp index 5a2387422..0f8fe964e 100644 --- a/include/mrdox/Config.hpp +++ b/include/mrdox/Config.hpp @@ -45,7 +45,7 @@ struct Config std::string ProjectName; // Indicates if only public declarations are documented. - bool PublicOnly; + bool PublicOnly = true; // Directory for outputting generated files. std::string OutDirectory; diff --git a/source/lib/XML.cpp b/source/lib/XML.cpp index 5896582d9..b85d98929 100644 --- a/source/lib/XML.cpp +++ b/source/lib/XML.cpp @@ -13,10 +13,12 @@ #include "CorpusVisitor.hpp" #include "Representation.h" #include +#include #include #include #include #include +#include //------------------------------------------------ /* @@ -553,6 +555,33 @@ char const* XMLGenerator:: Format = "xml"; +/** A visitor which keeps its own map of tool results. +*/ +class TestVisitor + : public BasicVisitor +{ + TestVisitor& corpus_; + tooling::InMemoryToolResults results_; + +public: + TestVisitor( + TestVisitor& corpus, + Config const& cfg) noexcept + : BasicVisitor(cfg) + , corpus_(corpus) + { + } + +private: + void + reportResult( + StringRef Key, + StringRef Value) override + { + results_.addResult(Key, Value); + } +}; + } // (anon) //------------------------------------------------ diff --git a/source/tests/TestVisitor.cpp b/source/tests/TestAction.cpp similarity index 100% rename from source/tests/TestVisitor.cpp rename to source/tests/TestAction.cpp diff --git a/source/tests/TestAction.hpp b/source/tests/TestAction.hpp new file mode 100644 index 000000000..d042f6ca9 --- /dev/null +++ b/source/tests/TestAction.hpp @@ -0,0 +1,94 @@ +// +// Licensed under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) +// +// Official repository: https://github.com/cppalliance/mrdox +// + +#ifndef MRDOX_TEST_TEST_VISITOR_HPP +#define MRDOX_TEST_TEST_VISITOR_HPP + +#include +#include + +namespace clang { +namespace mrdox { + +//------------------------------------------------ + +/** A Visitor which stores tool results in a local map +*/ +struct TestVisitor : public BasicVisitor +{ + explicit + TestVisitor( + Config const& cfg) noexcept + : BasicVisitor(cfg) + { + } + +private: + void + reportResult( + llvm::StringRef Key, + llvm::StringRef Value) override + { + results_.addResult(Key, Value); + } + + tooling::InMemoryToolResults results_; +}; + +//------------------------------------------------ + +struct TestAction + : public clang::ASTFrontendAction +{ + explicit + TestAction( + Config const& cfg) noexcept + : cfg_(cfg) + { + } + + std::unique_ptr + CreateASTConsumer( + clang::CompilerInstance& Compiler, + llvm::StringRef InFile) override + { + return std::make_unique(cfg_); + } + +private: + Config const& cfg_; +}; + +//------------------------------------------------ + +struct TestFactory + : public tooling::FrontendActionFactory +{ + explicit + TestFactory( + Config const& cfg) noexcept + : cfg_(cfg) + { + } + + std::unique_ptr + create() override + { + return std::make_unique(cfg_); + } + +private: + Config const& cfg_; +}; + +} // mrdox +} // clang + +#endif diff --git a/source/tests/TestMain.cpp b/source/tests/TestMain.cpp index c09a7fa39..a6ae394fb 100644 --- a/source/tests/TestMain.cpp +++ b/source/tests/TestMain.cpp @@ -10,6 +10,7 @@ #include "ClangDoc.h" #include "Representation.h" +#include "TestAction.hpp" #include #include #include @@ -78,6 +79,8 @@ struct Reporter } }; +//------------------------------------------------ + /** Return command line arguments as a vector of strings. */ std::vector @@ -112,7 +115,8 @@ createExecutor( #endif auto executor = std::make_unique< tooling::StandaloneToolExecutor>( - compilations, llvm::ArrayRef{} ); + compilations, + compilations.getAllFiles()); if (!executor) return llvm::make_error( "could not create StandaloneToolExecutor", @@ -258,12 +262,11 @@ testMain(int argc, const char** argv) Args.push_back(argv[i]); Config cfg; - if(llvm::Error err = setupConfig(cfg, argc, argv)) - { - llvm::errs() << "test failure: " << err << "\n"; - return EXIT_FAILURE; - } + llvm::Error err = executor->execute(std::make_unique(cfg)); + R.success("execute", err); + +#if 0 std::string xml; for(int i = 1; i < argc; ++i) { @@ -359,6 +362,7 @@ testMain(int argc, const char** argv) iter.increment(ec); } } +#endif if(R.failed) return EXIT_FAILURE; diff --git a/source/tests/TestVisitor.hpp b/source/tests/TestVisitor.hpp deleted file mode 100644 index 954e8bb33..000000000 --- a/source/tests/TestVisitor.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// -// Licensed under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) -// -// Official repository: https://github.com/cppalliance/mrdox -// - -#ifndef MRDOX_TEST_TEST_VISITOR_HPP -#define MRDOX_TEST_TEST_VISITOR_HPP - -#include - -namespace clang { -namespace mrdox - -class TestVisitor - : public BasicVisitor - -} // mrdox -} // clang - -#endif