-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
197 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// // Copyright Dominic (DNKpp) Koepke 2024 - 2024. | ||
// // Distributed under the Boost Software License, Version 1.0. | ||
// // (See accompanying file LICENSE_1_0.txt or copy at | ||
// // https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#ifndef MIMICPP_ADAPTERS_DOCTEST_HPP | ||
#define MIMICPP_ADAPTERS_DOCTEST_HPP | ||
|
||
#pragma once | ||
|
||
#include "mimic++/Reporter.hpp" | ||
|
||
#if __has_include(<doctest/doctest.h>) | ||
#include <doctest/doctest.h> | ||
#else | ||
#error "Unable to find Doctest includes." | ||
#endif | ||
|
||
namespace mimicpp::detail::doctest | ||
{ | ||
using namespace ::doctest; | ||
|
||
[[noreturn]] | ||
inline void send_fail([[maybe_unused]] const StringViewT msg) | ||
{ | ||
DOCTEST_FAIL(msg); | ||
unreachable(); | ||
} | ||
|
||
inline void send_success(const StringViewT msg) | ||
{ | ||
DOCTEST_REQUIRE_MESSAGE(true, msg); | ||
} | ||
|
||
inline void send_warning(const StringViewT msg) | ||
{ | ||
DOCTEST_MESSAGE(msg); | ||
} | ||
} | ||
|
||
namespace mimicpp | ||
{ | ||
/** | ||
* \brief Reporter for the integration into Doctest. | ||
* \ingroup REPORTING_ADAPTERS | ||
* \details This reporter enables the integration of ``mimic++`` into ``Doctest`` and prefixes the headers | ||
* of ``Doctest`` with ``doctest/``. | ||
* | ||
* This reporter installs itself by simply including this header file into any source file of the test executable. | ||
*/ | ||
using DoctestReporterT = BasicReporter< | ||
&detail::doctest::send_success, | ||
&detail::doctest::send_warning, | ||
&detail::doctest::send_fail | ||
>; | ||
} | ||
|
||
namespace mimicpp::detail::doctest | ||
{ | ||
inline const ReporterInstaller<DoctestReporterT> installer{}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright Dominic (DNKpp) Koepke 2024 - 2024. | ||
# Distributed under the Boost Software License, Version 1.0. | ||
# (See accompanying file LICENSE_1_0.txt or copy at | ||
# https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
set(TARGET_NAME "mimicpp-adapter-tests-doctest") | ||
add_executable(${TARGET_NAME} | ||
"main.cpp" | ||
) | ||
|
||
include(EnableWarnings) | ||
include(EnableSanitizers) | ||
enable_sanitizers(${TARGET_NAME}) | ||
|
||
CPMAddPackage("gh:doctest/[email protected]") | ||
|
||
target_link_libraries(${TARGET_NAME} | ||
PRIVATE | ||
mimicpp::mimicpp | ||
mimicpp::internal::warnings | ||
doctest::doctest | ||
) | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${doctest_SOURCE_DIR}/scripts/cmake") | ||
include(doctest) | ||
doctest_discover_tests(${TARGET_NAME}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// // Copyright Dominic (DNKpp) Koepke 2024 - 2024. | ||
// // Distributed under the Boost Software License, Version 1.0. | ||
// // (See accompanying file LICENSE_1_0.txt or copy at | ||
// // https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN | ||
#include "mimic++/adapters/Doctest.hpp" | ||
|
||
namespace | ||
{ | ||
inline std::atomic_int g_SuccessCounter{0}; | ||
inline std::atomic_int g_WarningCounter{0}; | ||
|
||
class SuccessListener final | ||
: public doctest::IReporter | ||
{ | ||
public: | ||
explicit SuccessListener([[maybe_unused]] const doctest::ContextOptions& in) | ||
{ | ||
} | ||
|
||
void report_query([[maybe_unused]] const doctest::QueryData& in) override | ||
{ | ||
} | ||
|
||
void test_run_start() override | ||
{ | ||
} | ||
|
||
void test_run_end([[maybe_unused]] const doctest::TestRunStats& in) override | ||
{ | ||
} | ||
|
||
void test_case_start([[maybe_unused]] const doctest::TestCaseData& in) override | ||
{ | ||
} | ||
|
||
void test_case_reenter([[maybe_unused]] const doctest::TestCaseData& in) override | ||
{ | ||
} | ||
|
||
void test_case_end([[maybe_unused]] const doctest::CurrentTestCaseStats& in) override | ||
{ | ||
} | ||
|
||
void test_case_exception([[maybe_unused]] const doctest::TestCaseException& in) override | ||
{ | ||
} | ||
|
||
void subcase_start([[maybe_unused]] const doctest::SubcaseSignature& in) override | ||
{ | ||
} | ||
|
||
void subcase_end() override | ||
{ | ||
} | ||
|
||
void log_assert([[maybe_unused]] const doctest::AssertData& in) override | ||
{ | ||
if (!in.m_failed) | ||
{ | ||
++g_SuccessCounter; | ||
} | ||
} | ||
|
||
void log_message([[maybe_unused]] const doctest::MessageData& in) override | ||
{ | ||
if (in.m_string == "Warning") | ||
{ | ||
++g_WarningCounter; | ||
} | ||
} | ||
|
||
void test_case_skipped([[maybe_unused]] const doctest::TestCaseData& in) override | ||
{ | ||
} | ||
}; | ||
} | ||
|
||
REGISTER_LISTENER("SuccessListener", 1, SuccessListener); | ||
|
||
TEST_SUITE("adapter::doctest") | ||
{ | ||
TEST_CASE("doctest::send_success notifies Doctest for success.") | ||
{ | ||
g_SuccessCounter = 0; | ||
|
||
mimicpp::detail::doctest::send_success("Success"); | ||
|
||
REQUIRE(g_SuccessCounter == 1); | ||
} | ||
|
||
TEST_CASE("doctest::send_warning notifies Doctest.") | ||
{ | ||
mimicpp::detail::doctest::send_warning("Warning"); | ||
|
||
REQUIRE(g_WarningCounter == 1); | ||
} | ||
|
||
TEST_CASE( | ||
"doctest::send_fail notifies Doctest for failures and aborts." | ||
* doctest::should_fail{}) | ||
{ | ||
mimicpp::detail::doctest::send_fail("Fail"); | ||
} | ||
} |