mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-14 17:35:39 +02:00
Allow testing ordering to be specified as declaration, lexicographical, or random. Allow random seed to be specified
This commit is contained in:
@@ -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:
|
||||
|
Reference in New Issue
Block a user