onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 1 | #include "doctest.h" |
| 2 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 3 | #include "header.h" |
| 4 | |
onqtam | 12d5598 | 2017-04-16 22:35:27 +0300 | [diff] [blame] | 5 | #include <stdexcept> |
| 6 | |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 7 | TEST_CASE("normal macros") { |
| 8 | int a = 5; |
| 9 | int b = 5; |
| 10 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 11 | CHECK(throw_if(true, std::runtime_error("whops!")) == 42); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 12 | |
| 13 | CHECK_FALSE(!(a == b)); |
| 14 | |
| 15 | REQUIRE(a == b); |
onqtam | cc6a6d6 | 2016-09-19 17:30:15 +0300 | [diff] [blame] | 16 | |
| 17 | CHECK_EQ(a, b); |
| 18 | |
| 19 | FAST_CHECK_EQ(a, b); |
| 20 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 21 | CHECK(doctest::Approx(0.1000001) == 0.1000002); |
| 22 | CHECK(doctest::Approx(0.502) == 0.501); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 23 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 24 | throw_if(true, 0); |
Elias Kosunen | 3de57e3 | 2016-12-20 18:57:03 +0200 | [diff] [blame] | 25 | } |
| 26 | |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 27 | TEST_CASE("exceptions-related macros") { |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 28 | CHECK_THROWS(throw_if(false, 0)); |
| 29 | CHECK_THROWS_AS(throw_if(false, 0), int); |
| 30 | CHECK_THROWS_AS(throw_if(true, 0), int); |
| 31 | CHECK_THROWS_AS(throw_if(true, 0), char); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 32 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 33 | CHECK_NOTHROW(throw_if(true, 0)); |
Elias Kosunen | 3de57e3 | 2016-12-20 18:57:03 +0200 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | TEST_CASE("exceptions-related macros for std::exception") { |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 37 | CHECK_THROWS(throw_if(false, 0)); |
| 38 | CHECK_THROWS_AS(throw_if(false, std::runtime_error("whops!")), std::exception&); |
| 39 | CHECK_THROWS_AS(throw_if(true, std::runtime_error("whops!")), std::exception&); |
| 40 | CHECK_THROWS_AS(throw_if(true, std::runtime_error("whops!")), int); |
Elias Kosunen | 3de57e3 | 2016-12-20 18:57:03 +0200 | [diff] [blame] | 41 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 42 | REQUIRE_NOTHROW(throw_if(true, std::runtime_error("whops!"))); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 43 | } |