Allow testing ordering to be specified as declaration, lexicographical, or random. Allow random seed to be specified

This commit is contained in:
Phil Nash
2014-09-15 18:39:31 +01:00
parent ea33961b43
commit fa0122bf54
7 changed files with 72 additions and 5 deletions

View File

@@ -59,7 +59,15 @@ namespace Catch {
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 {
struct RandomNumberGenerator {
int operator()( int n ) { return std::rand() % n; }
};
for( std::vector<TestCase>::const_iterator it = m_functionsInOrder.begin(),
itEnd = m_functionsInOrder.end();
it != itEnd;
@@ -67,6 +75,17 @@ namespace Catch {
if( testSpec.matches( *it ) && ( config.allowThrows() || !it->throws() ) )
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: