2017-07-20 08:01:46 -07:00
|
|
|
//
|
2017-02-06 20:07:03 -05:00
|
|
|
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2017-07-20 08:01:46 -07:00
|
|
|
//
|
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
//
|
|
|
|
|
|
2016-05-06 19:14:17 -04:00
|
|
|
#ifndef BEAST_UNIT_TEST_RECORDER_HPP
|
|
|
|
|
#define BEAST_UNIT_TEST_RECORDER_HPP
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-05-06 19:14:17 -04:00
|
|
|
#include <beast/unit_test/results.hpp>
|
|
|
|
|
#include <beast/unit_test/runner.hpp>
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
|
namespace beast {
|
|
|
|
|
namespace unit_test {
|
|
|
|
|
|
|
|
|
|
/** A test runner that stores the results. */
|
|
|
|
|
class recorder : public runner
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
results m_results;
|
|
|
|
|
suite_results m_suite;
|
|
|
|
|
case_results m_case;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
recorder() = default;
|
2016-08-29 10:43:56 -04:00
|
|
|
recorder(recorder const&) = default;
|
|
|
|
|
recorder& operator=(recorder const&) = default;
|
2017-07-20 08:01:46 -07:00
|
|
|
|
|
|
|
|
/** Returns a report with the results of all completed suites. */
|
|
|
|
|
results const&
|
|
|
|
|
report() const
|
|
|
|
|
{
|
|
|
|
|
return m_results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
virtual
|
|
|
|
|
void
|
2016-08-29 10:43:56 -04:00
|
|
|
on_suite_begin(suite_info const& info) override
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
2016-08-29 10:43:56 -04:00
|
|
|
m_suite = suite_results(info.full_name());
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual
|
|
|
|
|
void
|
|
|
|
|
on_suite_end() override
|
|
|
|
|
{
|
2016-08-29 10:43:56 -04:00
|
|
|
m_results.insert(std::move(m_suite));
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual
|
|
|
|
|
void
|
2016-08-29 10:43:56 -04:00
|
|
|
on_case_begin(std::string const& name) override
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
2016-08-29 10:43:56 -04:00
|
|
|
m_case = case_results(name);
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual
|
|
|
|
|
void
|
|
|
|
|
on_case_end() override
|
|
|
|
|
{
|
2016-08-26 08:01:44 -04:00
|
|
|
if(m_case.tests.size() > 0)
|
2016-08-29 10:43:56 -04:00
|
|
|
m_suite.insert(std::move(m_case));
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual
|
|
|
|
|
void
|
|
|
|
|
on_pass() override
|
|
|
|
|
{
|
|
|
|
|
m_case.tests.pass();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual
|
|
|
|
|
void
|
2016-08-29 10:43:56 -04:00
|
|
|
on_fail(std::string const& reason) override
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
2016-08-29 10:43:56 -04:00
|
|
|
m_case.tests.fail(reason);
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual
|
|
|
|
|
void
|
2016-08-29 10:43:56 -04:00
|
|
|
on_log(std::string const& s) override
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
2016-08-29 10:43:56 -04:00
|
|
|
m_case.log.insert(s);
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // unit_test
|
|
|
|
|
} // beast
|
|
|
|
|
|
|
|
|
|
#endif
|