Refactorized test suite
This commit is contained in:
parent
a447d2c6a8
commit
0073a633b0
|
@ -19,7 +19,7 @@
|
|||
#include "checkio.h"
|
||||
#include "testsuite.h"
|
||||
#include "tokenize.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
class TestIO : public TestFixture {
|
||||
public:
|
||||
|
@ -746,7 +746,7 @@ private:
|
|||
|
||||
|
||||
#define TEST_SCANF_CODE(format, type)\
|
||||
"void f() { " type " x; scanf(\"" format "\", &x); }"
|
||||
"void f(){" type " x; scanf(\"" format "\", &x);}"
|
||||
|
||||
#define TEST_SCANF_ERR(format, formatStr, type)\
|
||||
"[test.cpp:1]: (warning) " format " in format string (no. 1) requires '" formatStr " *' but the argument type is '" type " *'.\n"
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
|
||||
std::ostringstream errout;
|
||||
std::ostringstream output;
|
||||
std::ostringstream warnings;
|
||||
|
||||
/**
|
||||
* TestRegistry
|
||||
|
@ -66,7 +65,7 @@ std::size_t TestFixture::todos_counter = 0;
|
|||
std::size_t TestFixture::succeeded_todos_counter = 0;
|
||||
std::set<std::string> TestFixture::missingLibs;
|
||||
|
||||
TestFixture::TestFixture(const std::string &_name)
|
||||
TestFixture::TestFixture(const char* _name)
|
||||
:classname(_name)
|
||||
,quiet_tests(false)
|
||||
{
|
||||
|
@ -86,7 +85,6 @@ bool TestFixture::prepareTest(const char testname[])
|
|||
} else {
|
||||
std::cout << classname << "::" << testname << std::endl;
|
||||
}
|
||||
currentTest = classname + "::" + testname;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -121,7 +119,6 @@ void TestFixture::assert_(const char *filename, unsigned int linenr, bool condit
|
|||
if (!condition) {
|
||||
++fails_counter;
|
||||
errmsg << filename << ':' << linenr << ": Assertion failed." << std::endl << "_____" << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,8 +134,6 @@ void TestFixture::assertEquals(const char *filename, unsigned int linenr, const
|
|||
if (!msg.empty())
|
||||
errmsg << "Hint:" << std::endl << msg << std::endl;
|
||||
errmsg << "_____" << std::endl;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
void TestFixture::assertEquals(const char *filename, unsigned int linenr, const char expected[], const std::string& actual, const std::string &msg) const
|
||||
|
@ -156,20 +151,24 @@ void TestFixture::assertEquals(const char *filename, unsigned int linenr, const
|
|||
|
||||
void TestFixture::assertEquals(const char *filename, unsigned int linenr, long long expected, long long actual, const std::string &msg) const
|
||||
{
|
||||
std::ostringstream ostr1;
|
||||
ostr1 << expected;
|
||||
std::ostringstream ostr2;
|
||||
ostr2 << actual;
|
||||
assertEquals(filename, linenr, ostr1.str(), ostr2.str(), msg);
|
||||
if (expected != actual) {
|
||||
std::ostringstream ostr1;
|
||||
ostr1 << expected;
|
||||
std::ostringstream ostr2;
|
||||
ostr2 << actual;
|
||||
assertEquals(filename, linenr, ostr1.str(), ostr2.str(), msg);
|
||||
}
|
||||
}
|
||||
|
||||
void TestFixture::assertEqualsDouble(const char *filename, unsigned int linenr, double expected, double actual, const std::string &msg) const
|
||||
{
|
||||
std::ostringstream ostr1;
|
||||
ostr1 << expected;
|
||||
std::ostringstream ostr2;
|
||||
ostr2 << actual;
|
||||
assertEquals(filename, linenr, ostr1.str(), ostr2.str(), msg);
|
||||
if (expected != actual) {
|
||||
std::ostringstream ostr1;
|
||||
ostr1 << expected;
|
||||
std::ostringstream ostr2;
|
||||
ostr2 << actual;
|
||||
assertEquals(filename, linenr, ostr1.str(), ostr2.str(), msg);
|
||||
}
|
||||
}
|
||||
|
||||
void TestFixture::todoAssertEquals(const char *filename, unsigned int linenr,
|
||||
|
@ -265,10 +264,6 @@ std::size_t TestFixture::runTests(const options& args)
|
|||
}
|
||||
}
|
||||
|
||||
const std::string &w(warnings.str());
|
||||
if (!w.empty()) {
|
||||
std::cout << "\n\n" << w;
|
||||
}
|
||||
std::cout << "\n\nTesting Complete\nNumber of tests: " << countTests << std::endl;
|
||||
std::cout << "Number of todos: " << todos_counter;
|
||||
if (succeeded_todos_counter > 0)
|
||||
|
|
|
@ -39,7 +39,6 @@ protected:
|
|||
std::string classname;
|
||||
std::string testToRun;
|
||||
bool quiet_tests;
|
||||
std::string currentTest;
|
||||
|
||||
virtual void run() = 0;
|
||||
|
||||
|
@ -69,7 +68,7 @@ public:
|
|||
virtual void reportErr(const ErrorLogger::ErrorMessage &msg);
|
||||
void run(const std::string &str);
|
||||
|
||||
explicit TestFixture(const std::string &_name);
|
||||
explicit TestFixture(const char* _name);
|
||||
virtual ~TestFixture() { }
|
||||
|
||||
static std::size_t runTests(const options& args);
|
||||
|
@ -77,7 +76,6 @@ public:
|
|||
|
||||
extern std::ostringstream errout;
|
||||
extern std::ostringstream output;
|
||||
extern std::ostringstream warnings;
|
||||
|
||||
#define TEST_CASE( NAME ) if ( prepareTest(#NAME) ) { NAME(); }
|
||||
#define ASSERT( CONDITION ) assert_(__FILE__, __LINE__, CONDITION)
|
||||
|
|
Loading…
Reference in New Issue