GCC Code Coverage Report


Directory: src/
File: cpp_shared/testing.hpp
Date: 2024-12-30 15:39:09
Exec Total Coverage
Lines: 14 14 100.0%
Functions: 2 2 100.0%
Branches: 18 32 56.2%

Line Branch Exec Source
1 #ifndef CPP_TESTING
2 #define CPP_TESTING
3
4 #include "result.hpp"
5 #include <functional>
6 #include <iostream>
7
8 namespace cpp
9 {
10 namespace testing
11 {
12 7 bool run_test(const char* test,
13 const std::function<cpp::result::result_void()>& func)
14 {
15
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 const auto res = func();
16
17
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 2 times.
7 if (res.valid())
18 {
19
3/6
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
5 std::cout << "Test Case: \"" << test << "\" run successfully.\n";
20 }
21 else
22 {
23
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
2 std::cout << "Test Case: \"" << test << "\" found an error: ";
24
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
2 std::cout << res.err_msg() << "\n";
25 2 return false;
26 }
27
28 5 return true;
29 7 }
30
31 inline cpp::result::result_void
32 4 check(const char* check, bool ok,
33
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
6 const std::source_location& location = std::source_location::current())
34 {
35
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (ok)
36 2 return cpp::result::SUCCESS;
37
38
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 return cpp::result::report_error(check, location);
39 }
40
41 #define CHECK_(MSG, ARG) if (!(ARG)) return cpp::result::report_error(MSG);
42
43 } // namespace testing
44 } // namespace cpp
45
46 #endif
47