mimic++ v6
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#include "mimic++/Reporter.hpp"
12
13#if __has_include(<gtest/gtest.h>)
14 #include <gtest/gtest.h>
15#else
16 #error "Unable to find gtest includes."
17#endif
18
19namespace mimicpp::detail::gtest
20{
21 struct failure
22 {
23 };
24
25 [[noreturn]]
26 inline void send_fail(const StringViewT& msg)
27 {
28 // GTEST_FAIL has an immediate return
29 std::invoke(
30 [&] {
31 GTEST_FAIL() << msg;
32 });
33
34 throw failure{};
35 }
36
37 inline void send_success(const StringViewT& msg)
38 {
39 GTEST_SUCCEED() << msg;
40 }
41
42 inline void send_warning([[maybe_unused]] const StringViewT& msg)
43 {
44 // seems unsupported
45 }
46}
47
48namespace mimicpp
49{
50 // GCOVR_EXCL_START
51
61 &detail::gtest::send_success,
62 &detail::gtest::send_warning,
63 &detail::gtest::send_fail>;
64
65 // GCOVR_EXCL_STOP
66}
67
68namespace mimicpp::detail::gtest
69{
70 [[maybe_unused]]
71 inline const ReporterInstaller<GTestReporterT> installer{};
72}
73
74#endif
A reporter, which creates text messages and reports them via the provided callbacks.
Definition Reporter.hpp:356
BasicReporter< &detail::gtest::send_success, &detail::gtest::send_warning, &detail::gtest::send_fail > GTestReporterT
Reporter for the integration into gtest.
Definition gtest.hpp:60
Definition BoostTest.hpp:20
std::basic_string_view< CharT, CharTraitsT > StringViewT
Definition Fwd.hpp:345