Skip to content

Commit 9b7ec24

Browse files
committed
feat(util): run_all_tests script
1 parent 5902699 commit 9b7ec24

File tree

4 files changed

+512
-11
lines changed

4 files changed

+512
-11
lines changed

CMakeLists.txt

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ option(MRDOCS_INSTALL "Configure install target" ON)
2929
option(MRDOCS_PACKAGE "Build install package" ON)
3030
option(MRDOCS_BUILD_SHARED "Link shared" ${BUILD_SHARED_LIBS})
3131
option(MRDOCS_BUILD_TESTS "Build tests" ${BUILD_TESTING})
32+
option(MRDOCS_BUILD_STRICT_TESTS "Enable strict tests" ON)
3233
option(MRDOCS_REQUIRE_GIT "Git is required: not being able to extract version build is an error" ON)
3334
if (MRDOCS_BUILD_TESTS OR MRDOCS_INSTALL)
3435
option(MRDOCS_BUILD_DOCS "Build documentation" ON)
@@ -520,10 +521,39 @@ if (MRDOCS_BUILD_TESTS)
520521
)
521522
endforeach ()
522523

524+
#-------------------------------------------------
525+
# Self-documentation test (always run; warn-as-error toggled by strict flag)
526+
#-------------------------------------------------
527+
set(MRDOCS_SELF_DOC_OUTPUT "${CMAKE_BINARY_DIR}/docs/self-reference")
528+
set(MRDOCS_SELF_DOC_TAGFILE "${MRDOCS_SELF_DOC_OUTPUT}/reference.tag.xml")
529+
530+
add_test(NAME mrdocs-self-doc
531+
COMMAND
532+
mrdocs
533+
"${CMAKE_SOURCE_DIR}/CMakeLists.txt"
534+
"--config=${CMAKE_SOURCE_DIR}/docs/mrdocs.yml"
535+
"--output=${MRDOCS_SELF_DOC_OUTPUT}"
536+
--generator=adoc
537+
"--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
538+
"--stdlib-includes=${LIBCXX_DIR}"
539+
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
540+
"--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs"
541+
"--tagfile=${MRDOCS_SELF_DOC_TAGFILE}"
542+
--multipage=true
543+
--concurrency=16
544+
--log-level=debug
545+
$<$<BOOL:${MRDOCS_BUILD_STRICT_TESTS}>:--warn-as-error=true>
546+
)
547+
523548
#-------------------------------------------------
524549
# XML lint
525550
#-------------------------------------------------
526-
find_package(LibXml2)
551+
if (MRDOCS_BUILD_STRICT_TESTS)
552+
# Strict mode expects xml-lint to run; require LibXml2.
553+
find_package(LibXml2 REQUIRED)
554+
else()
555+
find_package(LibXml2)
556+
endif()
527557
if (LibXml2_FOUND)
528558
find_package(Java REQUIRED Runtime)
529559
# FindJava
@@ -541,7 +571,16 @@ if (MRDOCS_BUILD_TESTS)
541571
file(GLOB_RECURSE XML_SOURCES CONFIGURE_DEPENDS test-files/golden-tests/*.xml)
542572
add_test(NAME xml-lint
543573
COMMAND ${LIBXML2_XMLLINT_EXECUTABLE} --dropdtd --noout
544-
--relaxng ${CMAKE_CURRENT_BINARY_DIR}/mrdocs.rng ${XML_SOURCES}
574+
--relaxng ${CMAKE_CURRENT_BINARY_DIR}/mrdocs.rng ${XML_SOURCES}
575+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
576+
endif()
577+
578+
#-------------------------------------------------
579+
# YAML schema check
580+
#-------------------------------------------------
581+
if (PYTHON_EXECUTABLE)
582+
add_test(NAME yaml-schema-check
583+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/util/generate-yaml-schema.py --check
545584
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
546585
endif()
547586
endif()
@@ -589,7 +628,7 @@ if (MRDOCS_BUILD_DOCS)
589628
set(DOCS_BUILD_DIR ${DOCS_SOURCE_DIR}/build/site)
590629
set(DOCS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/doc/mrdocs/html)
591630

592-
# Add custom target for generating documentation
631+
# Add a custom target for generating documentation
593632
add_custom_target(generate_docs
594633
ALL
595634
COMMAND ${CMAKE_COMMAND} -E echo "Install npm dependencies"

docs/modules/ROOT/pages/contribute.adoc

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
This page contains information for contributors to the Mr.Docs project.
44
It is intended to provide an overview of the codebase and the process of adding new features.
55

6+
Before sending changes, run `python util/run_all_tests.py`.
7+
This script is treated as a “source of truth” pass that configures the preferred preset, builds, runs golden + unit + lint/schema/self-doc checks, installs into a local `install/<preset>` prefix, and (by default) builds docs using that fresh install.
8+
Not every policy can be enforced programmatically, but this script covers the checks that are automated; prefer it over ad-hoc command sequences.
9+
Use `--skip-docs` to omit docs or `--no-strict` to relax strict warning handling when needed.
10+
611
== Codebase Overview
712

813
The Mr.Docs codebase is divided into several modules:
@@ -49,19 +54,27 @@ As a last step, `DoGenerateAction` converts the public `Config` settings into a
4954
[#representing_symbols]
5055
== Representing Symbols
5156

52-
MrDocs has many categories of objects, where we utilize polymorphism with a fixed set of valid derived types, including Symbols (functions, classes, and enums), DocComment blocks, template parameters, template arguments, and data types. For each such family, we follow a consistent file layout. Most of these families are defined in the `mrdocs/Metadata` directory.
57+
MrDocs has many categories of objects, where we utilize polymorphism with a fixed set of valid derived types, including Symbols (functions, classes, and enums), DocComment blocks, template parameters, template arguments, and data types.
58+
For each such family, we follow a consistent file layout.
59+
Most of these families are defined in the `mrdocs/Metadata` directory.
5360

54-
Each base class is defined in its own header and, when necessary, implementation file. Each derived class also has its own header and implementation file. Finally, there is a single aggregator header file that includes all the derived headers. This file centralizes logic that requires knowledge of the full set of variants, such as visitors, comparison operators, and other operations that depend on the discriminator.
61+
Each base class is defined in its own header and, when necessary, implementation file.
62+
Each derived class also has its own header and implementation file.
63+
Finally, there is a single aggregator header file that includes all the derived headers.
64+
This file centralizes logic that requires knowledge of the full set of variants, such as visitors, comparison operators, and other operations that depend on the discriminator.
5565

56-
Suppose we have a polymorphic family of `Symbol` objects, with derived types `Function`, `Class`, and `Enum`. The files would be organized as follows:
66+
Suppose we have a polymorphic family of `Symbol` objects, with derived types `Function`, `Class`, and `Enum`.
67+
The files would be organized as follows:
5768

5869
* The `Symbol/SymbolNodes.inc` file defines the possible derived types and is used to generate code via macros.
5970
* The `Symbol/SymbolKind.hpp` file defines the `SymbolKind` enum, which is used as a discriminator for the derived types.
6071
* The base class `Symbol` is defined in `Symbol/BaseSymbol.hpp` and `Symbol/BaseSymbol.cpp` (if needed).
6172
* The available kinds of derived symbols are defined in `Symbol/<Derived>.hpp` and `Symbol/<Derived>.cpp` files, e.g., `Symbol/Function.hpp` and `Symbol/Function.cpp`.
6273
* The `Symbol.hpp` file includes all derived headers and defines operations that require knowledge of all variants, such as visitors and comparison operators.
6374

64-
This pattern keeps the individual derived types self-contained while making cross-variant operations explicit and localized. When adding a new derived type, contributors should create its header and source file alongside the existing ones and update the corresponding aggregator file to register the new variant. This keeps the codebase predictable, avoids scattering logic, and ensures that operations over polymorphic families remain easy to find and maintain.
75+
This pattern keeps the individual derived types self-contained while making cross-variant operations explicit and localized.
76+
When adding a new derived type, contributors should create its header and source file alongside the existing ones and update the corresponding aggregator file to register the new variant.
77+
This keeps the codebase predictable, avoids scattering logic, and ensures that operations over polymorphic families remain easy to find and maintain.
6578

6679
[#extract_symbols]
6780
=== Extracting Symbols
@@ -139,8 +152,7 @@ This is necessary to generate the full interface for user-defined types.
139152
After running the AST traversal on all translation units, `CorpusImpl::build` contains finalization steps for the `Corpus` object.
140153
At this point, we process C++ constructs that are not directly represented in the AST.
141154

142-
The first finalization step happens in `CorpusImpl::build` (`src/lib/Lib/CorpusImpl.cpp`), where the `Symbol` objects from a single translation unit
143-
are merged into a map containing the merged results from all other TUs.
155+
The first finalization step happens in `CorpusImpl::build` (`src/lib/Lib/CorpusImpl.cpp`), where the `Symbol` objects from a single translation unit are merged into a map containing the merged results from all other TUs.
144156
The merging step is necessary as there may be multiple identical definitions of the same entity.
145157
For instance, this represents the case where a function is declared at different points in the code base and might have different attributes or comments.
146158
At this step, the doc comments are also finalized.
@@ -267,7 +279,8 @@ Why This Approach:
267279
* Ensures new contributors are not lost when adapting to project style.
268280
* Encourages consistency without rigid automation.
269281

270-
General Advice: When in doubt, copy the style of the surrounding code. The `.clang-format` file is a tool to help you, not a rule to enforce blindly.
282+
General Advice: When in doubt, copy the style of the surrounding code.
283+
The `.clang-format` file is a tool to help you, not a rule to enforce blindly.
271284

272285
The utility script `./util/reformat.sh` can also be used to check a few project invariants, such as header guards and include order.
273286

@@ -277,4 +290,4 @@ If you find a bug or have a feature request, please open an issue on the MrDocs
277290

278291
If you would like to contribute a feature or bug fix, please open a pull request on the MrDocs GitHub repository: https://github.com/cppalliance/mrdocs/pulls
279292

280-
If you would like to discuss a feature or bug fix before opening a pull request, discussing happen in the `#mrdocs` channel on the Cpplang Slack: https://cpplang.slack.com/
293+
If you would like to discuss a feature or bug fix before opening a pull request, discussing happen in the `#mrdocs` channel on the Cpplang Slack: https://cpplang.slack.com/

util/README.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
= Build tools
22

33
This directory holds additional scripts and files for building and testing.
4+
5+
== Test runner
6+
7+
- Strict tests (self-doc, format check, warn-as-error) are enabled by default; pass `--no-strict` to disable `MRDOCS_BUILD_STRICT_TESTS`.
8+
- Run `python util/run_all_tests.py` to configure the best release/* preset for your OS, build, and execute the full ctest suite (golden tests first, then the rest).
9+
- The runner forces compiler warnings to be treated as errors with CI-matching flags: `-Werror -Wall` for gcc/clang and `/WX /W4` for MSVC, without clobbering preset defaults.
10+
- Add `--update-golden` to refresh golden fixtures before running the test suite when output diffs in error messages are intentional.
11+
- Use `--preset <name>` to override the automatic selection. The script prefers presets starting with `release/` (or `release-`) that match your OS and compiler, falling back to `debug/*` if needed.
12+
- After tests (and optional docs), the script installs into `install/<preset>` under the repo root to keep the prefix scoped to the workspace.
13+
- Docs build runs by default; pass `--skip-docs` to omit the documentation step. Docs are built after install with `MRDOCS_ROOT` pointed at the freshly installed prefix so the generated reference uses that version.
14+
- Strict tests (self-doc, format check, warn-as-error) are enabled by default; pass `--no-strict` to disable `MRDOCS_BUILD_STRICT_TESTS`.
15+
- `util/reformat.py` supports `--check` to validate formatting/include guards without modifying files (used by the strict test suite).

0 commit comments

Comments
 (0)