blob: 1ff9ade1b231576a099d174db22cb29b7485316c [file] [log] [blame]
onqtam7cc0e962017-04-17 23:30:36 +03001#pragma once
2
ncihnegnc5458f22019-01-28 05:08:18 -08003#include <doctest/doctest.h>
onqtam7cc0e962017-04-17 23:30:36 +03004
5// helper for throwing exceptions
onqtam7cc0e962017-04-17 23:30:36 +03006template <typename T>
7int 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
19TEST_SUITE("some TS") {
20 TEST_CASE("in TS") {
21 FAIL("");
22 }
23}
24
25REGISTER_EXCEPTION_TRANSLATOR(int& in) {
26 return doctest::toString(in);
27}
28
29TYPE_TO_STRING(doctest::String);
30
onqtambe460172018-05-30 18:15:58 +030031TEST_CASE_TEMPLATE("template 1", T, char) {
onqtam7cc0e962017-04-17 23:30:36 +030032 FAIL("");
33}
34
35TEST_CASE_TEMPLATE_DEFINE("template 2", T, header_test) {
36 FAIL("");
37}
38
onqtambe460172018-05-30 18:15:58 +030039TEST_CASE_TEMPLATE_INSTANTIATE(header_test, doctest::String);
onqtam7cc0e962017-04-17 23:30:36 +030040
onqtam8c311762017-04-17 23:58:56 +030041// to silence GCC warnings when inheriting from some class which has no virtual destructor - happens only on gcc 4.7/4.8
onqtam50cbb802017-12-09 17:17:39 +020042#if DOCTEST_GCC >= DOCTEST_COMPILER(4, 7, 0) && DOCTEST_GCC < DOCTEST_COMPILER(4, 9, 0)
43DOCTEST_GCC_SUPPRESS_WARNING("-Weffc++")
onqtamc79b7542017-04-19 20:47:13 +030044#endif // gcc 4.7 / 4.8
onqtam50cbb802017-12-09 17:17:39 +020045#if DOCTEST_GCC >= DOCTEST_COMPILER(5, 0, 0) && DOCTEST_GCC < DOCTEST_COMPILER(6, 0, 0)
46DOCTEST_GCC_SUPPRESS_WARNING("-Wstrict-overflow")
onqtamc79b7542017-04-19 20:47:13 +030047#endif // gcc 5
onqtam7cc0e962017-04-17 23:30:36 +030048
onqtam2d160732018-05-21 22:18:05 +030049DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(26439) // This kind of function may not throw. Declare it 'noexcept'
50
onqtam7cc0e962017-04-17 23:30:36 +030051struct SomeFixture
52{
53 int data;
54 SomeFixture()
55 : data(42) {
56 // setup here
57 }
58
59 ~SomeFixture() {
60 // teardown here
61 }
62};
63
onqtam2d160732018-05-21 22:18:05 +030064DOCTEST_MSVC_SUPPRESS_WARNING_POP
65
onqtam7cc0e962017-04-17 23:30:36 +030066TEST_CASE_FIXTURE(SomeFixture, "fixtured test") {
67 data /= 2;
68 CHECK(data == 21);
69}