Allow disabling the implementation of the new output capture

As it turns out, some platforms do not provide things like `dup`,
or `std::tmpfile`, but they do provide streams...

Closes #1335
Related to #1311
This commit is contained in:
Martin Hořeňovský 2018-07-13 20:27:00 +02:00
parent 76790604f5
commit 9ee4c1db52
3 changed files with 34 additions and 11 deletions

View File

@ -95,6 +95,12 @@
# define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
#endif
////////////////////////////////////////////////////////////////////////////////
// PS4
#if defined(__ORBIS__)
# define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE
#endif
////////////////////////////////////////////////////////////////////////////////
// Cygwin
#ifdef __CYGWIN__
@ -165,6 +171,13 @@
# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
#endif
#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE
#endif
#if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE)
# define CATCH_CONFIG_NEW_CAPTURE
#endif
#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS

View File

@ -15,6 +15,7 @@
#include <sstream>
#include <stdexcept>
#if defined(CATCH_CONFIG_NEW_CAPTURE)
#if defined(_MSC_VER)
#include <io.h> //_dup and _dup2
#define dup _dup
@ -23,6 +24,8 @@
#else
#include <unistd.h> // dup and dup2
#endif
#endif
namespace Catch {
@ -48,6 +51,7 @@ namespace Catch {
auto RedirectedStdErr::str() const -> std::string { return m_rss.str(); }
#if defined(CATCH_CONFIG_NEW_CAPTURE)
#if defined(_MSC_VER)
TempFile::TempFile() {
@ -122,11 +126,14 @@ namespace Catch {
m_stderrDest += m_stderrFile.getContents();
}
#endif // CATCH_CONFIG_NEW_CAPTURE
} // namespace Catch
#if defined(CATCH_CONFIG_NEW_CAPTURE)
#if defined(_MSC_VER)
#undef dup
#undef dup2
#undef fileno
#endif
#endif

View File

@ -47,6 +47,8 @@ namespace Catch {
};
#if defined(CATCH_CONFIG_NEW_CAPTURE)
// Windows's implementation of std::tmpfile is terrible (it tries
// to create a file inside system folder, thus requiring elevated
// privileges for the binary), so we have to use tmpnam(_s) and
@ -92,6 +94,7 @@ namespace Catch {
std::string& m_stderrDest;
};
#endif
} // end namespace Catch