Skip to content

Commit

Permalink
Fix decision coverage for excluded lines (#617)
Browse files Browse the repository at this point in the history
* Do not add coverage for excluded lines in decision analysis.
  • Loading branch information
Spacetown authored Aug 5, 2022
1 parent 896396d commit b5a7f9f
Show file tree
Hide file tree
Showing 38 changed files with 342 additions and 1,286 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Next Release

Known bugs:

- Decision coverage analysis can resurrect excluded coverage. (:issue:`600`)

Breaking changes:

New features and notable changes:
Expand All @@ -30,6 +28,7 @@ Bug fixes and small improvements:
- Respect excluded/noncode lines for aggregated branchcoverage. (:issue:`611`)
- Fix list options in configuration file (search-path). (:issue:`612`)
- Fix assert and key error in --decisions flag. (:issue:`642`)
- Fix adding none existing lines by decision analysis to data model. (:issue:`617`)

Documentation:

Expand Down
23 changes: 10 additions & 13 deletions gcovr/decision_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
DecisionCoverageSwitch,
FileCoverage,
)
from .merging import get_or_create_line_coverage

logger = logging.getLogger("gcovr")

Expand Down Expand Up @@ -136,10 +135,9 @@ def parse_all_lines(self):
logger.debug("Decision Analysis finished!")

def parse_one_line(self, lineno: int, code: str) -> None:
# FIXME this always creates a line, even if it doesn't exist
line_coverage = get_or_create_line_coverage(self.coverage, lineno)
line_coverage = self.coverage.lines.get(lineno)

if line_coverage.noncode:
if line_coverage is None or line_coverage.noncode:
return

# check, if a analysis for a classic if-/else if-branch is active
Expand Down Expand Up @@ -179,10 +177,11 @@ def parse_one_line(self, lineno: int, code: str) -> None:
line_coverage.decision = DecisionCoverageSwitch(line_coverage.count)
else:
# use the execution counts of the following line (compatibility with GCC 5)
# FIXME this INSERTS a line even if it doesn't already exist
line_coverage.decision = DecisionCoverageSwitch(
get_or_create_line_coverage(self.coverage, lineno + 1).count
)
line_coverage_next_line = self.coverage.lines.get(lineno + 1)
if line_coverage_next_line is not None:
line_coverage.decision = DecisionCoverageSwitch(
line_coverage_next_line.count
)

def start_multiline_decision_analysis(self, lineno: int, code: str) -> None:
# normal (non-compact) branch, analyze execution of following lines
Expand All @@ -197,11 +196,9 @@ def start_multiline_decision_analysis(self, lineno: int, code: str) -> None:
self.decision_analysis_open_brackets -= prepped_code.count(")")

def continue_multiline_decision_analysis(self, lineno: int, code: str) -> None:
# FIXME this inserts TWO lines, even if they don't already exist
exec_count = get_or_create_line_coverage(self.coverage, lineno).count
last_decision_line_cov = get_or_create_line_coverage(
self.coverage, self.last_decision_line
)
line_coverage = self.coverage.lines.get(lineno)
exec_count = 0 if line_coverage is None else line_coverage.count
last_decision_line_cov = self.coverage.lines.get(self.last_decision_line)

