mimic++ v9.2.1
Loading...
Searching...
No Matches
gtest.hpp
Go to the documentation of this file.
1// Copyright Dominic (DNKpp) Koepke 2024 - 2025.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef MIMICPP_ADAPTERS_GTEST_HPP
7#define MIMICPP_ADAPTERS_GTEST_HPP
8
9#pragma once
10
11#if __has_include("mimic++/Reporting.hpp")
12 #include "mimic++/Reporting.hpp"
13#elif not defined(MIMICPP_VERSION)
14 #error "It appears that the test-adapter is not included in the mimic++ project or package." \
15 "If you plan to use it alongside the mimic++-amalgamated header, please ensure to include the adapter-header afterwards."
16#endif
17
18#if __has_include(<gtest/gtest.h>)
19 #include <gtest/gtest.h>
20#else
21 #error "Unable to find gtest includes."
22#endif
23
24namespace mimicpp::reporting::detail::gtest
25{
26 struct failure
27 {
28 };
29
30 [[noreturn]]
31 inline void send_fail(StringViewT const msg)
32 {
33 // GTEST_FAIL has an immediate return
34 std::invoke(
35 [&] {
36 GTEST_FAIL() << msg;
37 });
38
39 throw failure{};
40 }
41
42 inline void send_success(StringViewT const msg)
43 {
44 GTEST_SUCCEED() << msg;
45 }
46
47 inline void send_warning([[maybe_unused]] StringViewT const msg)
48 {
49 // seems unsupported
50 }
51}
52
53namespace mimicpp::reporting
54{
55 // GCOVR_EXCL_START
56
66 &detail::gtest::send_success,
67 &detail::gtest::send_warning,
68 &detail::gtest::send_fail>;
69
70 // GCOVR_EXCL_STOP
71}
72
73namespace mimicpp::reporting::detail::gtest
74{
75 [[maybe_unused]]
76 inline ReporterInstaller<GTestReporterT> const installer{};
77}
78
79#endif
A reporter, which creates text messages and reports them via the provided callbacks.
Definition BasicReporter.hpp:40
BasicReporter< &detail::gtest::send_success, &detail::gtest::send_warning, &detail::gtest::send_fail > GTestReporterT
Reporter for the integration into gtest.
Definition gtest.hpp:65
Definition BasicReporter.hpp:27
std::basic_string_view< CharT, CharTraitsT > StringViewT
Definition Fwd.hpp:392