assertions.cpp 543 B

123456789101112131415161718
  1. #include <catch2/catch.hpp>
  2. #include <stdexcept>
  3. #define TL_ASSERT(cond) if (!(cond)) { throw std::runtime_error(std::string("assertion failure")); }
  4. #include <tl/expected.hpp>
  5. TEST_CASE("Assertions", "[assertions]") {
  6. tl::expected<int,int> o1 = 42;
  7. REQUIRE_THROWS_WITH(o1.error(), "assertion failure");
  8. tl::expected<int,int> o2 {tl::unexpect, 0};
  9. REQUIRE_THROWS_WITH(*o2, "assertion failure");
  10. struct foo { int bar; };
  11. tl::expected<struct foo,int> o3 {tl::unexpect, 0};
  12. REQUIRE_THROWS_WITH(o3->bar, "assertion failure");
  13. }