ein
0.0.1
一呼百應, "one call, a hundred responses"
Loading...
Searching...
No Matches
assert.hpp
Go to the documentation of this file.
1
#pragma once
2
27
#include <spdlog/spdlog.h>
28
#include <spdlog/fmt/bundled/core.h>
29
30
#define ein_assert(cond,...) \
31
do { \
32
if (!cond) [[unlikely]] { \
33
[]<typename ... Args> (Args && ... args) noexcept { \
34
if constexpr (sizeof...(Args) == 0) \
35
spdlog::error( \
36
"{}:{}: assertion failed ({}) in function {}", \
37
__FILE__,__LINE__,#cond,__PRETTY_FUNCTION__); \
38
else if constexpr (sizeof...(Args) == 1) \
39
spdlog::error( \
40
"{}:{}: assertion failed ({}) in function {}: {}", \
41
__FILE__,__LINE__,#cond,__PRETTY_FUNCTION__, \
42
fmt::format(std::forward<Args>(args)...)); \
43
else \
44
spdlog::error( \
45
"{}:{}: assertion failed ({}) in function {}: {}", \
46
__FILE__,__LINE__,#cond,__PRETTY_FUNCTION__, \
47
fmt::format(std::forward<Args>(args)...)); \
48
std::abort(); \
49
}(__VA_ARGS__); \
50
} \
51
} while (0)
52
53
54
#if defined(EIN_TESTING) || defined(EIN_TESTING_WAIT)
55
#include <unistd.h>
// fork
56
//#include <sys/wait.h> // wait
57
58
TEST_CASE(
"assert"
,
"[assert]"
) {
59
ein_assert
(
true
);
60
// REQUIRE_EXIT(ein_assert(false));
61
}
62
63
// TEST_CASE("ein_assert(false) should exit","[assert]") {
64
// if (fork() == 0) {
65
// ein_assert(false,"this should exit");
66
// _exit(0);
67
// }
68
// else {
69
// int status=0;
70
// ::wait(&status);
71
// REQUIRE(WIFEXITED(status));
72
// REQUIRE(WEXITSTATUS(status) == 1);
73
// }
74
// }
75
76
#endif
ein_assert
#define ein_assert(cond,...)
An assert with spdlog message formatting and logging.
Definition
assert.hpp:30
src
ein
assert.hpp
© 2024 Edward Kmett. All rights reserved.