mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-23 05:46:11 +01:00
Refactored ConsoleColour impl. Tweaked the (Windows) colours a bit.
Also fixed issue that would cause warnings on some compilers when doing REQUIRE( p ); where p is a pointer. Moved to build 23
This commit is contained in:
parent
a04981b450
commit
3df6c0d1b4
2
README
2
README
@ -1,4 +1,4 @@
|
|||||||
CATCH v0.9 build 22 (integration branch)
|
CATCH v0.9 build 23 (integration branch)
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
|
|
||||||
CATCH is an automated test framework for C, C++ and Objective-C.
|
CATCH is an automated test framework for C, C++ and Objective-C.
|
||||||
|
@ -70,7 +70,7 @@ inline bool isTrue( bool value ){ return value; }
|
|||||||
if( internal_catch_action & Catch::ResultAction::Debug ) BreakIntoDebugger(); \
|
if( internal_catch_action & Catch::ResultAction::Debug ) BreakIntoDebugger(); \
|
||||||
if( internal_catch_action & Catch::ResultAction::Abort ) throw Catch::TestFailureException(); \
|
if( internal_catch_action & Catch::ResultAction::Abort ) throw Catch::TestFailureException(); \
|
||||||
if( !Catch::shouldContinueOnFailure( resultDisposition ) ) throw Catch::TestFailureException(); \
|
if( !Catch::shouldContinueOnFailure( resultDisposition ) ) throw Catch::TestFailureException(); \
|
||||||
if( Catch::isTrue( false ) ){ bool this_is_here_to_invoke_warnings = ( originalExpr ); Catch::isTrue( this_is_here_to_invoke_warnings ); } \
|
Catch::isTrue( false && originalExpr ); \
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -12,11 +12,7 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
struct ConsoleColourImpl;
|
struct IConsoleColourCodes : NonCopyable {
|
||||||
|
|
||||||
class TextColour : NonCopyable {
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum Colours {
|
enum Colours {
|
||||||
None,
|
None,
|
||||||
|
|
||||||
@ -31,12 +27,17 @@ namespace Catch {
|
|||||||
ReconstructedExpression
|
ReconstructedExpression
|
||||||
};
|
};
|
||||||
|
|
||||||
|
virtual void set( Colours colour ) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TextColour : public IConsoleColourCodes {
|
||||||
|
public:
|
||||||
TextColour( Colours colour = None );
|
TextColour( Colours colour = None );
|
||||||
void set( Colours colour );
|
void set( Colours colour );
|
||||||
~TextColour();
|
~TextColour();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConsoleColourImpl* m_impl;
|
IConsoleColourCodes* m_impl;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
@ -10,102 +10,36 @@
|
|||||||
|
|
||||||
#include "catch_console_colour.hpp"
|
#include "catch_console_colour.hpp"
|
||||||
|
|
||||||
#if !defined(CATCH_CONFIG_USE_ANSI_COLOUR_CODES) && !defined(CATCH_PLATFORM_WINDOWS)
|
#if defined ( CATCH_PLATFORM_WINDOWS ) /////////////////////////////////////////
|
||||||
#define CATCH_CONFIG_USE_ANSI_COLOUR_CODES 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined( CATCH_CONFIG_USE_ANSI_COLOUR_CODES )
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
// use POSIX/ ANSI console terminal codes
|
|
||||||
// Implementation contributed by Adam Strzelecki (http://github.com/nanoant)
|
|
||||||
// https://github.com/philsquared/Catch/pull/131
|
|
||||||
|
|
||||||
TextColour::TextColour( Colours colour ) {
|
|
||||||
if( colour )
|
|
||||||
set( colour );
|
|
||||||
}
|
|
||||||
|
|
||||||
TextColour::~TextColour() {
|
|
||||||
set( TextColour::None );
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace { const char colourEscape = '\033'; }
|
|
||||||
|
|
||||||
inline bool shouldUseColour() {
|
|
||||||
static bool s_shouldUseColour
|
|
||||||
= CATCH_CONFIG_USE_ANSI_COLOUR_CODES != 0 &&
|
|
||||||
isatty( fileno(stdout) ) &&
|
|
||||||
!isDebuggerActive();
|
|
||||||
return s_shouldUseColour;
|
|
||||||
}
|
|
||||||
void TextColour::set( Colours colour ) {
|
|
||||||
if( shouldUseColour() ) {
|
|
||||||
switch( colour ) {
|
|
||||||
case TextColour::FileName:
|
|
||||||
std::cout << colourEscape << "[0m"; // white/ normal
|
|
||||||
break;
|
|
||||||
case TextColour::ResultError:
|
|
||||||
std::cout << colourEscape << "[1;31m"; // bold red
|
|
||||||
break;
|
|
||||||
case TextColour::ResultSuccess:
|
|
||||||
std::cout << colourEscape << "[1;32m"; // bold green
|
|
||||||
break;
|
|
||||||
case TextColour::Error:
|
|
||||||
std::cout << colourEscape << "[0;31m"; // red
|
|
||||||
break;
|
|
||||||
case TextColour::Success:
|
|
||||||
std::cout << colourEscape << "[0;32m"; // green
|
|
||||||
break;
|
|
||||||
case TextColour::OriginalExpression:
|
|
||||||
std::cout << colourEscape << "[0;36m"; // cyan
|
|
||||||
break;
|
|
||||||
case TextColour::ReconstructedExpression:
|
|
||||||
std::cout << colourEscape << "[0;33m"; // yellow
|
|
||||||
break;
|
|
||||||
case TextColour::None:
|
|
||||||
std::cout << colourEscape << "[0m"; // reset
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Catch
|
|
||||||
|
|
||||||
#elif defined ( CATCH_PLATFORM_WINDOWS )
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
namespace Catch {
|
namespace {
|
||||||
|
using namespace Catch;
|
||||||
|
|
||||||
namespace {
|
WORD mapConsoleColour( IConsoleColourCodes::Colours colour ) {
|
||||||
|
switch( colour ) {
|
||||||
WORD mapConsoleColour( TextColour::Colours colour ) {
|
case IConsoleColourCodes::FileName:
|
||||||
switch( colour ) {
|
return FOREGROUND_INTENSITY; // greyed out
|
||||||
case TextColour::FileName:
|
case IConsoleColourCodes::ResultError:
|
||||||
return FOREGROUND_INTENSITY; // greyed out
|
return FOREGROUND_RED | FOREGROUND_INTENSITY; // bright red
|
||||||
case TextColour::ResultError:
|
case IConsoleColourCodes::ResultSuccess:
|
||||||
return FOREGROUND_RED | FOREGROUND_INTENSITY; // bright red
|
return FOREGROUND_GREEN | FOREGROUND_INTENSITY; // bright green
|
||||||
case TextColour::ResultSuccess:
|
case IConsoleColourCodes::Error:
|
||||||
return FOREGROUND_GREEN | FOREGROUND_INTENSITY; // bright green
|
return FOREGROUND_RED | FOREGROUND_INTENSITY; // bright red
|
||||||
case TextColour::Error:
|
case IConsoleColourCodes::Success:
|
||||||
return FOREGROUND_RED; // dark red
|
return FOREGROUND_GREEN; // dark green
|
||||||
case TextColour::Success:
|
case IConsoleColourCodes::OriginalExpression:
|
||||||
return FOREGROUND_GREEN; // dark green
|
return FOREGROUND_BLUE | FOREGROUND_GREEN; // turquoise
|
||||||
case TextColour::OriginalExpression:
|
case IConsoleColourCodes::ReconstructedExpression:
|
||||||
return FOREGROUND_BLUE | FOREGROUND_GREEN; // turquoise
|
return FOREGROUND_RED | FOREGROUND_GREEN; // greeny-yellow
|
||||||
case TextColour::ReconstructedExpression:
|
default: return 0;
|
||||||
return FOREGROUND_RED | FOREGROUND_GREEN; // greeny-yellow
|
|
||||||
default: return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ConsoleColourImpl {
|
struct WindowsConsoleColourCodes : IConsoleColourCodes {
|
||||||
|
|
||||||
ConsoleColourImpl()
|
WindowsConsoleColourCodes()
|
||||||
: hStdout( GetStdHandle(STD_OUTPUT_HANDLE) ),
|
: hStdout( GetStdHandle(STD_OUTPUT_HANDLE) ),
|
||||||
wOldColorAttrs( 0 )
|
wOldColorAttrs( 0 )
|
||||||
{
|
{
|
||||||
@ -113,11 +47,11 @@ namespace Catch {
|
|||||||
wOldColorAttrs = csbiInfo.wAttributes;
|
wOldColorAttrs = csbiInfo.wAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ConsoleColourImpl() {
|
~WindowsConsoleColourCodes() {
|
||||||
SetConsoleTextAttribute( hStdout, wOldColorAttrs );
|
SetConsoleTextAttribute( hStdout, wOldColorAttrs );
|
||||||
}
|
}
|
||||||
|
|
||||||
void set( TextColour::Colours colour ) {
|
void set( Colours colour ) {
|
||||||
WORD consoleColour = mapConsoleColour( colour );
|
WORD consoleColour = mapConsoleColour( colour );
|
||||||
if( consoleColour > 0 )
|
if( consoleColour > 0 )
|
||||||
SetConsoleTextAttribute( hStdout, consoleColour );
|
SetConsoleTextAttribute( hStdout, consoleColour );
|
||||||
@ -128,11 +62,89 @@ namespace Catch {
|
|||||||
WORD wOldColorAttrs;
|
WORD wOldColorAttrs;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextColour::TextColour( Colours colour )
|
inline bool shouldUseColourForPlatform() {
|
||||||
: m_impl( new ConsoleColourImpl() )
|
return true;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
typedef WindowsConsoleColourCodes PlatformConsoleColourCodes;
|
||||||
|
|
||||||
|
} // end anon namespace
|
||||||
|
|
||||||
|
#else // Not Windows - assumed to be POSIX compatible //////////////////////////
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
using namespace Catch;
|
||||||
|
|
||||||
|
// use POSIX/ ANSI console terminal codes
|
||||||
|
// Implementation contributed by Adam Strzelecki (http://github.com/nanoant)
|
||||||
|
// https://github.com/philsquared/Catch/pull/131
|
||||||
|
|
||||||
|
struct AnsiConsoleColourCodes : IConsoleColourCodes {
|
||||||
|
|
||||||
|
~AnsiConsoleColourCodes() {
|
||||||
|
set( None );
|
||||||
|
}
|
||||||
|
|
||||||
|
void set( Colours colour ) {
|
||||||
|
const char colourEscape = '\033';
|
||||||
|
switch( colour ) {
|
||||||
|
case FileName:
|
||||||
|
std::cout << colourEscape << "[0m"; // white/ normal
|
||||||
|
break;
|
||||||
|
case ResultError:
|
||||||
|
std::cout << colourEscape << "[0;31m"; // red
|
||||||
|
break;
|
||||||
|
case ResultSuccess:
|
||||||
|
std::cout << colourEscape << "[0;32m"; // green
|
||||||
|
break;
|
||||||
|
case Error:
|
||||||
|
std::cout << colourEscape << "[1;31m"; // bold red
|
||||||
|
break;
|
||||||
|
case Success:
|
||||||
|
std::cout << colourEscape << "[1;32m"; // bold green
|
||||||
|
break;
|
||||||
|
case OriginalExpression:
|
||||||
|
std::cout << colourEscape << "[0;36m"; // cyan
|
||||||
|
break;
|
||||||
|
case ReconstructedExpression:
|
||||||
|
std::cout << colourEscape << "[0;33m"; // yellow
|
||||||
|
break;
|
||||||
|
case None:
|
||||||
|
std::cout << colourEscape << "[0m"; // reset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool shouldUseColourForPlatform() {
|
||||||
|
return isatty( fileno(stdout) );
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef AnsiConsoleColourCodes PlatformConsoleColourCodes;
|
||||||
|
|
||||||
|
} // namespace Catch
|
||||||
|
|
||||||
|
#endif // not Windows
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
struct NoConsoleColourCodes : IConsoleColourCodes {
|
||||||
|
void set( Colours ) {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
TextColour::TextColour( Colours colour ) : m_impl( NULL ) {
|
||||||
|
static bool s_shouldUseColour = shouldUseColourForPlatform() &&
|
||||||
|
!isDebuggerActive();
|
||||||
|
if( s_shouldUseColour )
|
||||||
|
m_impl = new PlatformConsoleColourCodes();
|
||||||
|
else
|
||||||
|
m_impl = new NoConsoleColourCodes();
|
||||||
|
|
||||||
if( colour )
|
if( colour )
|
||||||
m_impl->set( colour );
|
set( colour );
|
||||||
}
|
}
|
||||||
|
|
||||||
TextColour::~TextColour() {
|
TextColour::~TextColour() {
|
||||||
@ -145,16 +157,4 @@ namespace Catch {
|
|||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
TextColour::TextColour( Colours ){}
|
|
||||||
TextColour::~TextColour(){}
|
|
||||||
void TextColour::set( Colours ){}
|
|
||||||
|
|
||||||
} // end namespace Catch
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
// These numbers are maintained by a script
|
// These numbers are maintained by a script
|
||||||
Version libraryVersion( 0, 9, 22, "integration" );
|
Version libraryVersion( 0, 9, 23, "integration" );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
CatchSelfTest is a CATCH v0.9 b22 (integration) host application.
|
CatchSelfTest is a CATCH v0.9 b23 (integration) host application.
|
||||||
Run with -? for options
|
Run with -? for options
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
@ -4286,7 +4286,7 @@ with expansion:
|
|||||||
101 test cases - 47 failed (625 assertions - 104 failed)
|
101 test cases - 47 failed (625 assertions - 104 failed)
|
||||||
|
|
||||||
|
|
||||||
CatchSelfTest is a CATCH v0.9 b22 (integration) host application.
|
CatchSelfTest is a CATCH v0.9 b23 (integration) host application.
|
||||||
Run with -? for options
|
Run with -? for options
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* CATCH v0.9 build 22 (integration branch)
|
* CATCH v0.9 build 23 (integration branch)
|
||||||
* Generated: 2013-03-08 09:29:15.097480
|
* Generated: 2013-03-11 18:35:52.716695
|
||||||
* ----------------------------------------------------------
|
* ----------------------------------------------------------
|
||||||
* This file has been merged from multiple headers. Please don't edit it directly
|
* This file has been merged from multiple headers. Please don't edit it directly
|
||||||
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||||
@ -2544,7 +2544,7 @@ inline bool isTrue( bool value ){ return value; }
|
|||||||
if( internal_catch_action & Catch::ResultAction::Debug ) BreakIntoDebugger(); \
|
if( internal_catch_action & Catch::ResultAction::Debug ) BreakIntoDebugger(); \
|
||||||
if( internal_catch_action & Catch::ResultAction::Abort ) throw Catch::TestFailureException(); \
|
if( internal_catch_action & Catch::ResultAction::Abort ) throw Catch::TestFailureException(); \
|
||||||
if( !Catch::shouldContinueOnFailure( resultDisposition ) ) throw Catch::TestFailureException(); \
|
if( !Catch::shouldContinueOnFailure( resultDisposition ) ) throw Catch::TestFailureException(); \
|
||||||
if( Catch::isTrue( false ) ){ bool this_is_here_to_invoke_warnings = ( originalExpr ); Catch::isTrue( this_is_here_to_invoke_warnings ); } \
|
Catch::isTrue( false && originalExpr ); \
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@ -5345,11 +5345,7 @@ namespace Catch {
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
struct ConsoleColourImpl;
|
struct IConsoleColourCodes : NonCopyable {
|
||||||
|
|
||||||
class TextColour : NonCopyable {
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum Colours {
|
enum Colours {
|
||||||
None,
|
None,
|
||||||
|
|
||||||
@ -5364,112 +5360,51 @@ namespace Catch {
|
|||||||
ReconstructedExpression
|
ReconstructedExpression
|
||||||
};
|
};
|
||||||
|
|
||||||
|
virtual void set( Colours colour ) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TextColour : public IConsoleColourCodes {
|
||||||
|
public:
|
||||||
TextColour( Colours colour = None );
|
TextColour( Colours colour = None );
|
||||||
void set( Colours colour );
|
void set( Colours colour );
|
||||||
~TextColour();
|
~TextColour();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConsoleColourImpl* m_impl;
|
IConsoleColourCodes* m_impl;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
#if !defined(CATCH_CONFIG_USE_ANSI_COLOUR_CODES) && !defined(CATCH_PLATFORM_WINDOWS)
|
#if defined ( CATCH_PLATFORM_WINDOWS ) /////////////////////////////////////////
|
||||||
#define CATCH_CONFIG_USE_ANSI_COLOUR_CODES 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined( CATCH_CONFIG_USE_ANSI_COLOUR_CODES )
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
// use POSIX/ ANSI console terminal codes
|
|
||||||
// Implementation contributed by Adam Strzelecki (http://github.com/nanoant)
|
|
||||||
// https://github.com/philsquared/Catch/pull/131
|
|
||||||
|
|
||||||
TextColour::TextColour( Colours colour ) {
|
|
||||||
if( colour )
|
|
||||||
set( colour );
|
|
||||||
}
|
|
||||||
|
|
||||||
TextColour::~TextColour() {
|
|
||||||
set( TextColour::None );
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace { const char colourEscape = '\033'; }
|
|
||||||
|
|
||||||
inline bool shouldUseColour() {
|
|
||||||
static bool s_shouldUseColour
|
|
||||||
= CATCH_CONFIG_USE_ANSI_COLOUR_CODES != 0 &&
|
|
||||||
isatty( fileno(stdout) ) &&
|
|
||||||
!isDebuggerActive();
|
|
||||||
return s_shouldUseColour;
|
|
||||||
}
|
|
||||||
void TextColour::set( Colours colour ) {
|
|
||||||
if( shouldUseColour() ) {
|
|
||||||
switch( colour ) {
|
|
||||||
case TextColour::FileName:
|
|
||||||
std::cout << colourEscape << "[0m"; // white/ normal
|
|
||||||
break;
|
|
||||||
case TextColour::ResultError:
|
|
||||||
std::cout << colourEscape << "[1;31m"; // bold red
|
|
||||||
break;
|
|
||||||
case TextColour::ResultSuccess:
|
|
||||||
std::cout << colourEscape << "[1;32m"; // bold green
|
|
||||||
break;
|
|
||||||
case TextColour::Error:
|
|
||||||
std::cout << colourEscape << "[0;31m"; // red
|
|
||||||
break;
|
|
||||||
case TextColour::Success:
|
|
||||||
std::cout << colourEscape << "[0;32m"; // green
|
|
||||||
break;
|
|
||||||
case TextColour::OriginalExpression:
|
|
||||||
std::cout << colourEscape << "[0;36m"; // cyan
|
|
||||||
break;
|
|
||||||
case TextColour::ReconstructedExpression:
|
|
||||||
std::cout << colourEscape << "[0;33m"; // yellow
|
|
||||||
break;
|
|
||||||
case TextColour::None:
|
|
||||||
std::cout << colourEscape << "[0m"; // reset
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Catch
|
|
||||||
|
|
||||||
#elif defined ( CATCH_PLATFORM_WINDOWS )
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
namespace Catch {
|
namespace {
|
||||||
|
using namespace Catch;
|
||||||
|
|
||||||
namespace {
|
WORD mapConsoleColour( IConsoleColourCodes::Colours colour ) {
|
||||||
|
switch( colour ) {
|
||||||
WORD mapConsoleColour( TextColour::Colours colour ) {
|
case IConsoleColourCodes::FileName:
|
||||||
switch( colour ) {
|
return FOREGROUND_INTENSITY; // greyed out
|
||||||
case TextColour::FileName:
|
case IConsoleColourCodes::ResultError:
|
||||||
return FOREGROUND_INTENSITY; // greyed out
|
return FOREGROUND_RED | FOREGROUND_INTENSITY; // bright red
|
||||||
case TextColour::ResultError:
|
case IConsoleColourCodes::ResultSuccess:
|
||||||
return FOREGROUND_RED | FOREGROUND_INTENSITY; // bright red
|
return FOREGROUND_GREEN | FOREGROUND_INTENSITY; // bright green
|
||||||
case TextColour::ResultSuccess:
|
case IConsoleColourCodes::Error:
|
||||||
return FOREGROUND_GREEN | FOREGROUND_INTENSITY; // bright green
|
return FOREGROUND_RED | FOREGROUND_INTENSITY; // bright red
|
||||||
case TextColour::Error:
|
case IConsoleColourCodes::Success:
|
||||||
return FOREGROUND_RED; // dark red
|
return FOREGROUND_GREEN; // dark green
|
||||||
case TextColour::Success:
|
case IConsoleColourCodes::OriginalExpression:
|
||||||
return FOREGROUND_GREEN; // dark green
|
return FOREGROUND_BLUE | FOREGROUND_GREEN; // turquoise
|
||||||
case TextColour::OriginalExpression:
|
case IConsoleColourCodes::ReconstructedExpression:
|
||||||
return FOREGROUND_BLUE | FOREGROUND_GREEN; // turquoise
|
return FOREGROUND_RED | FOREGROUND_GREEN; // greeny-yellow
|
||||||
case TextColour::ReconstructedExpression:
|
default: return 0;
|
||||||
return FOREGROUND_RED | FOREGROUND_GREEN; // greeny-yellow
|
|
||||||
default: return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ConsoleColourImpl {
|
struct WindowsConsoleColourCodes : IConsoleColourCodes {
|
||||||
|
|
||||||
ConsoleColourImpl()
|
WindowsConsoleColourCodes()
|
||||||
: hStdout( GetStdHandle(STD_OUTPUT_HANDLE) ),
|
: hStdout( GetStdHandle(STD_OUTPUT_HANDLE) ),
|
||||||
wOldColorAttrs( 0 )
|
wOldColorAttrs( 0 )
|
||||||
{
|
{
|
||||||
@ -5477,11 +5412,11 @@ namespace Catch {
|
|||||||
wOldColorAttrs = csbiInfo.wAttributes;
|
wOldColorAttrs = csbiInfo.wAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ConsoleColourImpl() {
|
~WindowsConsoleColourCodes() {
|
||||||
SetConsoleTextAttribute( hStdout, wOldColorAttrs );
|
SetConsoleTextAttribute( hStdout, wOldColorAttrs );
|
||||||
}
|
}
|
||||||
|
|
||||||
void set( TextColour::Colours colour ) {
|
void set( Colours colour ) {
|
||||||
WORD consoleColour = mapConsoleColour( colour );
|
WORD consoleColour = mapConsoleColour( colour );
|
||||||
if( consoleColour > 0 )
|
if( consoleColour > 0 )
|
||||||
SetConsoleTextAttribute( hStdout, consoleColour );
|
SetConsoleTextAttribute( hStdout, consoleColour );
|
||||||
@ -5492,11 +5427,89 @@ namespace Catch {
|
|||||||
WORD wOldColorAttrs;
|
WORD wOldColorAttrs;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextColour::TextColour( Colours colour )
|
inline bool shouldUseColourForPlatform() {
|
||||||
: m_impl( new ConsoleColourImpl() )
|
return true;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
typedef WindowsConsoleColourCodes PlatformConsoleColourCodes;
|
||||||
|
|
||||||
|
} // end anon namespace
|
||||||
|
|
||||||
|
#else // Not Windows - assumed to be POSIX compatible //////////////////////////
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
using namespace Catch;
|
||||||
|
|
||||||
|
// use POSIX/ ANSI console terminal codes
|
||||||
|
// Implementation contributed by Adam Strzelecki (http://github.com/nanoant)
|
||||||
|
// https://github.com/philsquared/Catch/pull/131
|
||||||
|
|
||||||
|
struct AnsiConsoleColourCodes : IConsoleColourCodes {
|
||||||
|
|
||||||
|
~AnsiConsoleColourCodes() {
|
||||||
|
set( None );
|
||||||
|
}
|
||||||
|
|
||||||
|
void set( Colours colour ) {
|
||||||
|
const char colourEscape = '\033';
|
||||||
|
switch( colour ) {
|
||||||
|
case FileName:
|
||||||
|
std::cout << colourEscape << "[0m"; // white/ normal
|
||||||
|
break;
|
||||||
|
case ResultError:
|
||||||
|
std::cout << colourEscape << "[0;31m"; // red
|
||||||
|
break;
|
||||||
|
case ResultSuccess:
|
||||||
|
std::cout << colourEscape << "[0;32m"; // green
|
||||||
|
break;
|
||||||
|
case Error:
|
||||||
|
std::cout << colourEscape << "[1;31m"; // bold red
|
||||||
|
break;
|
||||||
|
case Success:
|
||||||
|
std::cout << colourEscape << "[1;32m"; // bold green
|
||||||
|
break;
|
||||||
|
case OriginalExpression:
|
||||||
|
std::cout << colourEscape << "[0;36m"; // cyan
|
||||||
|
break;
|
||||||
|
case ReconstructedExpression:
|
||||||
|
std::cout << colourEscape << "[0;33m"; // yellow
|
||||||
|
break;
|
||||||
|
case None:
|
||||||
|
std::cout << colourEscape << "[0m"; // reset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool shouldUseColourForPlatform() {
|
||||||
|
return isatty( fileno(stdout) );
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef AnsiConsoleColourCodes PlatformConsoleColourCodes;
|
||||||
|
|
||||||
|
} // namespace Catch
|
||||||
|
|
||||||
|
#endif // not Windows
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
struct NoConsoleColourCodes : IConsoleColourCodes {
|
||||||
|
void set( Colours ) {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
TextColour::TextColour( Colours colour ) : m_impl( NULL ) {
|
||||||
|
static bool s_shouldUseColour = shouldUseColourForPlatform() &&
|
||||||
|
!isDebuggerActive();
|
||||||
|
if( s_shouldUseColour )
|
||||||
|
m_impl = new PlatformConsoleColourCodes();
|
||||||
|
else
|
||||||
|
m_impl = new NoConsoleColourCodes();
|
||||||
|
|
||||||
if( colour )
|
if( colour )
|
||||||
m_impl->set( colour );
|
set( colour );
|
||||||
}
|
}
|
||||||
|
|
||||||
TextColour::~TextColour() {
|
TextColour::~TextColour() {
|
||||||
@ -5509,18 +5522,6 @@ namespace Catch {
|
|||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
TextColour::TextColour( Colours ){}
|
|
||||||
TextColour::~TextColour(){}
|
|
||||||
void TextColour::set( Colours ){}
|
|
||||||
|
|
||||||
} // end namespace Catch
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// #included from: catch_generators_impl.hpp
|
// #included from: catch_generators_impl.hpp
|
||||||
#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
|
||||||
|
|
||||||
@ -5869,7 +5870,7 @@ namespace Catch {
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
// These numbers are maintained by a script
|
// These numbers are maintained by a script
|
||||||
Version libraryVersion( 0, 9, 22, "integration" );
|
Version libraryVersion( 0, 9, 23, "integration" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// #included from: catch_line_wrap.hpp
|
// #included from: catch_line_wrap.hpp
|
||||||
|
Loading…
Reference in New Issue
Block a user