liuxiaolong
2021-07-20 58d904a328c0d849769b483e901a0be9426b8209
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// 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)
//
// Official repository: https://github.com/boostorg/beast
//
 
#ifndef BOOST_BEAST_UNIT_TEST_RECORDER_HPP
#define BOOST_BEAST_UNIT_TEST_RECORDER_HPP
 
#include <boost/beast/_experimental/unit_test/results.hpp>
#include <boost/beast/_experimental/unit_test/runner.hpp>
 
namespace boost {
namespace beast {
namespace unit_test {
 
/** A test runner that stores the results. */
class recorder : public runner
{
    results m_results;
    suite_results m_suite;
    case_results m_case;
 
public:
    recorder() = default;
 
    /** Returns a report with the results of all completed suites. */
    results const&
    report() const
    {
        return m_results;
    }
 
private:
    virtual
    void
    on_suite_begin(suite_info const& info) override
    {
        m_suite = suite_results(info.full_name());
    }
 
    virtual
    void
    on_suite_end() override
    {
        m_results.insert(std::move(m_suite));
    }
 
    virtual
    void
    on_case_begin(std::string const& name) override
    {
        m_case = case_results(name);
    }
 
    virtual
    void
    on_case_end() override
    {
        if(m_case.tests.size() > 0)
            m_suite.insert(std::move(m_case));
    }
 
    virtual
    void
    on_pass() override
    {
        m_case.tests.pass();
    }
 
    virtual
    void
    on_fail(std::string const& reason) override
    {
        m_case.tests.fail(reason);
    }
 
    virtual
    void
    on_log(std::string const& s) override
    {
        m_case.log.insert(s);
    }
};
 
} // unit_test
} // beast
} // boost
 
#endif