blob: fb125045e759d6c15f704955db8c8967f615f53d [file] [log] [blame]
onqtam4a655632016-05-26 14:20:52 +03001#include "doctest.h"
2
onqtam7cc0e962017-04-17 23:30:36 +03003#include "header.h"
4
onqtam12d55982017-04-16 22:35:27 +03005#include <stdexcept>
6
onqtam4a655632016-05-26 14:20:52 +03007TEST_CASE("normal macros") {
8 int a = 5;
9 int b = 5;
10
onqtam7cc0e962017-04-17 23:30:36 +030011 CHECK(throw_if(true, std::runtime_error("whops!")) == 42);
onqtam4a655632016-05-26 14:20:52 +030012
13 CHECK_FALSE(!(a == b));
14
15 REQUIRE(a == b);
onqtamcc6a6d62016-09-19 17:30:15 +030016
17 CHECK_EQ(a, b);
18
19 FAST_CHECK_EQ(a, b);
20
onqtam7cc0e962017-04-17 23:30:36 +030021 CHECK(doctest::Approx(0.1000001) == 0.1000002);
22 CHECK(doctest::Approx(0.502) == 0.501);
onqtam4a655632016-05-26 14:20:52 +030023
onqtam7cc0e962017-04-17 23:30:36 +030024 throw_if(true, 0);
Elias Kosunen3de57e32016-12-20 18:57:03 +020025}
26
onqtam4a655632016-05-26 14:20:52 +030027TEST_CASE("exceptions-related macros") {
onqtam7cc0e962017-04-17 23:30:36 +030028 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);
onqtam4a655632016-05-26 14:20:52 +030032
onqtam7cc0e962017-04-17 23:30:36 +030033 CHECK_NOTHROW(throw_if(true, 0));
Elias Kosunen3de57e32016-12-20 18:57:03 +020034}
35
36TEST_CASE("exceptions-related macros for std::exception") {
onqtam7cc0e962017-04-17 23:30:36 +030037 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 Kosunen3de57e32016-12-20 18:57:03 +020041
onqtam7cc0e962017-04-17 23:30:36 +030042 REQUIRE_NOTHROW(throw_if(true, std::runtime_error("whops!")));
onqtam4a655632016-05-26 14:20:52 +030043}