Skip to content

Commit 3a22947

Browse files
committed
refactor(TestArgs): reuse public config args
1 parent a1fb8ec commit 3a22947

File tree

6 files changed

+29
-79
lines changed

6 files changed

+29
-79
lines changed

CMakeLists.txt

+10-4
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,15 @@ if (MRDOCS_BUILD_TESTS)
338338
include(CTest)
339339
file(GLOB_RECURSE TEST_SUITE_FILES CONFIGURE_DEPENDS src/test_suite/*.cpp src/test_suite/*.hpp)
340340
file(GLOB_RECURSE UNIT_TEST_SOURCES CONFIGURE_DEPENDS src/test/*.cpp src/test/*.hpp)
341-
add_executable(mrdocs-test ${TEST_SUITE_FILES} ${UNIT_TEST_SOURCES})
341+
add_executable(mrdocs-test ${TEST_SUITE_FILES} ${UNIT_TEST_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/src/tool/PublicToolArgs.cpp)
342342
target_include_directories(mrdocs-test
343+
PUBLIC
344+
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/>"
345+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/>"
346+
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
343347
PRIVATE
344-
"${PROJECT_SOURCE_DIR}/include"
345348
"${PROJECT_SOURCE_DIR}/src"
349+
"${PROJECT_BINARY_DIR}/src"
346350
)
347351
target_link_libraries(mrdocs-test PUBLIC mrdocs-core)
348352
if (MRDOCS_CLANG)
@@ -358,9 +362,10 @@ if (MRDOCS_BUILD_TESTS)
358362
--action=test
359363
"${PROJECT_SOURCE_DIR}/test-files/golden-tests"
360364
"--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
361-
--generator=${testgenerator}
365+
--generate=${testgenerator}
362366
"--stdlib-includes=${LIBCXX_DIR}"
363367
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
368+
--report=2
364369
)
365370
foreach (action IN ITEMS test create update)
366371
add_custom_target(
@@ -371,9 +376,10 @@ if (MRDOCS_BUILD_TESTS)
371376
--action=${action}
372377
"${PROJECT_SOURCE_DIR}/test-files/golden-tests"
373378
"--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
374-
--generator=${testgenerator}
379+
--generate=${testgenerator}
375380
"--stdlib-includes=${LIBCXX_DIR}"
376381
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
382+
--report=2
377383
DEPENDS mrdocs-test
378384
)
379385
endforeach ()

src/test/TestArgs.cpp

+3-43
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
//
1010

1111
#include "TestArgs.hpp"
12-
#include <fmt/format.h>
13-
#include <cstddef>
1412
#include <vector>
1513

1614
namespace clang {
@@ -22,12 +20,9 @@ TestArgs TestArgs::instance_;
2220

2321
TestArgs::
2422
TestArgs()
25-
: commonCat("COMMON")
26-
27-
, usageText(
28-
R"(MrDocs Test Program
29-
)")
23+
: PublicToolArgs()
3024

25+
, usageText("MrDocs Test Program")
3126
, extraHelp(
3227
R"(
3328
EXAMPLES:
@@ -36,29 +31,17 @@ R"(
3631
mrdocs-test --action test friend.cpp
3732
)")
3833

39-
//
40-
// Common options
41-
//
42-
43-
, reportLevel(
44-
"report",
45-
llvm::cl::desc("The minimum reporting level (0 to 4)."),
46-
llvm::cl::init(2),
47-
llvm::cl::cat(commonCat))
48-
4934
//
5035
// Test options
5136
//
52-
5337
, action(
5438
"action",
5539
llvm::cl::desc(R"(Which action should be performed:)"),
5640
llvm::cl::init(test),
5741
llvm::cl::values(
5842
clEnumVal(test, "Compare output against expected."),
5943
clEnumVal(create, "Create missing expected documentation files."),
60-
clEnumVal(update, "Update all expected documentation files.")),
61-
llvm::cl::cat(commonCat))
44+
clEnumVal(update, "Update all expected documentation files.")))
6245

6346
, badOption(
6447
"bad",
@@ -69,28 +52,6 @@ R"(
6952
"unit",
7053
llvm::cl::desc("Run all or selected unit test suites."),
7154
llvm::cl::init(true))
72-
73-
, inputPaths(
74-
"inputs",
75-
llvm::cl::Sink,
76-
llvm::cl::desc("A list of directories and/or .cpp files to test."),
77-
llvm::cl::cat(commonCat))
78-
79-
, generator(
80-
"generator",
81-
llvm::cl::desc("The generator to use for tests."),
82-
llvm::cl::init("xml"))
83-
84-
, addons(
85-
"addons",
86-
llvm::cl::desc("The directory with the addons."),
87-
llvm::cl::cat(commonCat))
88-
89-
, stdlibIncludes(
90-
"stdlib-includes",
91-
llvm::cl::desc("A list of paths to std library headers."),
92-
llvm::cl::cat(commonCat))
93-
9455
{
9556
}
9657

@@ -104,7 +65,6 @@ hideForeignOptions()
10465

10566
std::vector<llvm::cl::Option const*> ours({
10667
&action,
107-
std::addressof(inputPaths),
10868
&badOption,
10969
&unitOption
11070
});

src/test/TestArgs.hpp

+2-12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define MRDOCS_TEST_TESTARGS_HPP
1313

1414
#include <llvm/Support/CommandLine.h>
15+
#include <tool/PublicToolArgs.hpp>
1516
#include <string>
1617

1718
namespace clang {
@@ -26,31 +27,20 @@ enum Action : int
2627

2728
/** Command line options and test settings.
2829
*/
29-
class TestArgs
30+
class TestArgs : public PublicToolArgs
3031
{
3132
TestArgs();
3233

33-
llvm::cl::OptionCategory commonCat;
34-
3534
public:
3635
static TestArgs instance_;
3736

3837
char const* usageText;
3938
llvm::cl::extrahelp extraHelp;
4039

41-
// Common options
42-
llvm::cl::opt<unsigned> reportLevel;
43-
4440
// Test options
4541
llvm::cl::opt<Action> action;
4642
llvm::cl::opt<bool> badOption;
4743
llvm::cl::opt<bool> unitOption;
48-
llvm::cl::list<std::string> inputPaths;
49-
50-
// Options replication public settings
51-
llvm::cl::opt<std::string> generator;
52-
llvm::cl::opt<std::string> addons;
53-
llvm::cl::list<std::string> stdlibIncludes;
5444

5545
// Hide all options that don't belong to us
5646
void hideForeignOptions();

src/test/TestMain.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
#include <llvm/Support/Signals.h>
2424
#include <stdlib.h>
2525

26-
int main(int argc, char** argv);
26+
int main(int argc, char const** argv);
2727

2828
namespace clang {
2929
namespace mrdocs {
3030

31-
void DoTestAction()
31+
void DoTestAction(char const** argv)
3232
{
3333
using namespace clang::mrdocs;
3434

35-
TestRunner runner(testArgs.generator);
36-
for(auto const& inputPath : testArgs.inputPaths)
37-
runner.checkPath(inputPath);
35+
TestRunner runner(testArgs.generate);
36+
for(auto const& inputPath : testArgs.inputs)
37+
runner.checkPath(inputPath, argv);
3838
auto const& results = runner.results;
3939

4040
std::stringstream os;
@@ -63,7 +63,7 @@ void DoTestAction()
6363
report::print(os.str());
6464
}
6565

66-
int test_main(int argc, char const* const* argv)
66+
int test_main(int argc, char const** argv)
6767
{
6868
// VFALCO this heap checking is too strong for
6969
// a clang tool's model of what is actually a leak.
@@ -80,10 +80,10 @@ int test_main(int argc, char const* const* argv)
8080

8181
// Apply reportLevel
8282
report::setMinimumLevel(report::getLevel(
83-
testArgs.reportLevel.getValue()));
83+
testArgs.report.getValue()));
8484

85-
if(! testArgs.inputPaths.empty())
86-
DoTestAction();
85+
if(!testArgs.inputs.empty())
86+
DoTestAction(argv);
8787

8888
if(testArgs.unitOption.getValue())
8989
test_suite::unit_test_main(argc, argv);
@@ -106,7 +106,7 @@ static void reportUnhandledException(
106106
} // mrdocs
107107
} // clang
108108

109-
int main(int argc, char** argv)
109+
int main(int argc, char const** argv)
110110
{
111111
try
112112
{

src/test/TestRunner.cpp

+3-9
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ handleDir(
264264
void
265265
TestRunner::
266266
checkPath(
267-
std::string inputPath)
267+
std::string inputPath,
268+
char const** argv)
268269
{
269270
namespace fs = llvm::sys::fs;
270271
namespace path = llvm::sys::path;
@@ -274,14 +275,6 @@ checkPath(
274275
// Set the reference directories for the test
275276
dirs_.configDir = inputPath;
276277
dirs_.cwd = dirs_.configDir;
277-
if (testArgs.addons.getValue() != "")
278-
{
279-
dirs_.mrdocsRoot = files::getParentDir(files::normalizePath(testArgs.addons.getValue()), 3);
280-
}
281-
else
282-
{
283-
report::warn("No addons directory specified to mrdocs tests");
284-
}
285278

286279
// See if inputPath references a file or directory
287280
auto fileType = files::getFileType(inputPath);
@@ -291,6 +284,7 @@ checkPath(
291284

292285
// Check for a directory-wide config
293286
Config::Settings dirSettings;
287+
testArgs.apply(dirSettings, dirs_, argv);
294288
dirSettings.sourceRoot = files::appendPath(inputPath, ".");
295289
dirSettings.stdlibIncludes.insert(
296290
dirSettings.stdlibIncludes.end(),

src/test/TestRunner.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class TestRunner
7979
This function checks the specified path
8080
and blocks until completed.
8181
*/
82-
void checkPath(std::string inputPath);
82+
void checkPath(std::string inputPath, char const** argv);
8383
};
8484

8585
} // mrdocs

0 commit comments

Comments
 (0)