Skip to content

Conversation

@DarkerStar
Copy link

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 cxx files in a directory, and only attempt to compile them during the test operation. 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:

  1. The compile command has to be manually assembled by scraping together configuration information from the build system. This causes two problems:

    1. 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.

    2. The constructed compile command may not be valid for some compilers. For example, the -c “only compile” flag and the -o output 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?

  2. This is a minor nit, but the output messages are printed with echo, rather than diag, because diag prints them unconditionally (whether the test passes or fails). However, echo does 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant