Skip to content

Commit

Permalink
More cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
horenmar committed Aug 12, 2024
1 parent fad6741 commit 822526e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
42 changes: 21 additions & 21 deletions src/catch2/internal/catch_output_redirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Catch {
namespace {
//! A no-op implementation, used if no reporter wants output
//! redirection.
class NoopRedirect : public OutputRedirectNew {
class NoopRedirect : public OutputRedirect {
void activateImpl() override {}
void deactivateImpl() override {}
std::string getStdout() override { return {}; }
Expand Down Expand Up @@ -66,7 +66,7 @@ namespace Catch {
* Redirects the `std::cout`, `std::cerr`, `std::clog` streams,
* but does not touch the actual `stdout`/`stderr` file descriptors.
*/
class StreamRedirect : public OutputRedirectNew {
class StreamRedirect : public OutputRedirect {
ReusableStringStream m_redirectedOut, m_redirectedErr;
RedirectedStreamNew m_cout, m_cerr, m_clog;

Expand Down Expand Up @@ -100,15 +100,15 @@ namespace Catch {
// to create a file inside system folder, thus requiring elevated
// privileges for the binary), so we have to use tmpnam(_s) and
// create the file ourselves there.
class TempFile2 {
class TempFile {
public:
TempFile2( TempFile2 const& ) = delete;
TempFile2& operator=( TempFile2 const& ) = delete;
TempFile2( TempFile2&& ) = delete;
TempFile2& operator=( TempFile2&& ) = delete;
TempFile( TempFile const& ) = delete;
TempFile& operator=( TempFile const& ) = delete;
TempFile( TempFile&& ) = delete;
TempFile& operator=( TempFile&& ) = delete;

# if defined( _MSC_VER )
TempFile2() {
TempFile() {
if ( tmpnam_s( m_buffer ) ) {
CATCH_RUNTIME_ERROR( "Could not get a temp filename" );
}
Expand All @@ -124,15 +124,15 @@ namespace Catch {
}
}
# else
TempFile2() {
TempFile() {
m_file = std::tmpfile();
if ( !m_file ) {
CATCH_RUNTIME_ERROR( "Could not create a temp file." );
}
}
# endif

~TempFile2() {
~TempFile() {
// TBD: What to do about errors here?
std::fclose( m_file );
// We manually create the file on Windows only, on Linux
Expand Down Expand Up @@ -180,8 +180,8 @@ namespace Catch {
* Works by replacing the file descriptors numbered 1 and 2
* with an open temporary file.
*/
class FileRedirect : public OutputRedirectNew {
TempFile2 m_outFile, m_errFile;
class FileRedirect : public OutputRedirect {
TempFile m_outFile, m_errFile;
int m_originalOut = -1;
int m_originalErr = -1;

Expand Down Expand Up @@ -239,22 +239,22 @@ namespace Catch {

} // end namespace

bool isRedirectAvailable( OutputRedirectNew::Kind kind ) {
bool isRedirectAvailable( OutputRedirect::Kind kind ) {
switch ( kind ) {
// These two are always available
case OutputRedirectNew::None:
case OutputRedirectNew::Streams:
case OutputRedirect::None:
case OutputRedirect::Streams:
return true;
#if defined( CATCH_CONFIG_NEW_CAPTURE )
case OutputRedirectNew::FileDescriptors:
case OutputRedirect::FileDescriptors:
return true;
#endif
default:
return false;
}
}

Detail::unique_ptr<OutputRedirectNew> makeOutputRedirect( bool actual ) {
Detail::unique_ptr<OutputRedirect> makeOutputRedirect( bool actual ) {
if ( actual ) {
// TODO: Clean this up later
#if defined( CATCH_CONFIG_NEW_CAPTURE )
Expand All @@ -267,18 +267,18 @@ namespace Catch {
}
}

RedirectGuard scopedActivate( OutputRedirectNew& redirectImpl ) {
RedirectGuard scopedActivate( OutputRedirect& redirectImpl ) {
return RedirectGuard( true, redirectImpl );
}

RedirectGuard scopedDeactivate( OutputRedirectNew& redirectImpl ) {
RedirectGuard scopedDeactivate( OutputRedirect& redirectImpl ) {
return RedirectGuard( false, redirectImpl );
}

OutputRedirectNew::~OutputRedirectNew() = default;
OutputRedirect::~OutputRedirect() = default;

RedirectGuard::RedirectGuard( bool activate,
OutputRedirectNew& redirectImpl ):
OutputRedirect& redirectImpl ):
m_redirect( &redirectImpl ),
m_activate( activate ),
m_previouslyActive( redirectImpl.isActive() ) {
Expand Down
16 changes: 8 additions & 8 deletions src/catch2/internal/catch_output_redirect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace Catch {

class OutputRedirectNew {
class OutputRedirect {
bool m_redirectActive = false;
virtual void activateImpl() = 0;
virtual void deactivateImpl() = 0;
Expand All @@ -34,7 +34,7 @@ namespace Catch {
FileDescriptors,
};

virtual ~OutputRedirectNew(); // = default;
virtual ~OutputRedirect(); // = default;

// TODO: check that redirect is not active before retrieving stdout/stderr?
virtual std::string getStdout() = 0;
Expand All @@ -53,17 +53,17 @@ namespace Catch {
}
};

bool isRedirectAvailable( OutputRedirectNew::Kind kind);
Detail::unique_ptr<OutputRedirectNew> makeOutputRedirect( bool actual );
bool isRedirectAvailable( OutputRedirect::Kind kind);
Detail::unique_ptr<OutputRedirect> makeOutputRedirect( bool actual );

class RedirectGuard {
OutputRedirectNew* m_redirect;
OutputRedirect* m_redirect;
bool m_activate;
bool m_previouslyActive;
bool m_moved = false;

public:
RedirectGuard( bool activate, OutputRedirectNew& redirectImpl );
RedirectGuard( bool activate, OutputRedirect& redirectImpl );
~RedirectGuard() noexcept( false );

RedirectGuard( RedirectGuard const& ) = delete;
Expand All @@ -74,8 +74,8 @@ namespace Catch {
RedirectGuard& operator=( RedirectGuard&& rhs ) noexcept;
};

RedirectGuard scopedActivate( OutputRedirectNew& redirectImpl );
RedirectGuard scopedDeactivate( OutputRedirectNew& redirectImpl );
RedirectGuard scopedActivate( OutputRedirect& redirectImpl );
RedirectGuard scopedDeactivate( OutputRedirect& redirectImpl );

} // end namespace Catch

Expand Down
4 changes: 2 additions & 2 deletions src/catch2/internal/catch_run_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Catch {
class IConfig;
class IEventListener;
using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
class OutputRedirectNew;
class OutputRedirect;

///////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -149,7 +149,7 @@ namespace Catch {
std::vector<SectionEndInfo> m_unfinishedSections;
std::vector<ITracker*> m_activeSections;
TrackerContext m_trackerContext;
Detail::unique_ptr<OutputRedirectNew> m_outputRedirect;
Detail::unique_ptr<OutputRedirect> m_outputRedirect;
FatalConditionHandler m_fatalConditionhandler;
bool m_lastAssertionPassed = false;
bool m_shouldReportUnexpected = true;
Expand Down

0 comments on commit 822526e

Please sign in to comment.