Iguana
1.1.0
Implementation Guardian of Analysis Algorithms
Toggle main menu visibility
Loading...
Searching...
No Matches
TestLogger.h
1
// test configuration
2
3
#include <iguana/services/Logger.h>
4
5
inline
int
TestLogger()
6
{
7
// this test just runs the `Logger` methods to catch any runtime errors
8
std::vector<iguana::Logger> logs;
9
logs.push_back({
"styled_logger"
, iguana::Logger::Level::trace});
10
logs.push_back({
"unstyled_logger"
, iguana::Logger::Level::trace});
11
12
// set styles
13
logs.at(0).EnableStyle();
14
logs.at(1).DisableStyle();
15
16
// set non-existent level; should print errors
17
// auto non_existent_level = static_cast<iguana::Logger::Level>(1000); // unused, since UndefinedBehaviorSanitizer catches any usage of this
18
// logs.at(0).SetLevel(non_existent_level); // UndefinedBehaviorSanitizer catches this
19
logs.at(0).SetLevel(
"non_existent_level"
);
20
21
for
(
auto
& log : logs) {
22
// test all log levels
23
log.Trace(
"trace is level {}"
,
static_cast<
int
>
(iguana::Logger::Level::trace));
24
log.Debug(
"debug is level {}"
,
static_cast<
int
>
(iguana::Logger::Level::debug));
25
log.Info(
"info is level {}"
,
static_cast<
int
>
(iguana::Logger::Level::info));
26
log.Warn(
"warn is level {}"
,
static_cast<
int
>
(iguana::Logger::Level::warn));
27
log.Error(
"error is level {}"
,
static_cast<
int
>
(iguana::Logger::Level::error));
28
// test non-existent level
29
// log.Print(non_existent_level, "print to non-existent log level {}", static_cast<int>(non_existent_level)); // UndefinedBehaviorSanitizer catches this
30
// test silence
31
log.SetLevel(
"silent"
);
32
log.Error(
"if this prints, 'silent' level failed"
);
33
log.SetLevel(
"trace"
);
34
// test run-time errors from `fmt`
35
log.Info(
"too many arguments: {}"
, 1, 2);
// noexcept
36
try
{
37
log.Info(
"too few arguments: {} {}"
, 1);
38
}
39
catch
(std::exception
const
& ex) {
40
log.Info(
"too few arguments test threw expected exception"
);
41
}
42
}
43
44
return
0;
45
}
iguana_v1.1.0
src
iguana
tests
include
TestLogger.h
Generated by
1.18.0