onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 1 | #pragma once |
| 2 | |
ncihnegn | c5458f2 | 2019-01-28 05:08:18 -0800 | [diff] [blame] | 3 | #include <doctest/doctest.h> |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 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 | |
onqtam | be46017 | 2018-05-30 18:15:58 +0300 | [diff] [blame] | 31 | TEST_CASE_TEMPLATE("template 1", T, char) { |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 32 | FAIL(""); |
| 33 | } |
| 34 | |
| 35 | TEST_CASE_TEMPLATE_DEFINE("template 2", T, header_test) { |
| 36 | FAIL(""); |
| 37 | } |
| 38 | |
onqtam | 88911e3 | 2019-03-20 21:00:05 +0200 | [diff] [blame] | 39 | TEST_CASE_TEMPLATE_INVOKE(header_test, doctest::String); |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 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 | |
| 49 | struct SomeFixture |
| 50 | { |
| 51 | int data; |
onqtam | 15ce266 | 2019-03-15 18:43:17 +0200 | [diff] [blame] | 52 | SomeFixture() noexcept |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 53 | : data(42) { |
| 54 | // setup here |
| 55 | } |
| 56 | |
| 57 | ~SomeFixture() { |
| 58 | // teardown here |
| 59 | } |
| 60 | }; |
| 61 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 62 | TEST_CASE_FIXTURE(SomeFixture, "fixtured test") { |
| 63 | data /= 2; |
| 64 | CHECK(data == 21); |
| 65 | } |