GCC Code Coverage Report


Directory: .
File: main.cpp
Date: 0000-00-00 00:00:00
Exec Total Coverage
Lines: 39 42 92.9%
Functions: 11 11 100.0%
Branches: 19 28 67.9%

Line Branch Exec Source
1 #include <iostream>
2
3 #if defined USE_LAMBDA
4 # include <algorithm>
5 # include <array>
6 # include <functional>
7 #endif
8
9 1 int /* GCOVR_EXCL_FUNCTION */ foo(int param) { // GCOVR_EXCL_FUNCTION
10
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (param) {
11 param++;
12 } else {
13 1 param--;
14 }
15
16 1 return param;
17 }
18
19 1 int bar(int param) { // Excluded by CLI option
20
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (param) {
21 param++;
22 } else {
23 1 param--;
24 }
25 1 return param;
26 }
27
28 #if defined USE_LAMBDA
29 #define LAMBDA_SORT /
30 { /
31 std::array<int, 10> arr = { 0, 9, 1, 8, 2, 7, 3, 6, 4, 5 }; /
32 std::sort( /
33 std::begin(arr), /
34 std::end(arr), /
35 [](int a, int b) { /
36 if (a > b) /
37 return true; /
38 return false; /
39 } /
40 ); /
41 }
42
43 // Function in line with exclude
44
3/4
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
84 void sort_excluded(void) /* GCOVR_EXCL_FUNCTION */ { LAMBDA_SORT /* THIS is not excluded*/
45
3/4
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
43 LAMBDA_SORT
46 2 }
47
48 1 void sort_lambda_excluded(void)
49 {
50
3/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✓ Branch 3 taken 16 times.
42 LAMBDA_SORT // GCOVR_EXCL_FUNCTION not working because after function definition
51
52 1 std::array<int, 10> arr = { 0, 9, 1, 8, 2, 7, 3, 6, 4, 5 };
53
54
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::sort(
55 std::begin(arr),
56 std::end(arr),
57 41 [](int a, int b) { // GCOVR_EXCL_FUNCTION
58
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 16 times.
41 if (a > b)
59 25 return true;
60
61 16 return false;
62 }
63 );
64 1 }
65
66 1 void sort_excluded_both(void) // GCOVR_EXCL_FUNCTION
67 {
68 1 std::array<int, 10> arr = { 0, 9, 1, 8, 2, 7, 3, 6, 4, 5 };
69
70
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::sort(
71 std::begin(arr),
72 std::end(arr),
73 41 [](int a, int b) { // GCOVR_EXCL_FUNCTION
74
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 16 times.
41 if (a > b)
75 25 return true;
76
77 16 return false;
78 }
79 );
80
81
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::sort(
82 std::begin(arr),
83 std::end(arr),
84 18 [](int a, int b) { // Excluded by CLI option
85
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (a > b)
86 return true;
87
88 18 return false;
89 }
90 );
91 1 }
92 #endif
93
94
95 1 int main(int argc, char* argv[]) {
96 1 foo(0);
97 1 bar(0);
98 #if defined USE_LAMBDA
99 1 sort_excluded();
100 1 sort_lambda_excluded();
101 1 sort_excluded_both();
102 #endif
103 1 return 0;
104 }
105