This commit is contained in:
Phil Nash 2014-09-15 18:40:24 +01:00
parent fa0122bf54
commit 6a8e8ada0d
3 changed files with 96 additions and 19 deletions

View File

@ -1,6 +1,6 @@
![catch logo](catch-logo-small.png) ![catch logo](catch-logo-small.png)
*v1.1 build 3 (develop branch)* *v1.1 build 4 (develop branch)*
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

@ -13,7 +13,7 @@
namespace Catch { namespace Catch {
// These numbers are maintained by a script // These numbers are maintained by a script
Version libraryVersion( 1, 1, 3, "develop" ); Version libraryVersion( 1, 1, 4, "develop" );
} }
#endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED #endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED

View File

@ -1,6 +1,6 @@
/* /*
* CATCH v1.1 build 3 (develop branch) * CATCH v1.1 build 4 (develop branch)
* Generated: 2014-09-03 19:22:56.858064 * Generated: 2014-09-15 18:39:57.728720
* ---------------------------------------------------------- * ----------------------------------------------------------
* 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.
@ -1048,6 +1048,8 @@ std::string toString( T const& value );
namespace Detail { namespace Detail {
extern std::string unprintableString;
// SFINAE is currently disabled by default for all compilers. // SFINAE is currently disabled by default for all compilers.
// If the non SFINAE version of IsStreamInsertable is ambiguous for you // If the non SFINAE version of IsStreamInsertable is ambiguous for you
// and your compiler supports SFINAE, try #defining CATCH_CONFIG_SFINAE // and your compiler supports SFINAE, try #defining CATCH_CONFIG_SFINAE
@ -1090,11 +1092,11 @@ namespace Detail {
#if defined(CATCH_CPP11_OR_GREATER) #if defined(CATCH_CPP11_OR_GREATER)
template<typename T, template<typename T,
bool IsEmum = std::is_enum<T>::value bool IsEnum = std::is_enum<T>::value
> >
struct EnumStringMaker struct EnumStringMaker
{ {
static std::string convert( T const& ) { return "{?}"; } static std::string convert( T const& ) { return unprintableString; }
}; };
template<typename T> template<typename T>
@ -1118,7 +1120,7 @@ namespace Detail {
} }
#else #else
template<typename T> template<typename T>
static std::string convert( T const& ) { return "{?}"; } static std::string convert( T const& ) { return unprintableString; }
#endif #endif
}; };
@ -1171,12 +1173,17 @@ namespace Detail {
std::string rangeToString( InputIterator first, InputIterator last ); std::string rangeToString( InputIterator first, InputIterator last );
} }
//template<typename T, typename Allocator>
//struct StringMaker<std::vector<T, Allocator> > {
// static std::string convert( std::vector<T,Allocator> const& v ) {
// return Detail::rangeToString( v.begin(), v.end() );
// }
//};
template<typename T, typename Allocator> template<typename T, typename Allocator>
struct StringMaker<std::vector<T, Allocator> > { std::string toString( std::vector<T,Allocator> const& v ) {
static std::string convert( std::vector<T,Allocator> const& v ) {
return Detail::rangeToString( v.begin(), v.end() ); return Detail::rangeToString( v.begin(), v.end() );
} }
};
namespace Detail { namespace Detail {
template<typename T> template<typename T>
@ -1613,7 +1620,7 @@ namespace Catch {
std::string matcherAsString = ::Catch::Matchers::matcher.toString(); \ std::string matcherAsString = ::Catch::Matchers::matcher.toString(); \
__catchResult \ __catchResult \
.setLhs( Catch::toString( arg ) ) \ .setLhs( Catch::toString( arg ) ) \
.setRhs( matcherAsString == "{?}" ? #matcher : matcherAsString ) \ .setRhs( matcherAsString == Catch::Detail::unprintableString ? #matcher : matcherAsString ) \
.setOp( "matches" ) \ .setOp( "matches" ) \
.setResultType( ::Catch::Matchers::matcher.match( arg ) ); \ .setResultType( ::Catch::Matchers::matcher.match( arg ) ); \
__catchResult.captureExpression(); \ __catchResult.captureExpression(); \
@ -3000,6 +3007,11 @@ namespace Catch {
Always, Always,
Never Never
}; }; }; };
struct RunTests { enum InWhatOrder {
InDeclarationOrder,
InLexicographicalOrder,
InRandomOrder
}; };
class TestSpec; class TestSpec;
@ -3017,6 +3029,8 @@ namespace Catch {
virtual bool showInvisibles() const = 0; virtual bool showInvisibles() const = 0;
virtual ShowDurations::OrNot showDurations() const = 0; virtual ShowDurations::OrNot showDurations() const = 0;
virtual TestSpec const& testSpec() const = 0; virtual TestSpec const& testSpec() const = 0;
virtual RunTests::InWhatOrder runOrder() const = 0;
virtual unsigned int rngSeed() const = 0;
}; };
} }
@ -3048,6 +3062,7 @@ namespace Catch {
#include <vector> #include <vector>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <ctime>
#ifndef CATCH_CONFIG_CONSOLE_WIDTH #ifndef CATCH_CONFIG_CONSOLE_WIDTH
#define CATCH_CONFIG_CONSOLE_WIDTH 80 #define CATCH_CONFIG_CONSOLE_WIDTH 80
@ -3068,9 +3083,11 @@ namespace Catch {
showHelp( false ), showHelp( false ),
showInvisibles( false ), showInvisibles( false ),
abortAfter( -1 ), abortAfter( -1 ),
rngSeed( 0 ),
verbosity( Verbosity::Normal ), verbosity( Verbosity::Normal ),
warnings( WarnAbout::Nothing ), warnings( WarnAbout::Nothing ),
showDurations( ShowDurations::DefaultForReporter ) showDurations( ShowDurations::DefaultForReporter ),
runOrder( RunTests::InDeclarationOrder )
{} {}
bool listTests; bool listTests;
@ -3085,10 +3102,12 @@ namespace Catch {
bool showInvisibles; bool showInvisibles;
int abortAfter; int abortAfter;
unsigned int rngSeed;
Verbosity::Level verbosity; Verbosity::Level verbosity;
WarnAbout::What warnings; WarnAbout::What warnings;
ShowDurations::OrNot showDurations; ShowDurations::OrNot showDurations;
RunTests::InWhatOrder runOrder;
std::string reporterName; std::string reporterName;
std::string outputFilename; std::string outputFilename;
@ -3170,6 +3189,8 @@ namespace Catch {
virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; } virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
virtual bool warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; } virtual bool warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; }
virtual ShowDurations::OrNot showDurations() const { return m_data.showDurations; } virtual ShowDurations::OrNot showDurations() const { return m_data.showDurations; }
virtual RunTests::InWhatOrder runOrder() const { return m_data.runOrder; }
virtual unsigned int rngSeed() const { return m_data.rngSeed; }
private: private:
ConfigData m_data; ConfigData m_data;
@ -3968,7 +3989,7 @@ namespace Clara {
if( it == itEnd ) { if( it == itEnd ) {
if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens ) if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens )
unusedTokens.push_back( token ); unusedTokens.push_back( token );
else if( m_throwOnUnrecognisedTokens ) else if( errors.empty() && m_throwOnUnrecognisedTokens )
errors.push_back( "unrecognised option: " + token.data ); errors.push_back( "unrecognised option: " + token.data );
} }
} }
@ -4066,7 +4087,28 @@ namespace Catch {
config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions ); config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions );
else else
throw std::runtime_error( "Unrecognised warning: '" + _warning + "'" ); throw std::runtime_error( "Unrecognised warning: '" + _warning + "'" );
}
inline void setOrder( ConfigData& config, std::string const& order ) {
if( startsWith( "declared", order ) )
config.runOrder = RunTests::InDeclarationOrder;
else if( startsWith( "lexical", order ) )
config.runOrder = RunTests::InLexicographicalOrder;
else if( startsWith( "random", order ) )
config.runOrder = RunTests::InRandomOrder;
else
throw std::runtime_error( "Unrecognised ordering: '" + order + "'" );
}
inline void setRngSeed( ConfigData& config, std::string const& seed ) {
if( seed == "time" ) {
config.rngSeed = static_cast<unsigned int>( std::time(0) );
}
else {
std::stringstream ss;
ss << seed;
ss >> config.rngSeed;
if( ss.fail() )
throw std::runtime_error( "Argment to --rng-seed should be the word 'time' or a number" );
}
} }
inline void setVerbosity( ConfigData& config, int level ) { inline void setVerbosity( ConfigData& config, int level ) {
// !TBD: accept strings? // !TBD: accept strings?
@ -4178,6 +4220,14 @@ namespace Catch {
.describe( "list all reporters" ) .describe( "list all reporters" )
.bind( &ConfigData::listReporters ); .bind( &ConfigData::listReporters );
cli["--order"]
.describe( "test case order (defaults to decl)" )
.bind( &setOrder, "decl|lex|rand" );
cli["--rng-seed"]
.describe( "set a specific seed for random numbers" )
.bind( &setRngSeed, "'time'|number" );
return cli; return cli;
} }
@ -5400,7 +5450,7 @@ namespace Catch {
Totals totals; Totals totals;
context.testGroupStarting( "", 1, 1 ); // deprecated? context.testGroupStarting( "all tests", 1, 1 ); // deprecated?
TestSpec testSpec = m_config->testSpec(); TestSpec testSpec = m_config->testSpec();
if( !testSpec.hasFilters() ) if( !testSpec.hasFilters() )
@ -5423,7 +5473,7 @@ namespace Catch {
m_testsAlreadyRun.insert( *it ); m_testsAlreadyRun.insert( *it );
} }
} }
context.testGroupEnded( "", totals, 1, 1 ); context.testGroupEnded( "all tests", totals, 1, 1 );
return totals; return totals;
} }
@ -5533,6 +5583,9 @@ namespace Catch {
try try
{ {
config(); // Force config to be constructed config(); // Force config to be constructed
std::srand( m_configData.rngSeed );
Runner runner( m_config ); Runner runner( m_config );
// Handle list request // Handle list request
@ -5625,7 +5678,15 @@ namespace Catch {
return m_nonHiddenFunctions; return m_nonHiddenFunctions;
} }
struct LexSort {
bool operator() (TestCase i,TestCase j) { return (i<j);}
};
virtual void getFilteredTests( TestSpec const& testSpec, IConfig const& config, std::vector<TestCase>& matchingTestCases ) const { virtual void getFilteredTests( TestSpec const& testSpec, IConfig const& config, std::vector<TestCase>& matchingTestCases ) const {
struct RandomNumberGenerator {
int operator()( int n ) { return std::rand() % n; }
};
for( std::vector<TestCase>::const_iterator it = m_functionsInOrder.begin(), for( std::vector<TestCase>::const_iterator it = m_functionsInOrder.begin(),
itEnd = m_functionsInOrder.end(); itEnd = m_functionsInOrder.end();
it != itEnd; it != itEnd;
@ -5633,6 +5694,17 @@ namespace Catch {
if( testSpec.matches( *it ) && ( config.allowThrows() || !it->throws() ) ) if( testSpec.matches( *it ) && ( config.allowThrows() || !it->throws() ) )
matchingTestCases.push_back( *it ); matchingTestCases.push_back( *it );
} }
switch( config.runOrder() ) {
case RunTests::InLexicographicalOrder:
std::sort( matchingTestCases.begin(), matchingTestCases.end(), LexSort() );
break;
case RunTests::InRandomOrder:
std::random_shuffle( matchingTestCases.begin(), matchingTestCases.end(), RandomNumberGenerator() );
break;
case RunTests::InDeclarationOrder:
// already in declaration order
break;
}
} }
private: private:
@ -6564,7 +6636,7 @@ namespace Catch {
namespace Catch { namespace Catch {
// These numbers are maintained by a script // These numbers are maintained by a script
Version libraryVersion( 1, 1, 3, "develop" ); Version libraryVersion( 1, 1, 4, "develop" );
} }
// #included from: catch_message.hpp // #included from: catch_message.hpp
@ -6981,6 +7053,8 @@ namespace Catch {
namespace Detail { namespace Detail {
std::string unprintableString = "{?}";
namespace { namespace {
struct Endianness { struct Endianness {
enum Arch { Big, Little }; enum Arch { Big, Little };
@ -8441,6 +8515,9 @@ namespace Catch {
stream << " host application.\n" stream << " host application.\n"
<< "Run with -? for options\n\n"; << "Run with -? for options\n\n";
if( m_config->rngSeed() != 0 )
stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n";
currentTestRunInfo.used = true; currentTestRunInfo.used = true;
} }
void lazyPrintGroupInfo() { void lazyPrintGroupInfo() {