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 1.0.0-b12
* Fix unit test runner to output all case names
* Update README for build requirements * Update README for build requirements
* Rename to CHANGELOG.md * Rename to CHANGELOG.md

View File

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

View File

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