Fixed #1324 (show number of tests that don't produce the desired results)
This commit is contained in:
parent
94c5d92b2b
commit
c6263b51b5
|
@ -65,6 +65,7 @@ std::ostringstream TestFixture::errmsg;
|
|||
unsigned int TestFixture::countTests;
|
||||
|
||||
size_t TestFixture::fails_counter = 0;
|
||||
size_t TestFixture::todos_counter = 0;
|
||||
|
||||
TestFixture::TestFixture(const std::string &_name) : classname(_name)
|
||||
{
|
||||
|
@ -126,6 +127,23 @@ void TestFixture::assertEquals(const char *filename, int linenr, unsigned int ex
|
|||
assertEquals(filename, linenr, ostr1.str(), ostr2.str());
|
||||
}
|
||||
|
||||
void TestFixture::todoAssertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual)
|
||||
{
|
||||
if (expected == actual)
|
||||
assertEquals(filename, linenr, "TODO assertion", "The assertion succeeded");
|
||||
else
|
||||
++todos_counter;
|
||||
}
|
||||
|
||||
void TestFixture::todoAssertEquals(const char *filename, int linenr, unsigned int expected, unsigned int actual)
|
||||
{
|
||||
std::ostringstream ostr1;
|
||||
ostr1 << expected;
|
||||
std::ostringstream ostr2;
|
||||
ostr2 << actual;
|
||||
todoAssertEquals(filename, linenr, ostr1.str(), ostr2.str());
|
||||
}
|
||||
|
||||
void TestFixture::assertThrowFail(const char *filename, int linenr)
|
||||
{
|
||||
++fails_counter;
|
||||
|
@ -174,6 +192,7 @@ size_t TestFixture::runTests(const char cmd[])
|
|||
}
|
||||
|
||||
std::cout << "\n\nTesting Complete\nNumber of tests: " << countTests << "\n";
|
||||
std::cout << "Number of todos: " << todos_counter << "\n";
|
||||
|
||||
std::cerr << errmsg.str();
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ private:
|
|||
static std::ostringstream errmsg;
|
||||
static unsigned int countTests;
|
||||
static size_t fails_counter;
|
||||
static size_t todos_counter;
|
||||
|
||||
protected:
|
||||
std::string classname;
|
||||
|
@ -42,6 +43,8 @@ protected:
|
|||
|
||||
void assertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual);
|
||||
void assertEquals(const char *filename, int linenr, unsigned int expected, unsigned int actual);
|
||||
void todoAssertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual);
|
||||
void todoAssertEquals(const char *filename, int linenr, unsigned int expected, unsigned int actual);
|
||||
void assertThrowFail(const char *filename, int linenr);
|
||||
|
||||
public:
|
||||
|
@ -61,7 +64,7 @@ public:
|
|||
#define TEST_CASE( NAME ) if ( runTest(#NAME) ) NAME ();
|
||||
#define ASSERT_EQUALS( EXPECTED , ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
||||
#define ASSERT_THROW( CMD, EXCEPTION ) try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (EXCEPTION &) { } catch (...) { assertThrowFail(__FILE__, __LINE__); }
|
||||
#define TODO_ASSERT_EQUALS( EXPECTED , ACTUAL ) if (EXPECTED==ACTUAL) assertEquals(__FILE__, __LINE__, "TODO assertion", "The assertion succeeded")
|
||||
#define TODO_ASSERT_EQUALS( EXPECTED , ACTUAL ) todoAssertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
||||
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance; }
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue