Compare commits

..

8 Commits

Author SHA1 Message Date
Phil Nash
584032dfa4 dev build 4
- undisturbed background colour (windows), from PR #456
2015-07-06 06:23:13 +01:00
Phil Nash
18acff62d3 Merge branch 'develop' of git://github.com/RandomInEqualities/Catch into RandomInEqualities-develop 2015-07-06 06:13:56 +01:00
Phil Nash
c1ca0fdabe dev build 3 2015-07-03 18:30:25 +01:00
Phil Nash
d6f1446e4e Fixed an issue on some compilers with implicit conversion from nullptr to Ptr
- also cleaned up some warnings to do with CATCH_NULL
2015-07-03 18:27:36 +01:00
Phil Nash
62e517f833 Fixed backslash detection in filenames-as-tags 2015-07-03 18:07:13 +01:00
csa
6160a2b079 Fix for white background in windows powershell when using colour output.
This commit fixes the white background that appears in windows powershell
when catch outputs messages with colour. The previous implementation
ignored the original background colour and defaulted to a white background.
2015-07-03 12:02:40 +02:00
Phil Nash
8f66e3495b dev build 2 2015-07-02 23:03:13 +01:00
Phil Nash
d87e551efa reseeds rng before each test case and provides access to seed through Catch::rngSeed() function 2015-07-02 23:02:35 +01:00
14 changed files with 69 additions and 23 deletions

View File

@@ -1,6 +1,6 @@
![catch logo](catch-logo-small.png) ![catch logo](catch-logo-small.png)
*v1.2.1-develop.1* *v1.2.1-develop.4*
Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch) Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch)

View File

