blob: 9c25bcba1f485e9a9f36da92cc20cde86eadebad [file] [log] [blame]
onqtam4a655632016-05-26 14:20:52 +03001#define DOCTEST_CONFIG_DISABLE
2
3#include "doctest.h"
4
5#ifdef _MSC_VER
6#pragma warning(disable : 4505) // unreferenced local functions being removed
7#endif // _MSC_VER
8
9#ifdef __clang__
10#pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
11#endif // __clang__
12
13using doctest::Approx;
14
15static int throws(bool in) {
16 if(in)
onqtam4b68df32017-03-17 20:45:54 +020017#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
onqtam4a655632016-05-26 14:20:52 +030018 throw "whops!";
onqtam4b68df32017-03-17 20:45:54 +020019#else // DOCTEST_CONFIG_NO_EXCEPTIONS
20 return 0;
21#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
onqtam4a655632016-05-26 14:20:52 +030022 return 42;
23}
24
onqtam658c8702017-03-14 14:08:22 +020025TEST_SUITE_BEGIN("the testsuite!");
onqtam4a655632016-05-26 14:20:52 +030026
27#define DO_STUFF() \
28 CHECK(1 == 0); \
29 CHECK_FALSE(1 == 0); \
30 CHECK(Approx(0.502) == 0.501); \
31 CHECK(1 == 1); \
32 REQUIRE(1 == 1); \
33 CHECK_FALSE(0); \
34 REQUIRE_FALSE(0); \
onqtamcc9e8652016-08-02 14:23:38 +030035 CHECK_THROWS(throws(true)); \
36 REQUIRE_THROWS(throws(true)); \
37 CHECK_THROWS_AS(throws(true), int); \
38 REQUIRE_THROWS_AS(throws(true), char); \
39 CHECK_NOTHROW(throws(false)); \
40 REQUIRE_NOTHROW(throws(false)); \
onqtam4a655632016-05-26 14:20:52 +030041 SUBCASE("") {}
42
43// in a separate function because the TEST_CASE() macro will expand to an uninstantiated template
44// and we want to ensure this code is parsed (MSVC will not if it is in an uninstantiated template)
45static void f() { DO_STUFF(); }
46
47TEST_CASE("ops") {
48 f();
49
50 throws(false);
51
52 DO_STUFF();
53}
54
55TEST_SUITE_END();
56
57// to silence GCC warnings when inheriting from the class TheFixture which has no virtual destructor
58#if defined(__GNUC__) && !defined(__clang__)
59#pragma GCC diagnostic ignored "-Weffc++"
60#endif // __GNUC__
61
62struct TheFixture
63{
64 int data;
65 TheFixture()
66 : data(42) {
67 // setup here
68 }
69
70 ~TheFixture() {
71 // teardown here
72 }
73};
74
onqtam658c8702017-03-14 14:08:22 +020075TEST_SUITE("the testsuite!") {
76 TEST_CASE_FIXTURE(TheFixture, "test with a fixture - 1") {
77 data /= 2;
78 CHECK(data == 21);
79 }
onqtam4a655632016-05-26 14:20:52 +030080}