Skip to content

Commit

Permalink
test: asciidoc golden tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Oct 22, 2024
1 parent 1aca304 commit 2bc09e6
Show file tree
Hide file tree
Showing 96 changed files with 21,440 additions and 110 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/local
/temp
/test-files/py
/test-files/**/*.adoc
/test-files/**/*.bad.xml
docs/node_modules
docs/build
Expand Down
56 changes: 37 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ if (LLVM_ROOT)
"No <LLVM_ROOT>/lib/cmake/llvm found.\n"
"Please set LLVM_ROOT to the root of LLVM install.\n")
endif()
message(STATUS "LLVM_ROOT: ${LLVM_ROOT}")
endif()
if (Clang_ROOT)
# Clang_ROOT is absolute
Expand All @@ -95,7 +96,19 @@ find_package(Clang REQUIRED CONFIG)

if (LLVM_ROOT)
set(LIBCXX_DIR "${LLVM_ROOT}/include/c++/v1/")
message(STATUS "LIBCXX_DIR: ${LIBCXX_DIR}")
if (NOT EXISTS "${LIBCXX_DIR}")
message(FATAL_ERROR
"LIBCXX_DIR (${LIBCXX_DIR}) does not exist.\n"
"LLVM_ROOT is set, but LIBCXX_DIR (/include/c++/v1) does not exist.\n")
endif()
set(STDLIB_INCLUDE_DIR "${LLVM_ROOT}/lib/clang/${Clang_VERSION_MAJOR}/include/")
message(STATUS "STDLIB_INCLUDE_DIR: ${STDLIB_INCLUDE_DIR}")
if (NOT EXISTS "${STDLIB_INCLUDE_DIR}")
message(FATAL_ERROR
"STDLIB_INCLUDE_DIR (${STDLIB_INCLUDE_DIR}) does not exist.\n"
"LLVM_ROOT is set, but STDLIB_INCLUDE_DIR (/lib/clang/${Clang_VERSION_MAJOR}/include) does not exist.\n")
endif()
endif()