# check, if the branch statement was finished in the last line
if self.decision_analysis_open_brackets == 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1>GCC Code Coverage Report</h1>
</tr>
<tr>
<th scope="row">Date:</th>
<td>2022-07-30 07:20:19</td>
<td>2022-08-04 20:10:40</td>
</tr>
<tr>
<th scope="row">Legend:</th>
Expand All @@ -47,8 +47,8 @@ <h1>GCC Code Coverage Report</h1>
<tr>
<th scope="row">Lines:</th>
<td>9</td>
<td>14</td>
<td class="coverage-low">64.3%</td>
<td>9</td>
<td class="coverage-high">100.0%</td>
</tr>
<tr>
<th scope="row">Functions:</th>
Expand Down
12 changes: 6 additions & 6 deletions gcovr/tests/decisions-neg-delta/reference/clang-10/coverage.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1>GCC Code Coverage Report</h1>
</tr>
<tr>
<th scope="row">Date:</th>
<td>2022-07-30 07:20:19</td>
<td>2022-08-04 20:10:40</td>
</tr>
<tr>
<th scope="row">Legend:</th>
Expand All @@ -47,8 +47,8 @@ <h1>GCC Code Coverage Report</h1>
<tr>
<th scope="row">Lines:</th>
<td>9</td>
<td>14</td>
<td class="coverage-low">64.3%</td>
<td>9</td>
<td class="coverage-high">100.0%</td>
</tr>
<tr>
<th scope="row">Functions:</th>
Expand Down Expand Up @@ -100,10 +100,10 @@ <h1>GCC Code Coverage Report</h1>
<a href="coverage.main.cpp.118fcbaaba162ba17933c7893247df3a.html">main.cpp</a>
</th>
<td>
<meter class="coverage-low" min="0" max="100" value="64.3" title="64.3%">64.3</meter>
<meter class="coverage-high" min="0" max="100" value="100.0" title="100.0%">100.0</meter>
</td>
<td class="CoverValue line-coverage coverage-low">64.3%</td>
<td class="CoverValue line-coverage coverage-low">9 / 14</td>
<td class="CoverValue line-coverage coverage-high">100.0%</td>
<td class="CoverValue line-coverage coverage-high">9 / 9</td>
<td class="CoverValue function-coverage coverage-high">100.0%</td>
<td class="CoverValue function-coverage coverage-high">2 / 2</td>
<td class="CoverValue branch-coverage coverage-low">66.7%</td>
Expand Down
35 changes: 0 additions & 35 deletions gcovr/tests/decisions-neg-delta/reference/clang-10/coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,13 @@
}
],
"lines": [
{
"branches": [],
"count": 0,
"gcovr/excluded": false,
"gcovr/noncode": false,
"line_number": 1
},
{
"branches": [],
"count": 0,
"gcovr/excluded": false,
"gcovr/noncode": true,
"line_number": 2
},
{
"branches": [],
"count": 0,
"gcovr/excluded": false,
"gcovr/noncode": false,
"line_number": 3
},
{
"branches": [],
"count": 0,
"gcovr/excluded": false,
"gcovr/noncode": false,
"line_number": 4
},
{
"branches": [],
"count": 1,
Expand Down Expand Up @@ -135,13 +114,6 @@
"gcovr/noncode": false,
"line_number": 11
},
{
"branches": [],
"count": 0,
"gcovr/excluded": false,
"gcovr/noncode": false,
"line_number": 12
},
{
"branches": [],
"count": 0,
Expand All @@ -156,13 +128,6 @@
"gcovr/noncode": false,
"line_number": 14
},
{
"branches": [],
"count": 0,
"gcovr/excluded": false,
"gcovr/noncode": false,
"line_number": 15
},
{
"branches": [],
"count": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>GCC Code Coverage Report</h1>
</tr>
<tr>
<th scope="row">Date:</th>
<td>2022-07-30 07:20:19</td>
<td>2022-08-04 20:10:40</td>
</tr>
</table>
</div>
Expand All @@ -42,8 +42,8 @@ <h1>GCC Code Coverage Report</h1>
<tr>
<th scope="row">Lines:</th>
<td>9</td>
<td>14</td>
<td class="coverage-low">64.3%</td>
<td>9</td>
<td class="coverage-high">100.0%</td>
</tr>
<tr>
<th scope="row">Functions:</th>
Expand Down Expand Up @@ -123,8 +123,8 @@ <h1>GCC Code Coverage Report</h1>
</td>
<td class="linedecision">
</td>
<td class="linecount uncoveredLine">&cross;</td>
<td class="src uncoveredLine"><span class="cp">#include</span> <span class="cpf">&lt;vector&gt;</span><span class="cp"></span></td>
<td class="linecount "></td>
<td class="src "><span class="cp">#include</span> <span class="cpf">&lt;vector&gt;</span><span class="cp"></span></td>
</tr>

<tr class="source-line">
Expand All @@ -143,8 +143,8 @@ <h1>GCC Code Coverage Report</h1>
</td>
<td class="linedecision">
</td>
<td class="linecount uncoveredLine">&cross;</td>
<td class="src uncoveredLine"><span class="k">class</span> <span class="nc">Foo</span> <span class="p">{</span></td>
<td class="linecount "></td>
<td class="src "><span class="k">class</span> <span class="nc">Foo</span> <span class="p">{</span></td>
</tr>

<tr class="source-line">
Expand All @@ -153,8 +153,8 @@ <h1>GCC Code Coverage Report</h1>
</td>
<td class="linedecision">
</td>
<td class="linecount uncoveredLine">&cross;</td>
<td class="src uncoveredLine"><span class="k">public</span><span class="o">:</span></td>
<td class="linecount "></td>
<td class="src "><span class="k">public</span><span class="o">:</span></td>
</tr>

<tr class="source-line">
Expand Down Expand Up @@ -268,8 +268,8 @@ <h1>GCC Code Coverage Report</h1>
</td>
<td class="linedecision">
</td>
<td class="linecount uncoveredLine">&cross;</td>
<td class="src uncoveredLine"><span class="p">};</span></td>
<td class="linecount "></td>
<td class="src "><span class="p">};</span></td>
</tr>

<tr class="source-line">
Expand Down Expand Up @@ -298,8 +298,8 @@ <h1>GCC Code Coverage Report</h1>
</td>
<td class="linedecision">
</td>
<td class="linecount uncoveredLine">&cross;</td>
<td class="src uncoveredLine"> <span class="n">Foo</span> <span class="n">foo</span><span class="p">;</span></td>
<td class="linecount "></td>
<td class="src "> <span class="n">Foo</span> <span class="n">foo</span><span class="p">;</span></td>
</tr>

<tr class="source-line">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1>GCC Code Coverage Report</h1>
</tr>
<tr>
<th scope="row">Date:</th>
<td>2022-07-30 07:20:41</td>
<td>2022-08-04 20:12:31</td>
</tr>
<tr>
<th scope="row">Legend:</th>
Expand All @@ -47,8 +47,8 @@ <h1>GCC Code Coverage Report</h1>
<tr>
<th scope="row">Lines:</th>
<td>9</td>
<td>14</td>
<td class="coverage-low">64.3%</td>
<td>9</td>
<td class="coverage-high">100.0%</td>
</tr>
<tr>
<th scope="row">Functions:</th>
Expand Down
35 changes: 0 additions & 35 deletions gcovr/tests/decisions-neg-delta/reference/clang-13/coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,13 @@
}
],
"lines": [
{
"branches": [],
"count": 0,
"gcovr/excluded": false,
"gcovr/noncode": false,
"line_number": 1
},
{
"branches": [],
"count": 0,
"gcovr/excluded": false,
"gcovr/noncode": true,
"line_number": 2
},
{
"branches": [],
"count": 0,
"gcovr/excluded": false,
"gcovr/noncode": false,
"line_number": 3
},
{
"branches": [],
"count": 0,
"gcovr/excluded": false,
"gcovr/noncode": false,
"line_number": 4
},
{
"branches": [],
"count": 1,
Expand Down Expand Up @@ -135,13 +114,6 @@
"gcovr/noncode": false,
"line_number": 11
},
{
"branches": [],
"count": 0,
"gcovr/excluded": false,
"gcovr/noncode": false,
"line_number": 12
},
{
"branches": [],
"count": 0,
Expand All @@ -156,13 +128,6 @@
"gcovr/noncode": false,
"line_number": 14
},
{
"branches": [],
"count": 0,
"gcovr/excluded": false,
"gcovr/noncode": false,
"line_number": 15
},
{
"branches": [],
"count": 1,
Expand Down
Loading

0 comments on commit b5a7f9f

Please sign in to comment.