File: test_reporter.hpp

package info (click to toggle)
trompeloeil-cpp 47-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,476 kB
  • sloc: cpp: 17,573; sh: 126; makefile: 5
file content (86 lines) | stat: -rw-r--r-- 1,839 bytes parent folder | download
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
#ifndef TROMPELOEIL_TEST_REPORTER_HPP
#define TROMPELOEIL_TEST_REPORTER_HPP

#include <trompeloeil.hpp>

namespace detail
{
/*
 * Use compiler-version independent make_unique.
 */
using ::trompeloeil::detail::make_unique;

// std::uncaught_exception() is deprecated in C++17.
inline
bool
there_are_uncaught_exceptions()
{
    /*
     * GCC 5.x supports specifying -std=c++17 but libstdc++-v3 for
     * GCC 5.x doesn't declare std::uncaught_exceptions().
     * Rather than detect what version of C++ Standard Library
     * is in use, we equate the compiler version with the library version.
     *
     * Some day this test will based on __cpp_lib_uncaught_exceptions.
     */
#   if (TROMPELOEIL_CPLUSPLUS > 201402L) && \
       ((!TROMPELOEIL_GCC) || \
        (TROMPELOEIL_GCC && TROMPELOEIL_GCC_VERSION >= 60000))

    return std::uncaught_exceptions() > 0;

#   else

    return std::uncaught_exception();

#   endif
}

} /* namespace detail */

class reported {};

struct report
{
    trompeloeil::severity s;
    const char           *file;
    unsigned long         line;
    std::string           msg;
};

extern std::vector<report> reports;
extern std::vector<std::string> okReports;

namespace trompeloeil
{
template <>
struct reporter<specialized>
{
    static void send(severity s,
                     char const* file,
                     unsigned long line,
                     char const* msg)
    {
        reports.push_back(report{s, file, line, msg});
        if (s == severity::fatal && !::detail::there_are_uncaught_exceptions())
        {
            throw reported{};
        }
    }

    static void sendOk(char const* msg)
    {
        okReports.push_back(msg);
    }
};
}

struct Fixture
{
    Fixture() {
        reports.clear();
        okReports.clear();
    }
};

#endif //TROMPELOEIL_TEST_REPORTER_HPP