Fix unit test runner to output all case names:

Also fixes a bug where suite::log was incorrectly flushed.
This commit is contained in:
Vinnie Falco
2016-08-29 11:48:45 -04:00
parent 4bb0b9d0d9
commit f144619e7c
3 changed files with 16 additions and 20 deletions

View File

@ -1,5 +1,6 @@
1.0.0-b12
* Fix unit test runner to output all case names
* Update README for build requirements
* Rename to CHANGELOG.md

View File

@ -90,7 +90,6 @@ private:
results results_;
suite_results suite_results_;
case_results case_results_;
bool prefixed_ = false;
public:
reporter(reporter const&) = delete;
@ -228,7 +227,6 @@ reporter<_>::
on_suite_begin(suite_info const& info)
{
suite_results_ = suite_results{info.full_name()};
prefixed_ = false;
}
template<class _>
@ -244,13 +242,9 @@ reporter<_>::
on_case_begin(std::string const& name)
{
case_results_ = case_results(name);
if(! prefixed_)
{
os_ << suite_results_.name <<
(case_results_.name.empty() ? "" :
(" " + case_results_.name)) << std::endl;
prefixed_ = true;
}
os_ << suite_results_.name <<
(case_results_.name.empty() ? "" :
(" " + case_results_.name)) << std::endl;
}
template<class _>
@ -286,13 +280,6 @@ void
reporter<_>::
on_log(std::string const& s)
{
if(!prefixed_)
{
os_ << suite_results_.name <<
(case_results_.name.empty() ? "" :
(" " + case_results_.name)) << "\n";
prefixed_ = true;
}
os_ << s;
os_.flush();
}

View File

@ -72,7 +72,7 @@ private:
{
auto const& s = this->str();
if(s.size() > 0)
suite_.runner_->on_log(s);
suite_.runner_->log(s);
this->str("");
return 0;
}
@ -146,7 +146,9 @@ public:
/** Returns the "current" running suite.
If no suite is running, nullptr is returned.
*/
static suite* this_suite()
static
suite*
this_suite()
{
return *p_this_suite();
}
@ -158,6 +160,7 @@ public:
}
/** Invokes the test using the specified runner.
Data members are set up here instead of the constructor as a
convenience to writing the derived class to avoid repetition of
forwarded constructor arguments to the base.
@ -168,6 +171,7 @@ public:
operator()(runner& r);
/** Evaluate a test condition.
The condition is passed as a template argument instead of `bool` so
that implicit conversion is not required. The `reason` argument is
logged if the condition is false.
@ -298,7 +302,10 @@ public:
{
auto const& name = ss_.str();
if(! name.empty())
{
suite_.log.flush();
suite_.runner_->testcase(name);
}
}
scoped_testcase(suite& self, std::stringstream& ss)
@ -333,10 +340,11 @@ public:
inline
void
suite::testcase_t::operator()(std::string const& name,
abort_t abort)
suite::testcase_t::operator()(
std::string const& name, abort_t abort)
{
suite_.abort_ = abort == abort_on_fail;
suite_.log.flush();
suite_.runner_->testcase(name);
}