File: fatal.cpp

package info (click to toggle)
boost-ext-ut 2.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 620 kB
  • sloc: cpp: 6,773; makefile: 13; sh: 10
file content (58 lines) | stat: -rw-r--r-- 1,442 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// Copyright (c) 2019-2020 Kris Jusiak (kris at jusiak dot net)
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/ut.hpp>
#include <optional>
#include <vector>

int main() {
  using boost::ut::operator""_test;
  using namespace boost::ut::literals;
  using boost::ut::fatal;

  "fatal"_test = [] {
    using namespace boost::ut::operators;
    using boost::ut::expect;

    std::optional<int> o{42};
    expect(fatal(o.has_value())) << "fatal assertion";
    expect(*o == 42_i);
  };

  "fatal logging"_test = [] {
    using namespace boost::ut::operators;
    using boost::ut::expect;

    std::optional<int> o{42};
    expect(fatal(o.has_value())) << "fatal assertion";
    expect(*o == 42_i);
  };

  "fatal matcher"_test = [] {
    using namespace boost::ut::operators;
    using boost::ut::expect;
    using boost::ut::that;

    std::optional<int> o{42};
    expect(fatal(that % o.has_value()) and that % *o == 42)
        << "fatal assertion";
  };

  "fatal terse"_test = [] {
    using namespace boost::ut::operators::terse;

    std::optional<int> o{42};
    (o.has_value() >> fatal and *o == 42_i) << "fatal assertion";
  };

  using namespace boost::ut::operators;
  using boost::ut::expect;

  std::vector v{1u};
  expect(fatal(std::size(v) == 1_ul)) << "fatal assertion";
  expect(v[0] == 1_u);
}