blob: 63b50eb5ed4d6ea57a020c54838f761262190bef [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
onqtam88911e32019-03-20 21:00:05 +020039TEST_CASE_TEMPLATE_INVOKE(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
49struct SomeFixture
50{
51 int data;
onqtam15ce2662019-03-15 18:43:17 +020052 SomeFixture() noexcept
onqtam7cc0e962017-04-17 23:30:36 +030053 : data(42) {
54 // setup here
55 }
56
57 ~SomeFixture() {
58 // teardown here
59 }
60};
61
onqtam7cc0e962017-04-17 23:30:36 +030062TEST_CASE_FIXTURE(SomeFixture, "fixtured test") {
63 data /= 2;
64 CHECK(data == 21);
65}