mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 21:05:39 +02:00
Add abiiity to stop after n tests. Add ordered list of tests to check sw4
This commit is contained in:
@@ -45,8 +45,10 @@ namespace CatchOverrides {
|
||||
template <typename T>
|
||||
class Config
|
||||
{
|
||||
typedef std::map<int, bool> LineData;
|
||||
typedef std::map<int, int> LineData;
|
||||
typedef std::map<std::string, LineData> FileLineData;
|
||||
typedef std::map<int, std::string> StringLineData;
|
||||
typedef std::map<std::string, StringLineData> FileStringLineData;
|
||||
public:
|
||||
bool includeSuccessfulResults(const std::string& file, int c) const
|
||||
{
|
||||
@@ -58,7 +60,7 @@ namespace CatchOverrides {
|
||||
{
|
||||
if( c <= lineIt->first )
|
||||
break;
|
||||
result = lineIt->second;
|
||||
result = lineIt->second ? true : false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -69,12 +71,12 @@ namespace CatchOverrides {
|
||||
if( it == showSuccessfulTestsData.end() )
|
||||
{
|
||||
LineData tmp;
|
||||
tmp.insert(std::make_pair(c,v));
|
||||
tmp.insert(std::make_pair(c,(v ? 1 : 0)));
|
||||
showSuccessfulTestsData.insert(std::make_pair(file, tmp));
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second.insert(std::make_pair(c,v));
|
||||
it->second.insert(std::make_pair(c,(v ? 1 : 0)));
|
||||
}
|
||||
}
|
||||
bool warnAboutMissingAssertions(const std::string& file, int c) const
|
||||
@@ -87,7 +89,7 @@ namespace CatchOverrides {
|
||||
{
|
||||
if( c <= lineIt->first )
|
||||
break;
|
||||
result = lineIt->second;
|
||||
result = lineIt->second ? true : false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -98,10 +100,72 @@ namespace CatchOverrides {
|
||||
if( it == missingAssertionData.end() )
|
||||
{
|
||||
LineData tmp;
|
||||
tmp.insert(std::make_pair(c,v));
|
||||
tmp.insert(std::make_pair(c,(v ? 1 : 0)));
|
||||
missingAssertionData.insert(std::make_pair(file, tmp));
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second.insert(std::make_pair(c,(v ? 1 : 0)));
|
||||
}
|
||||
}
|
||||
int abortAfter(const std::string& file, int c) const
|
||||
{
|
||||
int result(-1);
|
||||
FileLineData::const_iterator it = abortAfterData.find(file);
|
||||
if( it != abortAfterData.end() )
|
||||
{
|
||||
for( LineData::const_iterator lineIt = it->second.begin(); lineIt != it->second.end(); ++lineIt )
|
||||
{
|
||||
if( c <= lineIt->first )
|
||||
break;
|
||||
result = lineIt->second;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
void insertAbortAfter(const std::string& file, int c, int v)
|
||||
{
|
||||
FileLineData::iterator it = abortAfterData.find(file);
|
||||
if( it == abortAfterData.end() )
|
||||
{
|
||||
LineData tmp;
|
||||
tmp.insert(std::make_pair(c,v));
|
||||
abortAfterData.insert(std::make_pair(file, tmp));
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second.insert(std::make_pair(c,v));
|
||||
}
|
||||
}
|
||||
std::vector<std::string> listOfTests(const std::string& file, int c) const
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
FileStringLineData::const_iterator it = testData.find(file);
|
||||
if( it != testData.end() )
|
||||
{
|
||||
for( StringLineData::const_iterator lineIt = it->second.begin(); lineIt != it->second.end(); ++lineIt )
|
||||
{
|
||||
if( lineIt->second.empty() && c > lineIt->first)
|
||||
result.clear();
|
||||
else {
|
||||
if( c <= lineIt->first )
|
||||
break;
|
||||
result.push_back(lineIt->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
void insertTest(const std::string& file, int c, const std::string& v)
|
||||
{
|
||||
FileStringLineData::iterator it = testData.find(file);
|
||||
if( it == testData.end() )
|
||||
{
|
||||
StringLineData tmp;
|
||||
tmp.insert(std::make_pair(c,v));
|
||||
testData.insert(std::make_pair(file, tmp));
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second.insert(std::make_pair(c,v));
|
||||
}
|
||||
@@ -117,6 +181,8 @@ namespace CatchOverrides {
|
||||
private:
|
||||
FileLineData showSuccessfulTestsData;
|
||||
FileLineData missingAssertionData;
|
||||
FileLineData abortAfterData;
|
||||
FileStringLineData testData;
|
||||
|
||||
static Config<T>* s_instance;
|
||||
};
|
||||
@@ -130,6 +196,8 @@ namespace CatchOverrides {
|
||||
{
|
||||
Config<T>::instance().insertSuccessfulResults(file, c, false);
|
||||
Config<T>::instance().insertMissingAssertions(file, c, false);
|
||||
Config<T>::instance().insertAbortAfter(file, c, -1);
|
||||
Config<T>::instance().insertTest(file, c, "");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -152,6 +220,26 @@ namespace CatchOverrides {
|
||||
Config<T>::instance().insertMissingAssertions(file, c, v ? true : false);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct ConfigAbortAfter
|
||||
{
|
||||
template <typename U>
|
||||
ConfigAbortAfter( const std::string& file, int c, U v )
|
||||
{
|
||||
Config<T>::instance().insertAbortAfter(file, c, v);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct ConfigAddTest
|
||||
{
|
||||
template <typename U>
|
||||
ConfigAddTest( const std::string& file, int c, U v )
|
||||
{
|
||||
Config<T>::instance().insertTest(file, c, v);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace Catch {
|
||||
|
@@ -192,6 +192,9 @@ private:
|
||||
#define INTERNAL_CATCH_MAP_CATEGORY_TO_TAG( Category, Tag ) \
|
||||
INTERNAL_CATCH_MAP_CATEGORY_TO_TAG2( #Category, Tag, __COUNTER__ )
|
||||
|
||||
#define INTERNAL_CATCH_MAP_CATEGORY_TO_LIST( Category ) \
|
||||
INTERNAL_CATCH_MAP_CATEGORY_TO_LIST2( #Category, __COUNTER__ )
|
||||
|
||||
#define FAIL_STRING( str ) _T( str )
|
||||
|
||||
#else // detect CLR
|
||||
@@ -238,6 +241,9 @@ private:
|
||||
#define INTERNAL_CATCH_MAP_CATEGORY_TO_TAG( Category, Tag ) \
|
||||
INTERNAL_CATCH_MAP_CATEGORY_TO_TAG2( Category, Tag, __COUNTER__ )
|
||||
|
||||
#define INTERNAL_CATCH_MAP_CATEGORY_TO_LIST( Category, List ) \
|
||||
INTERNAL_CATCH_MAP_CATEGORY_TO_LIST2( Category, List, __COUNTER__ )
|
||||
|
||||
#define FAIL_STRING( str ) WIDEN( str )
|
||||
|
||||
#endif // detect CLR
|
||||
@@ -250,12 +256,24 @@ private:
|
||||
#define CATCH_INTERNAL_CONFIG_WARN_MISSING_ASSERTIONS2( v, Count ) \
|
||||
namespace { CatchOverrides::ConfigWarnMissingAssertions<Catch::IConfig const*> INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H_____O_V_E_R_R_I_D_E____, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count, v); }
|
||||
|
||||
#define CATCH_INTERNAL_CONFIG_ABORT_AFTER2( v, Count ) \
|
||||
namespace { CatchOverrides::ConfigAbortAfter<Catch::IConfig const*> INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H_____O_V_E_R_R_I_D_E____, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count, v); }
|
||||
|
||||
#define CATCH_INTERNAL_CONFIG_ADD_TEST2( v, Count ) \
|
||||
namespace { CatchOverrides::ConfigAddTest<Catch::IConfig const*> INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H_____O_V_E_R_R_I_D_E____, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count, v); }
|
||||
|
||||
#define CATCH_INTERNAL_CONFIG_SHOW_SUCCESS( v ) \
|
||||
CATCH_INTERNAL_CONFIG_SHOW_SUCCESS2( v, __COUNTER__)
|
||||
|
||||
#define CATCH_INTERNAL_CONFIG_WARN_MISSING_ASSERTIONS( v ) \
|
||||
CATCH_INTERNAL_CONFIG_WARN_MISSING_ASSERTIONS2( v, __COUNTER__)
|
||||
|
||||
#define CATCH_INTERNAL_CONFIG_ABORT_AFTER( v ) \
|
||||
CATCH_INTERNAL_CONFIG_ABORT_AFTER2( v, __COUNTER__)
|
||||
|
||||
#define CATCH_INTERNAL_CONFIG_ADD_TEST( v ) \
|
||||
CATCH_INTERNAL_CONFIG_ADD_TEST2( v, __COUNTER__)
|
||||
|
||||
#define CATCH_INTERNAL_RUN_SINGLE_TEST( Count ) \
|
||||
{ CatchOverrides::ConfigGuard cg; \
|
||||
Catch::ConfigData cd(cg.value().get()); \
|
||||
@@ -263,6 +281,7 @@ private:
|
||||
cd.abortAfter = 1; \
|
||||
cd.showSuccessfulTests = CatchOverrides::Config<Catch::IConfig const*>::instance().includeSuccessfulResults(__FILE__, Count ); \
|
||||
cd.warnings = (CatchOverrides::Config<Catch::IConfig const*>::instance().warnAboutMissingAssertions(__FILE__, Count ) ? Catch::WarnAbout::NoAssertions : Catch::WarnAbout::Nothing); \
|
||||
cd.abortAfter = CatchOverrides::Config<Catch::IConfig const*>::instance().abortAfter(__FILE__, Count ); \
|
||||
Catch::Ptr<Catch::Config> config(new Catch::Config(cd)); \
|
||||
Catch::MSTestReporter* rep = new Catch::MSTestReporter(config.get()); \
|
||||
Catch::RunContext tr(config.get(), rep); \
|
||||
@@ -351,6 +370,7 @@ private:
|
||||
Catch::ConfigData cd; \
|
||||
cd.showSuccessfulTests = CatchOverrides::Config<Catch::IConfig const*>::instance().includeSuccessfulResults(__FILE__, Count ); \
|
||||
cd.warnings = (CatchOverrides::Config<Catch::IConfig const*>::instance().warnAboutMissingAssertions(__FILE__, Count ) ? Catch::WarnAbout::NoAssertions : Catch::WarnAbout::Nothing); \
|
||||
cd.abortAfter = CatchOverrides::Config<Catch::IConfig const*>::instance().abortAfter(__FILE__, Count ); \
|
||||
cd.reporterName = "vs_reporter"; \
|
||||
cd.name = "Batch run using tag : " Tag; \
|
||||
cd.testsOrTags.push_back( Tag ); \
|
||||
@@ -365,6 +385,35 @@ private:
|
||||
}; \
|
||||
}
|
||||
|
||||
#define INTERNAL_CATCH_MAP_CATEGORY_TO_LIST2( Category, Count ) \
|
||||
CHECK_FOR_TEST_CASE_CLASH \
|
||||
namespace CATCH_INTERNAL_NAMESPACE( INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ) { \
|
||||
CatchOverrides::ConfigReset<Catch::IConfig const*> INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_O_N_F_I_G___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) )(__FILE__, Count); \
|
||||
INTERNAL_CATCH_CLASS_DEFINITION( INTERNAL_CATCH_UNIQUE_NAME_LINE( C_A_T_C_H____T_E_S_T____C_L_A_S_S___, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ) ) \
|
||||
{ \
|
||||
INTERNAL_CATCH_CLASS_CONTEXT \
|
||||
BEGIN_INTERNAL_CATCH_BATCH_METHOD( Category, INTERNAL_CATCH_CONCAT_LINE_COUNTER( Count ) ) \
|
||||
{ \
|
||||
Catch::ConfigData cd; \
|
||||
cd.showSuccessfulTests = CatchOverrides::Config<Catch::IConfig const*>::instance().includeSuccessfulResults(__FILE__, Count ); \
|
||||
cd.warnings = (CatchOverrides::Config<Catch::IConfig const*>::instance().warnAboutMissingAssertions(__FILE__, Count ) ? Catch::WarnAbout::NoAssertions : Catch::WarnAbout::Nothing); \
|
||||
cd.abortAfter = CatchOverrides::Config<Catch::IConfig const*>::instance().abortAfter(__FILE__, Count ); \
|
||||
cd.reporterName = "vs_reporter"; \
|
||||
cd.name = "Batch run using category : " Category; \
|
||||
std::vector<std::string> stringNames = CatchOverrides::Config<Catch::IConfig const*>::instance().listOfTests(__FILE__, Count ); \
|
||||
Catch::Ptr<Catch::Config> config(new Catch::Config(cd)); \
|
||||
Catch::MSTestReporter* rep = new Catch::MSTestReporter(config.get()); \
|
||||
Catch::RunContext tr(config.get(), rep); \
|
||||
for( std::vector<std::string>::iterator it = stringNames.begin(); it != stringNames.end(); ++it ) { \
|
||||
std::vector<Catch::TestCase> testCase = Catch::getRegistryHub().getTestCaseRegistry().getMatchingTestCases(*it); \
|
||||
if( testCase.empty() ) Assert::Fail(FAIL_STRING("No tests match")); \
|
||||
if( testCase.size() > 1 ) Assert::Fail(FAIL_STRING("More than one test with the same name")); \
|
||||
tr.runTest(*testCase.begin()); \
|
||||
} \
|
||||
} \
|
||||
}; \
|
||||
}
|
||||
|
||||
//#undef CATCH_CONFIG_VARIADIC_MACROS
|
||||
|
||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
||||
|
Reference in New Issue
Block a user