list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
Expand Down Expand Up @@ -337,29 +350,34 @@ if (MRDOCS_BUILD_TESTS)
endif ()
target_compile_definitions(mrdocs-test PRIVATE -DMRDOCS_TEST_FILES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test-files")
add_test(NAME mrdocs-unit-tests COMMAND mrdocs-test --unit=true)
add_test(NAME mrdocs-golden-tests
COMMAND
mrdocs-test
--unit=false
--action=test
"${PROJECT_SOURCE_DIR}/test-files/golden-tests"
--addons="${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
--system-includes="${LIBCXX_DIR}"
--system-includes="${STDLIB_INCLUDE_DIR}")
foreach (action IN ITEMS create update)
add_custom_target(
mrdocs-${action}-test-fixtures
foreach (testgenerator IN ITEMS xml adoc)
add_test(NAME mrdocs-golden-tests-${testgenerator}
COMMAND
mrdocs-test
--unit=false
--action=${action}
--action=test
"${PROJECT_SOURCE_DIR}/test-files/golden-tests"
--addons="${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
--system-includes="${LIBCXX_DIR}"
--system-includes="${STDLIB_INCLUDE_DIR}"
DEPENDS mrdocs-test
"--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
--generator=${testgenerator}
"--stdlib-includes=${LIBCXX_DIR}"
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
)
endforeach ()
foreach (action IN ITEMS test create update)
add_custom_target(
mrdocs-${action}-test-fixtures-${testgenerator}
COMMAND
mrdocs-test
--unit=false
--action=${action}
"${PROJECT_SOURCE_DIR}/test-files/golden-tests"
"--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
--generator=${testgenerator}
"--stdlib-includes=${LIBCXX_DIR}"
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
DEPENDS mrdocs-test
)
endforeach ()
endforeach()

#-------------------------------------------------
# XML lint
Expand Down Expand Up @@ -436,7 +454,7 @@ if (MRDOCS_BUILD_DOCS)
COMMAND ${CMAKE_COMMAND} -E echo "Install npm dependencies"
COMMAND ${NPM_EXECUTABLE} install
COMMAND ${CMAKE_COMMAND} -E echo "Run Antora"
COMMAND ${NPX_EXECUTABLE} antora local-antora-playbook.yml
COMMAND ${NPX_EXECUTABLE} antora antora-playbook.yml
WORKING_DIRECTORY ${DOCS_SOURCE_DIR}
COMMENT "Generating MrDocs documentation"
USES_TERMINAL
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Lib/ConfigOptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"name": "inputs",
"command-line-only": true,
"brief": "Configuration or compilation database files",
"details": "The inputs are configuration files or compilation database files that are used to generate the documentation. These inputs can be configuration files or compilation database files. When the input ends with `mrdocs.yml`, it is interpreted as a configuration file, the file is read and the options are used to generate the documentation as if it was provided to the `config` option. When the input ends with `compilation_database.json` or `CMakeLists.txt`, it is interpreted as a compilation database file, the file is read and the compiler flags are used to generate the documentation as if it was provided to the `compilation-database` option.",
"details": "The inputs are configuration files or compilation database files that used to generate the documentation. When the input ends with `mrdocs.yml`, it is interpreted as a configuration file, the file is read and the options are used to generate the documentation as if it was provided to the `config` option. When the input ends with `compilation_database.json` or `CMakeLists.txt`, it is interpreted as a compilation database file, the file is read and the compiler flags are used to generate the documentation as if it was provided to the `compilation-database` option.",
"type": "list<path>",
"default": [],
"command-line-sink": true,
Expand Down
19 changes: 10 additions & 9 deletions src/test/TestArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ R"(
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.")),
clEnumVal(create, "Create missing expected documentation files."),
clEnumVal(update, "Update all expected documentation files.")),
llvm::cl::cat(commonCat))

, badOption(
Expand All @@ -76,20 +76,21 @@ R"(
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))

, systemIncludes(
"system-includes",
llvm::cl::desc("A list of paths to the system headers."),
, stdlibIncludes(
"stdlib-includes",
llvm::cl::desc("A list of paths to std library headers."),
llvm::cl::cat(commonCat))

, includes(
"includes",
llvm::cl::desc("A list of paths to additional include directories."),
llvm::cl::cat(commonCat))
{
}

Expand Down
6 changes: 4 additions & 2 deletions src/test/TestArgs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ class TestArgs
llvm::cl::opt<bool> badOption;
llvm::cl::opt<bool> unitOption;
llvm::cl::list<std::string> inputPaths;

// Options replication public settings
llvm::cl::opt<std::string> generator;
llvm::cl::opt<std::string> addons;
llvm::cl::list<std::string> systemIncludes;
llvm::cl::list<std::string> includes;
llvm::cl::list<std::string> stdlibIncludes;

// Hide all options that don't belong to us
void hideForeignOptions();
Expand Down
6 changes: 3 additions & 3 deletions src/test/TestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void DoTestAction()
{
using namespace clang::mrdocs;

TestRunner runner;
TestRunner runner(testArgs.generator);
for(auto const& inputPath : testArgs.inputPaths)
runner.checkPath(inputPath);
auto const& results = runner.results;
Expand All @@ -55,9 +55,9 @@ void DoTestAction()
os <<
report::numberOf(results.numberOfDirs.load(),
"directory", "directories") << " visited";
if(auto n = results.expectedXmlMatching.load())
if(auto n = results.expectedDocsMatching.load())
os << ", " << report::numberOf(n, "file", "files") << " matched";
if(auto n = results.expectedXmlWritten.load())
if(auto n = results.expectedDocsWritten.load())
os << ", " << report::numberOf(n, "file", "files") << " written";
os << ".\n";
report::print(os.str());
Expand Down
Loading

0 comments on commit 2bc09e6

Please sign in to comment.