-
Notifications
You must be signed in to change notification settings - Fork 120
/
log.cpp
43 lines (38 loc) · 1.09 KB
/
log.cpp
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
//
// 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>
#ifdef __cpp_lib_expected
#include <expected>
#include <string>
#endif
int main() {
using namespace boost::ut;
"log"_test = [] {
boost::ut::log << "pre:" << 42;
expect(42_i == 42) << "message on failure";
boost::ut::log << "post";
};
#if defined(__cpp_lib_expected)
"lazy log"_test = [] {
// It's not possible to write a test like:
// expect(e.has_value()) << e.error() << fatal;
// This would evaluate e.error() when there is no error, instead lazy
// evaluation is needed.
std::expected<bool, std::string> e = true;
expect(e.has_value()) << [&] { return e.error(); } << fatal;
expect(e.value() == true);
};
#endif
#if defined(BOOST_UT_HAS_FORMAT)
"log format"_test = [] {
boost::ut::log("\npre: {}\n", 42);
expect(42_i == 42) << "message on failure";
boost::ut::log("\npost\n");
};
#endif
}