File: assertions.cpp

package info (click to toggle)
gsmartcontrol 2.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,904 kB
  • sloc: cpp: 66,205; sh: 240; ansic: 125; xml: 33; makefile: 13
file content (18 lines) | stat: -rw-r--r-- 543 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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");
}