onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "doctest.h" |
| 4 | |
| 5 | // helper for throwing exceptions |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 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; |
| 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 | TYPE_TO_STRING(doctest::String); |
| 30 | |
| 31 | TEST_CASE_TEMPLATE("template 1", T, doctest::Types<char>) { |
| 32 | FAIL(""); |
| 33 | } |
| 34 | |
| 35 | TEST_CASE_TEMPLATE_DEFINE("template 2", T, header_test) { |
| 36 | FAIL(""); |
| 37 | } |
| 38 | |
| 39 | TEST_CASE_TEMPLATE_INSTANTIATE(header_test, doctest::Types<doctest::String>); |
| 40 | |
onqtam | 8c31176 | 2017-04-17 23:58:56 +0300 | [diff] [blame] | 41 | // to silence GCC warnings when inheriting from some class which has no virtual destructor - happens only on gcc 4.7/4.8 |
onqtam | 50cbb80 | 2017-12-09 17:17:39 +0200 | [diff] [blame] | 42 | #if DOCTEST_GCC >= DOCTEST_COMPILER(4, 7, 0) && DOCTEST_GCC < DOCTEST_COMPILER(4, 9, 0) |
| 43 | DOCTEST_GCC_SUPPRESS_WARNING("-Weffc++") |
onqtam | c79b754 | 2017-04-19 20:47:13 +0300 | [diff] [blame] | 44 | #endif // gcc 4.7 / 4.8 |
onqtam | 50cbb80 | 2017-12-09 17:17:39 +0200 | [diff] [blame] | 45 | #if DOCTEST_GCC >= DOCTEST_COMPILER(5, 0, 0) && DOCTEST_GCC < DOCTEST_COMPILER(6, 0, 0) |
| 46 | DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-overflow") |
onqtam | c79b754 | 2017-04-19 20:47:13 +0300 | [diff] [blame] | 47 | #endif // gcc 5 |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 48 | |
onqtam | 2d16073 | 2018-05-21 22:18:05 +0300 | [diff] [blame] | 49 | DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(26439) // This kind of function may not throw. Declare it 'noexcept' |
| 50 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 51 | struct SomeFixture |
| 52 | { |
| 53 | int data; |
| 54 | SomeFixture() |
| 55 | : data(42) { |
| 56 | // setup here |
| 57 | } |
| 58 | |
| 59 | ~SomeFixture() { |
| 60 | // teardown here |
| 61 | } |
| 62 | }; |
| 63 | |
onqtam | 2d16073 | 2018-05-21 22:18:05 +0300 | [diff] [blame] | 64 | DOCTEST_MSVC_SUPPRESS_WARNING_POP |
| 65 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 66 | TEST_CASE_FIXTURE(SomeFixture, "fixtured test") { |
| 67 | data /= 2; |
| 68 | CHECK(data == 21); |
| 69 | } |