rippled
Loading...
Searching...
No Matches
recorder.h
1// Distributed under the Boost Software License, Version 1.0. (See accompanying
2// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
3//
4
5#pragma once
6
7#include <xrpl/beast/unit_test/results.h>
8#include <xrpl/beast/unit_test/runner.h>
9
10namespace beast {
11namespace unit_test {
12
14class recorder : public runner
15{
16private:
20
21public:
22 recorder() = default;
23
25 results const&
26 report() const
27 {
28 return m_results;
29 }
30
31private:
32 virtual void
33 on_suite_begin(suite_info const& info) override
34 {
36 }
37
38 virtual void
39 on_suite_end() override
40 {
41 m_results.insert(std::move(m_suite));
42 }
43
44 virtual void
45 on_case_begin(std::string const& name) override
46 {
47 m_case = case_results(name);
48 }
49
50 virtual void
51 on_case_end() override
52 {
53 if (m_case.tests.size() > 0)
54 m_suite.insert(std::move(m_case));
55 }
56
57 virtual void
58 on_pass() override
59 {
61 }
62
63 virtual void
64 on_fail(std::string const& reason) override
65 {
66 m_case.tests.fail(reason);
67 }
68
69 virtual void
70 on_log(std::string const& s) override
71 {
72 m_case.log.insert(s);
73 }
74};
75
76} // namespace unit_test
77} // namespace beast
void insert(std::string const &s)
Insert a string into the log.
Definition results.h:80
void pass()
Register a successful test condition.
Definition results.h:61
void fail(std::string const &reason="")
Register a failed test condition.
Definition results.h:68
Holds a set of test condition outcomes in a testcase.
Definition results.h:17
tests_t tests
Memberspace for a container of test condition outcomes.
Definition results.h:101
log_t log
Memberspace for a container of testcase log messages.
Definition results.h:104
size_type size() const
Returns the number of items in the container.
A test runner that stores the results.
Definition recorder.h:15
results const & report() const
Returns a report with the results of all completed suites.
Definition recorder.h:26
virtual void on_suite_end() override
Called when a suite ends.
Definition recorder.h:39
virtual void on_fail(std::string const &reason) override
Called for each failing condition.
Definition recorder.h:64
virtual void on_case_end() override
Called when a new case ends.
Definition recorder.h:51
suite_results m_suite
Definition recorder.h:18
virtual void on_case_begin(std::string const &name) override
Called when a new case starts.
Definition recorder.h:45
virtual void on_suite_begin(suite_info const &info) override
Called when a new suite starts.
Definition recorder.h:33
virtual void on_pass() override
Called for each passing condition.
Definition recorder.h:58
virtual void on_log(std::string const &s) override
Called when a test logs output.
Definition recorder.h:70
Holds the results of running a set of testsuites.
Definition results.h:168
void insert(suite_results &&r)
Insert a set of suite results.
Definition results.h:203
Unit test runner interface.
Definition runner.h:23
Associates a unit test type with metadata.
Definition suite_info.h:19
std::string full_name() const
Return the canonical suite name as a string.
Definition suite_info.h:67
Holds the set of testcase results in a suite.
Definition results.h:111
void insert(case_results &&r)
Insert a set of testcase results.
Definition results.h:146