@@ -112,7 +112,7 @@ namespace Catch {
std::set<std::string> tags = test.tags; std::set<std::string> tags = test.tags;
std::string filename = test.lineInfo.file; std::string filename = test.lineInfo.file;
std::string::size_type lastSlash = filename.find_last_of( "\//" ); std::string::size_type lastSlash = filename.find_last_of( "\\/" );
if( lastSlash != std::string::npos ) if( lastSlash != std::string::npos )
filename = filename.substr( lastSlash+1 ); filename = filename.substr( lastSlash+1 );
@@ -198,7 +198,7 @@ namespace Catch {
if( m_configData.filenamesAsTags ) if( m_configData.filenamesAsTags )
applyFilenamesAsTags(); applyFilenamesAsTags();
std::srand( m_configData.rngSeed ); seedRng( *m_config );
Runner runner( m_config ); Runner runner( m_config );

View File

@@ -22,6 +22,8 @@
#include "catch_compiler_capabilities.h" #include "catch_compiler_capabilities.h"
namespace Catch { namespace Catch {
struct IConfig;
class NonCopyable { class NonCopyable {
#ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS #ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
@@ -109,6 +111,9 @@ namespace Catch {
void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ); void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo );
void seedRng( IConfig const& config );
unsigned int rngSeed();
// Use this in variadic streaming macros to allow // Use this in variadic streaming macros to allow
// >> +StreamEndStop // >> +StreamEndStop
// as well as // as well as

View File

@@ -82,6 +82,14 @@ namespace Catch {
return line < other.line || ( line == other.line && file < other.file ); return line < other.line || ( line == other.line && file < other.file );
} }
void seedRng( IConfig const& config ) {
if( config.rngSeed() != 0 )
std::srand( config.rngSeed() );
}
unsigned int rngSeed() {
return getCurrentContext().getConfig()->rngSeed();
}
std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
#ifndef __GNUG__ #ifndef __GNUG__
os << info.file << "(" << info.line << ")"; os << info.file << "(" << info.line << ")";

View File

@@ -60,12 +60,13 @@ namespace {
{ {
CONSOLE_SCREEN_BUFFER_INFO csbiInfo; CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo ); GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo );
originalAttributes = csbiInfo.wAttributes; originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY );
originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
} }
virtual void use( Colour::Code _colourCode ) { virtual void use( Colour::Code _colourCode ) {
switch( _colourCode ) { switch( _colourCode ) {
case Colour::None: return setTextAttribute( originalAttributes ); case Colour::None: return setTextAttribute( originalForegroundAttributes );
case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
case Colour::Red: return setTextAttribute( FOREGROUND_RED ); case Colour::Red: return setTextAttribute( FOREGROUND_RED );
case Colour::Green: return setTextAttribute( FOREGROUND_GREEN ); case Colour::Green: return setTextAttribute( FOREGROUND_GREEN );
@@ -85,10 +86,11 @@ namespace {
private: private:
void setTextAttribute( WORD _textAttribute ) { void setTextAttribute( WORD _textAttribute ) {
SetConsoleTextAttribute( stdoutHandle, _textAttribute ); SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes );
} }
HANDLE stdoutHandle; HANDLE stdoutHandle;
WORD originalAttributes; WORD originalForegroundAttributes;
WORD originalBackgroundAttributes;
}; };
IColourImpl* platformColourInstance() { IColourImpl* platformColourInstance() {

View File

@@ -78,7 +78,7 @@ namespace Catch {
virtual ~RunContext() { virtual ~RunContext() {
m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) ); m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) );
m_context.setRunner( m_prevRunner ); m_context.setRunner( m_prevRunner );
m_context.setConfig( CATCH_NULL ); m_context.setConfig( Ptr<IConfig const>() );
m_context.setResultCapture( m_prevResultCapture ); m_context.setResultCapture( m_prevResultCapture );
m_context.setConfig( m_prevConfig ); m_context.setConfig( m_prevConfig );
} }
@@ -259,6 +259,8 @@ namespace Catch {
m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal ); m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
TestCaseTracker::Guard guard( *m_testCaseTracker ); TestCaseTracker::Guard guard( *m_testCaseTracker );
seedRng( *m_config );
Timer timer; Timer timer;
timer.start(); timer.start();
if( m_reporter->getPreferences().shouldRedirectStdOut ) { if( m_reporter->getPreferences().shouldRedirectStdOut ) {

View File

@@ -90,6 +90,8 @@ namespace Catch {
break; break;
case RunTests::InRandomOrder: case RunTests::InRandomOrder:
{ {
seedRng( config );
RandomNumberGenerator rng; RandomNumberGenerator rng;
std::random_shuffle( matchingTestCases.begin(), matchingTestCases.end(), rng ); std::random_shuffle( matchingTestCases.begin(), matchingTestCases.end(), rng );
} }

View File

@@ -37,7 +37,7 @@ namespace Catch {
return os; return os;
} }
Version libraryVersion( 1, 2, 1, "develop", 1 ); Version libraryVersion( 1, 2, 1, "develop", 4 );
} }

View File

@@ -9,6 +9,9 @@
#include "catch.hpp" #include "catch.hpp"
#include "catch_test_spec_parser.hpp" #include "catch_test_spec_parser.hpp"
#ifdef __clang__
# pragma clang diagnostic ignored "-Wc++98-compat"
#endif
inline Catch::TestCase fakeTestCase( const char* name, const char* desc = "" ){ return Catch::makeTestCase( CATCH_NULL, "", name, desc, CATCH_INTERNAL_LINEINFO ); } inline Catch::TestCase fakeTestCase( const char* name, const char* desc = "" ){ return Catch::makeTestCase( CATCH_NULL, "", name, desc, CATCH_INTERNAL_LINEINFO ); }

View File

@@ -6,7 +6,8 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/ */
#ifdef __clang__ #ifdef __clang__
#pragma clang diagnostic ignored "-Wpadded" # pragma clang diagnostic ignored "-Wpadded"
# pragma clang diagnostic ignored "-Wc++98-compat"
#endif #endif
#include "catch.hpp" #include "catch.hpp"

View File

@@ -7,7 +7,8 @@
*/ */
#ifdef __clang__ #ifdef __clang__
#pragma clang diagnostic ignored "-Wpadded" # pragma clang diagnostic ignored "-Wpadded"
# pragma clang diagnostic ignored "-Wc++98-compat"
#endif #endif
#include "internal/catch_test_case_tracker.hpp" #include "internal/catch_test_case_tracker.hpp"

View File

@@ -1,2 +1,4 @@
// This file is only here to verify (to the extent possible) the self sufficiency of the header // This file is only here to verify (to the extent possible) the self sufficiency of the header
#include "catch_suppress_warnings.h"
#include "catch_xmlwriter.hpp" #include "catch_xmlwriter.hpp"
#include "catch_reenable_warnings.h"

View File

@@ -16,8 +16,9 @@ CATCH_REGISTER_TAG_ALIAS( "[@tricky]", "[tricky]~[.]" )
#ifdef __clang__ #ifdef __clang__
#pragma clang diagnostic ignored "-Wpadded" # pragma clang diagnostic ignored "-Wpadded"
#pragma clang diagnostic ignored "-Wweak-vtables" # pragma clang diagnostic ignored "-Wweak-vtables"
# pragma clang diagnostic ignored "-Wc++98-compat"
#endif #endif

View File

@@ -1,6 +1,6 @@
/* /*
* Catch v1.2.1-develop.1 * Catch v1.2.1-develop.4
* Generated: 2015-07-02 08:21:11.983471 * Generated: 2015-07-06 06:21:18.816844
* ---------------------------------------------------------- * ----------------------------------------------------------
* 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.
@@ -233,6 +233,8 @@
namespace Catch { namespace Catch {
struct IConfig;
class NonCopyable { class NonCopyable {
#ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS #ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
NonCopyable( NonCopyable const& ) = delete; NonCopyable( NonCopyable const& ) = delete;
@@ -319,6 +321,9 @@ namespace Catch {
void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ); void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo );
void seedRng( IConfig const& config );
unsigned int rngSeed();
// Use this in variadic streaming macros to allow // Use this in variadic streaming macros to allow
// >> +StreamEndStop // >> +StreamEndStop
// as well as // as well as
@@ -5208,7 +5213,7 @@ namespace Catch {
virtual ~RunContext() { virtual ~RunContext() {
m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) ); m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) );
m_context.setRunner( m_prevRunner ); m_context.setRunner( m_prevRunner );
m_context.setConfig( CATCH_NULL ); m_context.setConfig( Ptr<IConfig const>() );
m_context.setResultCapture( m_prevResultCapture ); m_context.setResultCapture( m_prevResultCapture );
m_context.setConfig( m_prevConfig ); m_context.setConfig( m_prevConfig );
} }
@@ -5388,6 +5393,8 @@ namespace Catch {
m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal ); m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
TestCaseTracker::Guard guard( *m_testCaseTracker ); TestCaseTracker::Guard guard( *m_testCaseTracker );
seedRng( *m_config );
Timer timer; Timer timer;
timer.start(); timer.start();
if( m_reporter->getPreferences().shouldRedirectStdOut ) { if( m_reporter->getPreferences().shouldRedirectStdOut ) {
@@ -5611,7 +5618,7 @@ namespace Catch {
std::set<std::string> tags = test.tags; std::set<std::string> tags = test.tags;
std::string filename = test.lineInfo.file; std::string filename = test.lineInfo.file;
std::string::size_type lastSlash = filename.find_last_of( "\//" ); std::string::size_type lastSlash = filename.find_last_of( "\\/" );
if( lastSlash != std::string::npos ) if( lastSlash != std::string::npos )
filename = filename.substr( lastSlash+1 ); filename = filename.substr( lastSlash+1 );
@@ -5697,7 +5704,7 @@ namespace Catch {
if( m_configData.filenamesAsTags ) if( m_configData.filenamesAsTags )
applyFilenamesAsTags(); applyFilenamesAsTags();
std::srand( m_configData.rngSeed ); seedRng( *m_config );
Runner runner( m_config ); Runner runner( m_config );
@@ -5822,6 +5829,8 @@ namespace Catch {
break; break;
case RunTests::InRandomOrder: case RunTests::InRandomOrder:
{ {
seedRng( config );
RandomNumberGenerator rng; RandomNumberGenerator rng;
std::random_shuffle( matchingTestCases.begin(), matchingTestCases.end(), rng ); std::random_shuffle( matchingTestCases.begin(), matchingTestCases.end(), rng );
} }
@@ -6324,12 +6333,13 @@ namespace {
{ {
CONSOLE_SCREEN_BUFFER_INFO csbiInfo; CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo ); GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo );
originalAttributes = csbiInfo.wAttributes; originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY );
originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
} }
virtual void use( Colour::Code _colourCode ) { virtual void use( Colour::Code _colourCode ) {
switch( _colourCode ) { switch( _colourCode ) {
case Colour::None: return setTextAttribute( originalAttributes ); case Colour::None: return setTextAttribute( originalForegroundAttributes );
case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
case Colour::Red: return setTextAttribute( FOREGROUND_RED ); case Colour::Red: return setTextAttribute( FOREGROUND_RED );
case Colour::Green: return setTextAttribute( FOREGROUND_GREEN ); case Colour::Green: return setTextAttribute( FOREGROUND_GREEN );
@@ -6349,10 +6359,11 @@ namespace {
private: private:
void setTextAttribute( WORD _textAttribute ) { void setTextAttribute( WORD _textAttribute ) {
SetConsoleTextAttribute( stdoutHandle, _textAttribute ); SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes );
} }
HANDLE stdoutHandle; HANDLE stdoutHandle;
WORD originalAttributes; WORD originalForegroundAttributes;
WORD originalBackgroundAttributes;
}; };
IColourImpl* platformColourInstance() { IColourImpl* platformColourInstance() {
@@ -6812,7 +6823,7 @@ namespace Catch {
return os; return os;
} }
Version libraryVersion( 1, 2, 1, "develop", 1 ); Version libraryVersion( 1, 2, 1, "develop", 4 );
} }
@@ -7104,6 +7115,14 @@ namespace Catch {
return line < other.line || ( line == other.line && file < other.file ); return line < other.line || ( line == other.line && file < other.file );
} }
void seedRng( IConfig const& config ) {
if( config.rngSeed() != 0 )
std::srand( config.rngSeed() );
}
unsigned int rngSeed() {
return getCurrentContext().getConfig()->rngSeed();
}
std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
#ifndef __GNUG__ #ifndef __GNUG__
os << info.file << "(" << info.line << ")"; os << info.file << "(" << info.line << ")";