-
-
Notifications
You must be signed in to change notification settings - Fork 456
Description
Describe the bug
coverage lcov
can generate BRDA:
records with line number zero. Current versions of lcov's genhtml
reject such lines:
genhtml: ERROR: line 0 of .../sourcefile.py has branchcov but no linecov data
To Reproduce
The bad BRDA records are coming from here:
coveragepy/coverage/lcovreport.py
Lines 108 to 112 in 5467e1f
# The exit branches have a negative line number, | |
# this will not produce valid lcov. Setting | |
# the line number of the exit branch to 0 will allow | |
# for valid lcov, while preserving the data. | |
line_number = max(line_number, 0) |
I do not understand how to hit this case. The commentary, and the description of what negative numbers mean in arc records (https://coverage.readthedocs.io/en/7.6.1/api_coveragedata.html#coverage.CoverageData.arc) make it sound like unexecuted conditional return statements could cause the problem. Running coverage run --branch test.py
on this file
def f(x):
if x < 0:
return
print("got here")
f(0)
f(1)
produces a .coverage
database whose arc
table does contain negative numbers, but running coverage lcov
on that database produces
BRDA:3,0,0,-
BRDA:4,0,1,1
BRF:2
BRH:1
which does not use line zero and looks correct to me (well, modulo the fact that a human would say there isn't a branch on line 4? but that's a separate issue).
Looking at the database for the real program that produced the actual bad lcov-format report that prompted this issue, I see lots more cases of negative numbers in the arc table, but the associated positive numbers are too large to be actual line numbers in the associated file, which means I don't actually understand what the records in the arc table mean, so I'm stuck.
Expected behavior
coverage lcov
should generate a .lcov file that genhtml
does not reject.