GCC Code Coverage Report


Directory: ./
File: src/iguana/tests/include/TestLogger.h
Date: 2025-06-06 22:09:53
Exec Total Coverage
Lines: 21 22 95.5%
Functions: 1 1 100.0%
Branches: 21 40 52.5%

Line Branch Exec Source
1 // test configuration
2
3 #include <iguana/services/Logger.h>
4
5
1/2
✓ Branch 0 (2→3) taken 1 times.
✗ Branch 1 (2→41) 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
1/2
✓ Branch 0 (2→3) taken 1 times.
✗ Branch 1 (2→41) not taken.
2 logs.push_back({"styled_logger", iguana::Logger::Level::trace});
10
1/2
✓ Branch 0 (5→6) taken 1 times.
✗ Branch 1 (5→41) not taken.
2 logs.push_back({"unstyled_logger", iguana::Logger::Level::trace});
11
12 // set styles
13
2/4
✓ Branch 0 (8→9) taken 1 times.
✗ Branch 1 (8→41) not taken.
✓ Branch 2 (9→10) taken 1 times.
✗ Branch 3 (9→41) not taken.
1 logs.at(0).EnableStyle();
14
2/4
✓ Branch 0 (10→11) taken 1 times.
✗ Branch 1 (10→41) not taken.
✓ Branch 2 (11→12) taken 1 times.
✗ Branch 3 (11→41) 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 (12→13) taken 1 times.
✗ Branch 1 (12→41) not taken.
✓ Branch 2 (13→14) taken 1 times.
✗ Branch 3 (13→41) not taken.
1 logs.at(0).SetLevel("non_existent_level");
20
21
2/2
✓ Branch 0 (27→15) taken 2 times.
✓ Branch 1 (27→28) taken 1 times.
3 for(auto& log : logs) {
22 // test all log levels
23
1/2
✓ Branch 0 (16→17) taken 2 times.
✗ Branch 1 (16→41) not taken.
2 log.Trace("trace is level {}", static_cast<int>(iguana::Logger::Level::trace));
24
1/2
✓ Branch 0 (17→18) taken 2 times.
✗ Branch 1 (17→41) not taken.
2 log.Debug("debug is level {}", static_cast<int>(iguana::Logger::Level::debug));
25
1/2
✓ Branch 0 (18→19) taken 2 times.
✗ Branch 1 (18→41) not taken.
2 log.Info("info is level {}", static_cast<int>(iguana::Logger::Level::info));
26
1/2
✓ Branch 0 (19→20) taken 2 times.
✗ Branch 1 (19→41) not taken.
2 log.Warn("warn is level {}", static_cast<int>(iguana::Logger::Level::warn));
27 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 (20→21) taken 2 times.
✗ Branch 1 (20→41) not taken.
✓ Branch 2 (21→22) taken 2 times.
✗ Branch 3 (21→41) not taken.
2 log.SetLevel("silent");
32 2 log.Error("if this prints, 'silent' level failed");
33
2/4
✓ Branch 0 (22→23) taken 2 times.
✗ Branch 1 (22→41) not taken.
✓ Branch 2 (23→24) taken 2 times.
✗ Branch 3 (23→41) not taken.
2 log.SetLevel("trace");
34 // test run-time errors from `fmt`
35
1/2
✗ Branch 0 (24→25) not taken.
✓ Branch 1 (24→34) 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 (34→35) not taken.
✓ Branch 1 (34→36) 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