Skip to content
Snippets Groups Projects
Commit 99ba8e2b authored by Martin Marinov's avatar Martin Marinov Committed by GitHub Enterprise
Browse files

MTBR-915 Improve baseline records for unexpected ourcomes (#76)

parent 74af306b
Branches
No related tags found
1 merge request!14Merge latest changes to Base from ReForm
...@@ -28,9 +28,8 @@ public: ...@@ -28,9 +28,8 @@ public:
~StopWatchSessionT() NOEXCEPT(false) ~StopWatchSessionT() NOEXCEPT(false)
{ {
const auto dvsr = std::max(ONE, dvsr_);
// TODO: implement "prettier" DEB out if seconds turn into minutes/hours/etc // TODO: implement "prettier" DEB out if seconds turn into minutes/hours/etc
DEB_line_if(dvsr_ == ONE, deb_lvl_, DEB_line_if(dvsr_ <= ONE, deb_lvl_,
sssn_name_ << " took " << sw_.stop() / 1000.0 << " s."); sssn_name_ << " took " << sw_.stop() / 1000.0 << " s.");
DEB_line_if(dvsr_ > ONE, deb_lvl_, DEB_line_if(dvsr_ > ONE, deb_lvl_,
dvsr_ << " x " << sssn_name_ << " took " << sw_.stop() / 1000.0 / dvsr_ dvsr_ << " x " << sssn_name_ << " took " << sw_.stop() / 1000.0 / dvsr_
......
...@@ -20,17 +20,26 @@ namespace Test ...@@ -20,17 +20,26 @@ namespace Test
namespace namespace
{ {
void record_and_handle_unexpected( void record_and_handle_unexpected(const char* const _call, const Outcome& _oc,
const char* const _call, const Outcome& _oc, const bool _unexpected) const bool _unexpected, const char* const _expctd_what)
{ {
TEST(outcome, record(_call, _oc.ok(), _oc.error_description().c_str()));
if (_unexpected) if (_unexpected)
{
Base::OStringStream strm;
strm << "Unexpected outcome: Expected " << _expctd_what
<< " but got " << _oc.error_description().c_str() << " instead!";
TEST(outcome, record(_call, _oc.ok(), strm.str.c_str()));
_oc.unexpected_handler(); _oc.unexpected_handler();
} }
else
TEST(outcome, record(_call, _oc.ok(), _oc.error_description().c_str()));
}
} // namespace } // namespace
Outcome::Outcome() : ok_(true), error_code_("0"), error_message_("Success") {} const char SUCCESS[] = "Success";
const Outcome FAILURE(false, "FAILURE", "Failure");
Outcome::Outcome() : ok_(true), error_code_(SUCCESS), error_message_(SUCCESS) {}
Outcome::Outcome( Outcome::Outcome(
bool _ok, const std::string& _error_code, const std::string& _error_message) bool _ok, const std::string& _error_code, const std::string& _error_message)
...@@ -58,21 +67,22 @@ Outcome::UnexpectedHandler Outcome::unexpected_handler = [] ...@@ -58,21 +67,22 @@ Outcome::UnexpectedHandler Outcome::unexpected_handler = []
const Outcome& record_outcome(const char* const _call, const Outcome& _oc) const Outcome& record_outcome(const char* const _call, const Outcome& _oc)
{ {
// Never call unexpected-outcome handler // Never call unexpected-outcome handler
record_and_handle_unexpected(_call, _oc, false); record_and_handle_unexpected(_call, _oc, false, nullptr);
return _oc; return _oc;
} }
void expect_success(const char* const _call, const Outcome& _oc) void expect_success(const char* const _call, const Outcome& _oc)
{ {
// Call unexpected-outcome handler if the call *failed* // Call unexpected-outcome handler if the call *failed*
record_and_handle_unexpected(_call, _oc, !_oc.ok()); record_and_handle_unexpected(_call, _oc, !_oc.ok(), SUCCESS);
} }
void expect_outcome( void expect_outcome(
const char* const _call, const Outcome& _oc, const char* const _error_code) const char* const _call, const Outcome& _oc, const char* const _error_code)
{ {
// Call unexpected-outcome handler if the error code is not correct // Call unexpected-outcome handler if the error code is not correct
record_and_handle_unexpected(_call, _oc, _oc.error_code() != _error_code); record_and_handle_unexpected(
_call, _oc, _oc.error_code() != _error_code, _error_code);
} }
void expect_outcome( void expect_outcome(
...@@ -84,10 +94,11 @@ void expect_outcome( ...@@ -84,10 +94,11 @@ void expect_outcome(
void expect_failure(const char* const _call, const Outcome& _oc) void expect_failure(const char* const _call, const Outcome& _oc)
{ {
// If _oc represents a failure, replace it with a generic failure outcome // If _oc represents a failure, replace it with a generic failure outcome
auto oc = _oc.ok() ? _oc : Outcome(_oc.ok(), "FAILURE", "Failure"); auto oc = _oc.ok() ? _oc : FAILURE;
// Call unexpected-outcome handler if the call *succeeds* // Call unexpected-outcome handler if the call *succeeds*
record_and_handle_unexpected(_call, oc, oc.ok()); record_and_handle_unexpected(
_call, oc, oc.ok(), FAILURE.error_code().c_str());
} }
void ignore_outcome(const char* const _call, const char* const _reason) void ignore_outcome(const char* const _call, const char* const _reason)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment