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 |
| 6 | |
| 7 | template <typename T> |
| 8 | int throw_if(bool in, const T& ex) { |
| 9 | if(in) |
| 10 | #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS |
| 11 | throw ex; |
| 12 | #else // DOCTEST_CONFIG_NO_EXCEPTIONS |
| 13 | ((void)ex); |
| 14 | #endif // DOCTEST_CONFIG_NO_EXCEPTIONS |
| 15 | return 42; |
| 16 | } |
| 17 | |
| 18 | // stuff that should be fine when used in a header - test cases for example should be registered only once |
| 19 | |
| 20 | TEST_SUITE("some TS") { |
| 21 | TEST_CASE("in TS") { |
| 22 | FAIL(""); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | REGISTER_EXCEPTION_TRANSLATOR(int& in) { |
| 27 | return doctest::toString(in); |
| 28 | } |
| 29 | |
| 30 | TYPE_TO_STRING(doctest::String); |
| 31 | |
| 32 | TEST_CASE_TEMPLATE("template 1", T, doctest::Types<char>) { |
| 33 | FAIL(""); |
| 34 | } |
| 35 | |
| 36 | TEST_CASE_TEMPLATE_DEFINE("template 2", T, header_test) { |
| 37 | FAIL(""); |
| 38 | } |
| 39 | |
| 40 | TEST_CASE_TEMPLATE_INSTANTIATE(header_test, doctest::Types<doctest::String>); |
| 41 | |
onqtam | 8c31176 | 2017-04-17 23:58:56 +0300 | [diff] [blame] | 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 defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ > 6 && __GNUC_MINOR__ < 9 |
| 44 | #pragma GCC diagnostic ignored "-Weffc++" |
| 45 | #endif // __GNUC__ |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 46 | |
| 47 | struct SomeFixture |
| 48 | { |
| 49 | int data; |
| 50 | SomeFixture() |
| 51 | : data(42) { |
| 52 | // setup here |
| 53 | } |
| 54 | |
| 55 | ~SomeFixture() { |
| 56 | // teardown here |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | TEST_CASE_FIXTURE(SomeFixture, "fixtured test") { |
| 61 | data /= 2; |
| 62 | CHECK(data == 21); |
| 63 | } |