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