Skip to content

Commit

Permalink
fix: do not remove contract from coverage report if a function is mis…
Browse files Browse the repository at this point in the history
…sing statements or branches

The previous behavior expects all functions to have a report for both
statements and branches. If not, it removes the whole contract from the
coverage report.
While the assumption seems reasonable, some functions seem to only have
either one of statements or branches, ending up in removing contracts
that would otherwise contain useful coverage information.

This is related to eth-brownie#1087 and should at least be a partial fix to it
  • Loading branch information
danhper committed Aug 16, 2021
1 parent 9d152b2 commit c6a4e35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This changelog format is based on [Keep a Changelog](https://keepachangelog.com/
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/eth-brownie/brownie)
- Fix issue with missing contracts in coverage report

## [1.16.0](https://github.com/eth-brownie/brownie/tree/v1.16.0) - 2021-08-08
### Added
Expand Down
17 changes: 10 additions & 7 deletions brownie/test/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,22 @@ def _split_by_fn(build, coverage_eval):

def _split(coverage_eval, coverage_map, key):
results = {}
for fn, map_ in coverage_map["statements"][key].items():
results[fn] = [[i for i in map_ if int(i) in coverage_eval[0]], [], []]
for fn, map_ in coverage_map["branches"][key].items():
results[fn][1] = [i for i in map_ if int(i) in coverage_eval[1]]
results[fn][2] = [i for i in map_ if int(i) in coverage_eval[2]]
branches = coverage_map["branches"][key]
statements = coverage_map["statements"][key]
for fn in branches.keys() & statements.keys():
results[fn] = [
[i for i in statements[fn] if int(i) in coverage_eval[0]],
[i for i in branches[fn] if int(i) in coverage_eval[1]],
[i for i in branches[fn] if int(i) in coverage_eval[2]],
]
return results


def _statement_totals(coverage_eval, coverage_map, exclude_contracts):
result = {}
count, total = 0, 0
for path, fn in [(k, x) for k, v in coverage_eval.items() for x in v]:
if fn.split(".")[0] in exclude_contracts:
if fn.split(".")[0] in exclude_contracts or fn not in coverage_eval[path]:
continue
count += len(coverage_eval[path][fn][0])
total += len(coverage_map[path][fn])
Expand All @@ -247,7 +250,7 @@ def _branch_totals(coverage_eval, coverage_map, exclude_contracts):
result = {}
final = [0, 0, 0]
for path, fn in [(k, x) for k, v in coverage_map.items() for x in v]:
if fn.split(".")[0] in exclude_contracts:
if fn.split(".")[0] in exclude_contracts or fn not in coverage_eval[path]:
continue
if path not in coverage_eval:
true, false = 0, 0
Expand Down

0 comments on commit c6a4e35

Please sign in to comment.