mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Add an experimental new way of capturing stdout/stderr
Unlike the relatively non-invasive old way of capturing stdout/stderr, this new way is also able to capture output from C's stdlib functions such as `printf`. This is done by redirecting stdout and stderr file descriptors to a file, and then reading this file back. This approach has two sizeable drawbacks: 1) Performance, obviously. Previously an installed capture made the program run faster (as long as it was then discarded), because a call to `std::cout` did not result in text output to the console. This new capture method in fact forces disk IO. While it is likely that any modern OS will keep this file in memory-cache and might never actually issue the IO to the backing storage, it is still a possibility and calls to the file system are not free. 2) Nonportability. While POSIX is usually assumed portable, and this implementation relies only on a very common parts of it, it is no longer standard C++ (or just plain C) and thus might not be available on some obscure platforms. Different C libs might also implement the relevant functions in a less-than-useful ways (e.g. MS's `tmpfile` generates a temp file inside system folder, so it will not work without elevated privileges and thus is useless). These two drawbacks mean that, at least for now, the new capture is opt-in. To opt-in, `CATCH_CONFIG_EXPERIMENTAL_REDIRECT` needs to be defined in the implementation file. Closes #1243
This commit is contained in:
@@ -121,6 +121,7 @@ by using `_NO_` in the macro, e.g. `CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS`.
|
||||
CATCH_CONFIG_DISABLE_STRINGIFICATION // Disable stringifying the original expression
|
||||
CATCH_CONFIG_DISABLE // Disables assertions and test case registration
|
||||
CATCH_CONFIG_WCHAR // Enables use of wchart_t
|
||||
CATCH_CONFIG_EXPERIMENTAL_REDIRECT // Enables the new (experimental) way of capturing stdout/stderr
|
||||
|
||||
Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, because some versions of MinGW do not have the necessary Win32 API support.
|
||||
|
||||
@@ -131,7 +132,9 @@ Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC,
|
||||
`CATCH_CONFIG_WCHAR` is on by default, but can be disabled. Currently
|
||||
it is only used in support for DJGPP cross-compiler.
|
||||
|
||||
These toggles can be disabled by using `_NO_` form of the toggle, e.g. `CATCH_CONFIG_NO_WINDOWS_SEH`.
|
||||
With the exception of `CATCH_CONFIG_EXPERIMENTAL_REDIRECT`,
|
||||
these toggles can be disabled by using `_NO_` form of the toggle,
|
||||
e.g. `CATCH_CONFIG_NO_WINDOWS_SEH`.
|
||||
|
||||
### `CATCH_CONFIG_FAST_COMPILE`
|
||||
Defining this flag speeds up compilation of test files by ~20%, by making 2 changes:
|
||||
|
Reference in New Issue
Block a user