Fixed ticket #481 (testrunner should exit with non-zero status if one of tests fails)
http://sourceforge.net/apps/trac/cppcheck/ticket/481
This commit is contained in:
parent
a0a526a205
commit
d04eeb4fd4
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
int main(int argc, const char *argv[])
|
int main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
TestFixture::runTests((argc == 2) ? argv[1] : NULL);
|
return TestFixture::runTests((argc == 2) ? argv[1] : NULL);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,8 @@ public:
|
||||||
std::ostringstream TestFixture::errmsg;
|
std::ostringstream TestFixture::errmsg;
|
||||||
unsigned int TestFixture::countTests;
|
unsigned int TestFixture::countTests;
|
||||||
|
|
||||||
|
size_t TestFixture::fails_counter = 0;
|
||||||
|
|
||||||
TestFixture::TestFixture(const std::string &_name) : classname(_name)
|
TestFixture::TestFixture(const std::string &_name) : classname(_name)
|
||||||
{
|
{
|
||||||
TestRegistry::theInstance().addTest(this);
|
TestRegistry::theInstance().addTest(this);
|
||||||
|
@ -105,6 +107,8 @@ void TestFixture::assertEquals(const char *filename, int linenr, const std::stri
|
||||||
{
|
{
|
||||||
if (expected != actual)
|
if (expected != actual)
|
||||||
{
|
{
|
||||||
|
++fails_counter;
|
||||||
|
|
||||||
errmsg << "Assertion failed in " << filename << " at line " << linenr << std::endl
|
errmsg << "Assertion failed in " << filename << " at line " << linenr << std::endl
|
||||||
<< "Expected:" << std::endl
|
<< "Expected:" << std::endl
|
||||||
<< writestr(expected) << std::endl
|
<< writestr(expected) << std::endl
|
||||||
|
@ -124,6 +128,8 @@ void TestFixture::assertEquals(const char *filename, int linenr, unsigned int ex
|
||||||
|
|
||||||
void TestFixture::assertThrowFail(const char *filename, int linenr)
|
void TestFixture::assertThrowFail(const char *filename, int linenr)
|
||||||
{
|
{
|
||||||
|
++fails_counter;
|
||||||
|
|
||||||
errmsg << "Assertion failed in " << filename << " at line " << linenr << std::endl
|
errmsg << "Assertion failed in " << filename << " at line " << linenr << std::endl
|
||||||
<< "The expected exception was not thrown" << std::endl;
|
<< "The expected exception was not thrown" << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -144,7 +150,7 @@ void TestFixture::run(const std::string &str)
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestFixture::runTests(const char cmd[])
|
size_t TestFixture::runTests(const char cmd[])
|
||||||
{
|
{
|
||||||
std::string classname(cmd ? cmd : "");
|
std::string classname(cmd ? cmd : "");
|
||||||
std::string testname("");
|
std::string testname("");
|
||||||
|
@ -170,6 +176,8 @@ void TestFixture::runTests(const char cmd[])
|
||||||
std::cout << "\n\nTesting Complete\nNumber of tests: " << countTests << "\n";
|
std::cout << "\n\nTesting Complete\nNumber of tests: " << countTests << "\n";
|
||||||
|
|
||||||
std::cerr << errmsg.str();
|
std::cerr << errmsg.str();
|
||||||
|
|
||||||
|
return fails_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestFixture::reportOut(const std::string & /*outmsg*/)
|
void TestFixture::reportOut(const std::string & /*outmsg*/)
|
||||||
|
|
|
@ -29,6 +29,7 @@ class TestFixture : public ErrorLogger
|
||||||
private:
|
private:
|
||||||
static std::ostringstream errmsg;
|
static std::ostringstream errmsg;
|
||||||
static unsigned int countTests;
|
static unsigned int countTests;
|
||||||
|
static size_t fails_counter;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string classname;
|
std::string classname;
|
||||||
|
@ -52,7 +53,7 @@ public:
|
||||||
virtual ~TestFixture() { }
|
virtual ~TestFixture() { }
|
||||||
|
|
||||||
static void printTests();
|
static void printTests();
|
||||||
static void runTests(const char cmd[]);
|
static size_t runTests(const char cmd[]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue