header.h (1563B)
1 #pragma once 2 3 #include <doctest/doctest.h> 4 5 // helper for throwing exceptions 6 template <typename T> 7 int throw_if(bool in, const T& ex) { 8 if(in) 9 #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS 10 throw ex; // NOLINT 11 #else // DOCTEST_CONFIG_NO_EXCEPTIONS 12 ((void)ex); 13 #endif // DOCTEST_CONFIG_NO_EXCEPTIONS 14 return 42; 15 } 16 17 // stuff that should be fine when used in a header - test cases for example should be registered only once 18 19 TEST_SUITE("some TS") { 20 TEST_CASE("in TS") { 21 FAIL(""); 22 } 23 } 24 25 REGISTER_EXCEPTION_TRANSLATOR(int& in) { 26 return doctest::toString(in); 27 } 28 29 // Removes class on MSVC 30 TYPE_TO_STRING(doctest::String); 31 32 TEST_CASE_TEMPLATE("template 1", T, char) { 33 FAIL(""); 34 } 35 36 TEST_CASE_TEMPLATE_DEFINE("template 2", T, header_test) { 37 FAIL(""); 38 } 39 40 TEST_CASE_TEMPLATE_INVOKE(header_test, doctest::String); 41 42 // to silence GCC warnings when inheriting from some class which has no virtual destructor - happens only on gcc 4.7/4.8 43 #if DOCTEST_GCC >= DOCTEST_COMPILER(4, 7, 0) && DOCTEST_GCC < DOCTEST_COMPILER(4, 9, 0) 44 DOCTEST_GCC_SUPPRESS_WARNING("-Weffc++") 45 #endif // gcc 4.7 / 4.8 46 #if DOCTEST_GCC >= DOCTEST_COMPILER(5, 0, 0) && DOCTEST_GCC < DOCTEST_COMPILER(6, 0, 0) 47 DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-overflow") 48 #endif // gcc 5 49 50 // NOLINTBEGIN 51 struct SomeFixture 52 { 53 int data; 54 SomeFixture() noexcept 55 : data(42) { 56 // setup here 57 } 58 59 ~SomeFixture() { 60 // teardown here 61 } 62 }; 63 // NOLINTEND 64 65 TEST_CASE_FIXTURE(SomeFixture, "fixtured test") { 66 data /= 2; 67 CHECK(data == 21); 68 }