Add "How do I do compile pass/fail testing?" #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New HOWTO (as promised way back in Feb 2022 on Slack) on how to do compile pass/fail testing using
build2.First there is some brief discussion on what compile pass/fail testing is, why you might want to do it, and some pitfalls.
Then ad hoc recipes are used with custom aliases and pattern matching to select all
cxxfiles in a directory, and only attempt to compile them during thetestoperation. There are two slightly different recipes: one for tests that pass when compilation succeeds, and one for tests that fail when compilation succeeds (and pass when compilation fails).The recipes are not perfect. There are two areas of concern, one major, one minor:
The compile command has to be manually assembled by scraping together configuration information from the build system. This causes two problems:
The include path, necessary to be able to find project includes, is hard-coded. It will not only have to be adjusted if the project is organized differently, it also won’t work with installed headers.
The constructed compile command may not be valid for some compilers. For example, the
-c“only compile” flag and the-ooutput file name flag are both valid with GCC and Clang… but will they work with MSVC? (Don’t know myself, never used MSVC.) Will they work for all compilers?This is a minor nit, but the output messages are printed with
echo, rather thandiag, becausediagprints them unconditionally (whether the test passes or fails). However,echodoes not suppress the regular compiling diagnostic message. This means that the compilation steps are printed unnecessarily, which just creates noise.It would be nicer if the only output when tests pass are the “compile-pass/fail-test xxx passes” messages. (If a test fails, then the current output—either compiler diagnostics, or build system diagnostics—is fine.)
Hope this helps!