Line | Branch | Exec | Source |
---|---|---|---|
1 | // test configuration | ||
2 | |||
3 | #include <iguana/services/Logger.h> | ||
4 | |||
5 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | inline int TestLogger() |
6 | { | ||
7 | // this test just runs the `Logger` methods to catch any runtime errors | ||
8 | std::vector<iguana::Logger> logs; | ||
9 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | logs.push_back({"styled_logger", iguana::Logger::Level::trace}); |
10 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | logs.push_back({"unstyled_logger", iguana::Logger::Level::trace}); |
11 | |||
12 | // set styles | ||
13 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | logs.at(0).EnableStyle(); |
14 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | 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 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | logs.at(0).SetLevel("non_existent_level"); |
20 | |||
21 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for(auto& log : logs) { |
22 | // test all log levels | ||
23 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | log.Trace("trace is level {}", static_cast<int>(iguana::Logger::Level::trace)); |
24 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | log.Debug("debug is level {}", static_cast<int>(iguana::Logger::Level::debug)); |
25 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | log.Info("info is level {}", static_cast<int>(iguana::Logger::Level::info)); |
26 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | log.Warn("warn is level {}", static_cast<int>(iguana::Logger::Level::warn)); |
27 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | 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 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | log.SetLevel("silent"); |
32 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | log.Error("if this prints, 'silent' level failed"); |
33 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | log.SetLevel("trace"); |
34 | // test run-time errors from `fmt` | ||
35 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | log.Info("too many arguments: {}", 1, 2); // noexcept |
36 | try { | ||
37 | ✗ | log.Info("too few arguments: {} {}", 1); | |
38 | } | ||
39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | catch(std::exception const& ex) { |
40 | 2 | log.Info("too few arguments test threw expected exception"); | |
41 | 2 | } | |
42 | } | ||
43 | |||
44 | 1 | return 0; | |
45 | 1 | } | |
46 |