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