Refactorization: Moved code out of macro TEST_CASE
This commit is contained in:
parent
d3501e77a8
commit
bcf3a1e9e1
|
@ -20,6 +20,7 @@
|
|||
#include "options.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <list>
|
||||
|
||||
std::ostringstream errout;
|
||||
|
@ -73,15 +74,19 @@ TestFixture::TestFixture(const std::string &_name)
|
|||
}
|
||||
|
||||
|
||||
bool TestFixture::runTest(const char testname[])
|
||||
bool TestFixture::prepareTest(const char testname[])
|
||||
{
|
||||
// Check if tests should be executed
|
||||
if (testToRun.empty() || testToRun == testname) {
|
||||
// Tests will be executed - prepare them
|
||||
++countTests;
|
||||
if (quiet_tests) {
|
||||
std::cout << '.';
|
||||
std::putchar('.'); // Use putchar to write through redirection of std::cout/cerr
|
||||
} else {
|
||||
std::cout << classname << "::" << testname << std::endl;
|
||||
}
|
||||
_lib = Library();
|
||||
currentTest = classname + "::" + testname;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -232,6 +237,10 @@ void TestFixture::run(const std::string &str)
|
|||
if (quiet_tests) {
|
||||
std::cout << '\n' << classname << ':';
|
||||
}
|
||||
if (quiet_tests) {
|
||||
REDIRECT;
|
||||
run();
|
||||
} else
|
||||
run();
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ protected:
|
|||
|
||||
virtual void run() = 0;
|
||||
|
||||
bool runTest(const char testname[]);
|
||||
bool prepareTest(const char testname[]);
|
||||
|
||||
void assert_(const char *filename, unsigned int linenr, bool condition) const;
|
||||
void todoAssert(const char *filename, unsigned int linenr, bool condition) const;
|
||||
|
@ -65,6 +65,7 @@ protected:
|
|||
long long current, long long actual) const;
|
||||
void assertThrowFail(const char *filename, unsigned int linenr) const;
|
||||
void complainMissingLib(const char* libname) const;
|
||||
|
||||
void processOptions(const options& args);
|
||||
public:
|
||||
virtual void reportOut(const std::string &outmsg);
|
||||
|
@ -78,12 +79,12 @@ public:
|
|||
static std::size_t runTests(const options& args);
|
||||
};
|
||||
|
||||
#define TEST_CASE( NAME ) if ( runTest(#NAME) ) { _lib = Library(); currentTest = classname + "::" + #NAME; if (quiet_tests) { REDIRECT; NAME(); } else { NAME ();} }
|
||||
#define TEST_CASE( NAME ) if ( prepareTest(#NAME) ) { NAME(); }
|
||||
#define ASSERT( CONDITION ) assert_(__FILE__, __LINE__, CONDITION)
|
||||
#define ASSERT_EQUALS( EXPECTED , ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
||||
#define ASSERT_EQUALS_DOUBLE( EXPECTED , ACTUAL ) assertEqualsDouble(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
||||
#define ASSERT_EQUALS_MSG( EXPECTED , ACTUAL, MSG ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL, MSG)
|
||||
#define ASSERT_THROW( CMD, EXCEPTION ) try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (EXCEPTION &) { } catch (...) { assertThrowFail(__FILE__, __LINE__); }
|
||||
#define ASSERT_THROW( CMD, EXCEPTION ) try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&) { } catch (...) { assertThrowFail(__FILE__, __LINE__); }
|
||||
#define TODO_ASSERT_EQUALS( WANTED , CURRENT , ACTUAL ) todoAssertEquals(__FILE__, __LINE__, WANTED, CURRENT, ACTUAL)
|
||||
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue