Improvement of testrunner's output
- Separation between failures - \n is translated into "\\n\n" instead of "\\n", so that a newline is inserted - Succeeded TODOs are no longer mentioned twice - Removed "" around messages
This commit is contained in:
parent
f8181df340
commit
8c541151d6
|
@ -60,6 +60,7 @@ unsigned int TestFixture::countTests;
|
||||||
|
|
||||||
size_t TestFixture::fails_counter = 0;
|
size_t TestFixture::fails_counter = 0;
|
||||||
size_t TestFixture::todos_counter = 0;
|
size_t TestFixture::todos_counter = 0;
|
||||||
|
size_t TestFixture::succeeded_todos_counter = 0;
|
||||||
|
|
||||||
TestFixture::TestFixture(const std::string &_name)
|
TestFixture::TestFixture(const std::string &_name)
|
||||||
:classname(_name)
|
:classname(_name)
|
||||||
|
@ -77,29 +78,34 @@ bool TestFixture::runTest(const char testname[])
|
||||||
if (quiet_tests) {
|
if (quiet_tests) {
|
||||||
std::cout << '.';
|
std::cout << '.';
|
||||||
} else {
|
} else {
|
||||||
std::cout << classname << "::" << testname << "\n";
|
std::cout << classname << "::" << testname << std::endl;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string writestr(const std::string &str)
|
static std::string writestr(const std::string &str, bool gccStyle = false)
|
||||||
{
|
{
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
ostr << "\"";
|
if (gccStyle)
|
||||||
for (unsigned int i = 0; i < str.length(); ++i) {
|
ostr << '\"';
|
||||||
char ch = str[i];
|
for (std::string::const_iterator i = str.begin(); i != str.end(); ++i) {
|
||||||
if (ch == '\n')
|
if (*i == '\n') {
|
||||||
ostr << "\\n";
|
ostr << "\\n";
|
||||||
else if (ch == '\t')
|
if ((i+1) != str.end() && !gccStyle)
|
||||||
|
ostr << std::endl;
|
||||||
|
} else if (*i == '\t')
|
||||||
ostr << "\\t";
|
ostr << "\\t";
|
||||||
else if (ch == '\"')
|
else if (*i == '\"')
|
||||||
ostr << "\\\"";
|
ostr << "\\\"";
|
||||||
else
|
else
|
||||||
ostr << std::string(1, ch);
|
ostr << *i;
|
||||||
}
|
}
|
||||||
ostr << "\"";
|
if (!str.empty() && !gccStyle)
|
||||||
|
ostr << std::endl;
|
||||||
|
else if (gccStyle)
|
||||||
|
ostr << '\"';
|
||||||
return ostr.str();
|
return ostr.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +116,7 @@ void TestFixture::assert_(const char *filename, int linenr, bool condition)
|
||||||
if (gcc_style_errors) {
|
if (gcc_style_errors) {
|
||||||
errmsg << filename << ':' << linenr << ": Assertion failed." << std::endl;
|
errmsg << filename << ':' << linenr << ": Assertion failed." << std::endl;
|
||||||
} else {
|
} else {
|
||||||
errmsg << "Assertion failed in " << filename << " at line " << linenr << std::endl;
|
errmsg << "_____" << std::endl << "Assertion failed in " << filename << " at line " << linenr << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,17 +128,17 @@ void TestFixture::assertEquals(const char *filename, int linenr, const std::stri
|
||||||
if (gcc_style_errors) {
|
if (gcc_style_errors) {
|
||||||
errmsg << filename << ':' << linenr << ": Assertion failed. "
|
errmsg << filename << ':' << linenr << ": Assertion failed. "
|
||||||
<< "Expected: "
|
<< "Expected: "
|
||||||
<< writestr(expected)
|
<< writestr(expected, true)
|
||||||
<< ". Actual: "
|
<< ". Actual: "
|
||||||
<< writestr(actual)
|
<< writestr(actual, true)
|
||||||
<< "."
|
<< '.'
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
} else {
|
} else {
|
||||||
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
|
||||||
<< "Actual:" << std::endl
|
<< "Actual:" << std::endl
|
||||||
<< writestr(actual) << std::endl;
|
<< writestr(actual) << std::endl << "_____" << std::endl;
|
||||||
}
|
}
|
||||||
if (!msg.empty()) {
|
if (!msg.empty()) {
|
||||||
errmsg << msg << std::endl;
|
errmsg << msg << std::endl;
|
||||||
|
@ -163,10 +169,17 @@ void TestFixture::todoAssertEquals(const char *filename, int linenr,
|
||||||
const std::string ¤t,
|
const std::string ¤t,
|
||||||
const std::string &actual)
|
const std::string &actual)
|
||||||
{
|
{
|
||||||
assertEquals(filename, linenr, current, actual);
|
|
||||||
if (wanted == actual) {
|
if (wanted == actual) {
|
||||||
assertEquals(filename, linenr, "TODO assertion", "The assertion succeeded");
|
if (gcc_style_errors) {
|
||||||
|
errmsg << filename << ':' << linenr << ": Assertion succeeded unexpectedly. "
|
||||||
|
<< "Result: " << writestr(wanted, true) << "." << std::endl;
|
||||||
|
} else {
|
||||||
|
errmsg << "Assertion succeeded unexpectedly in " << filename << " at line " << linenr << std::endl
|
||||||
|
<< "Result:" << std::endl << writestr(wanted) << std::endl << "_____" << std::endl;
|
||||||
|
}
|
||||||
|
++succeeded_todos_counter;
|
||||||
} else {
|
} else {
|
||||||
|
assertEquals(filename, linenr, current, actual);
|
||||||
++todos_counter;
|
++todos_counter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +200,7 @@ void TestFixture::assertThrowFail(const char *filename, int linenr)
|
||||||
errmsg << filename << ':' << linenr << " Assertion failed. "
|
errmsg << filename << ':' << linenr << " Assertion failed. "
|
||||||
<< "The expected exception was not thrown" << std::endl;
|
<< "The expected exception was not thrown" << std::endl;
|
||||||
} else {
|
} else {
|
||||||
errmsg << "Assertion failed in " << filename << " at line " << linenr << std::endl
|
errmsg << "_____" << std::endl << "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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,12 +250,15 @@ size_t TestFixture::runTests(const options& args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "\n\nTesting Complete\nNumber of tests: " << countTests << "\n";
|
std::cout << "\n\nTesting Complete\nNumber of tests: " << countTests << std::endl;
|
||||||
std::cout << "Number of todos: " << todos_counter << "\n";
|
std::cout << "Number of todos: " << todos_counter;
|
||||||
|
if (succeeded_todos_counter > 0)
|
||||||
|
std::cout << " (" << succeeded_todos_counter << " succeeded)";
|
||||||
|
std::cout << std::endl;
|
||||||
// calling flush here, to do all output before the error messages (in case the output is buffered)
|
// calling flush here, to do all output before the error messages (in case the output is buffered)
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
|
|
||||||
std::cerr << "Tests failed: " << fails_counter << "\n";
|
std::cerr << "Tests failed: " << fails_counter << std::endl << std::endl;
|
||||||
std::cerr << errmsg.str();
|
std::cerr << errmsg.str();
|
||||||
std::cerr.flush();
|
std::cerr.flush();
|
||||||
return fails_counter;
|
return fails_counter;
|
||||||
|
|
|
@ -34,6 +34,7 @@ private:
|
||||||
static unsigned int countTests;
|
static unsigned int countTests;
|
||||||
static size_t fails_counter;
|
static size_t fails_counter;
|
||||||
static size_t todos_counter;
|
static size_t todos_counter;
|
||||||
|
static size_t succeeded_todos_counter;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string classname;
|
std::string classname;
|
||||||
|
|
Loading…
Reference in New Issue