Skip to content

Commit

Permalink
Add tests for assertions.
Browse files Browse the repository at this point in the history
Signed-off-by: Daira Hopwood <[email protected]>
  • Loading branch information
daira committed Dec 8, 2022
1 parent 3e109c9 commit 19e3dba
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/assertions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <catch2/catch.hpp>
#include <stdexcept>

#define TL_ASSERT(cond) if (!(cond)) { throw std::runtime_error(std::string("assertion failure")); }

#include <tl/expected.hpp>

TEST_CASE("Assertions", "[assertions]") {
tl::expected<int,int> o1 = 42;
REQUIRE_THROWS_WITH(o1.error(), "assertion failure");

tl::expected<int,int> o2 {tl::unexpect, 0};
REQUIRE_THROWS_WITH(*o2, "assertion failure");

struct foo { int bar; };
tl::expected<struct foo,int> o3 {tl::unexpect, 0};
REQUIRE_THROWS_WITH(o3->bar, "assertion failure");
}

0 comments on commit 19e3dba

Please sign in to comment.