onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame^] | 1 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN |
| 2 | #include "doctest.h" |
| 3 | |
| 4 | static int throws(bool in) { |
| 5 | if(in) |
| 6 | throw 5; |
| 7 | return 42; |
| 8 | } |
| 9 | |
| 10 | using doctest::Approx; |
| 11 | |
| 12 | TEST_SUITE("meaningless macros"); |
| 13 | |
| 14 | TEST_CASE("an empty test that will succeed") {} |
| 15 | |
| 16 | TEST_CASE("an empty test that will fail because of an exception") { throws(true); } |
| 17 | |
| 18 | TEST_SUITE_END(); |
| 19 | |
| 20 | TEST_CASE("normal macros") { |
| 21 | int a = 5; |
| 22 | int b = 5; |
| 23 | |
| 24 | CHECK(throws(true) == 42); |
| 25 | |
| 26 | CHECK_FALSE(!(a == b)); |
| 27 | |
| 28 | REQUIRE(a == b); |
| 29 | //WARN(reinterpret_cast<void*>(1000) == reinterpret_cast<void*>(1004)); |
| 30 | |
| 31 | CHECK(Approx(0.1000001) == 0.1000002); |
| 32 | CHECK(Approx(0.502) == 0.501); |
| 33 | |
| 34 | const char* c_string = "test_test"; |
| 35 | |
| 36 | CHECK(c_string == "test_test"); |
| 37 | |
| 38 | throws(true); |
| 39 | } |
| 40 | |
| 41 | TEST_CASE("exceptions-related macros") { |
| 42 | CHECK_THROWS(throws(false)); |
| 43 | CHECK_THROWS_AS(throws(false), int); |
| 44 | CHECK_THROWS_AS(throws(true), int); |
| 45 | CHECK_THROWS_AS(throws(true), char); |
| 46 | |
| 47 | REQUIRE_NOTHROW(throws(true)); |
| 48 | } |