Skip to content

Commit

Permalink
fix: handle scientific notation when parsing hit count in lcov reports (
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-codecov committed Jan 3, 2024
1 parent b084755 commit f87a597
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
16 changes: 13 additions & 3 deletions services/report/languages/lcov.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import typing
from collections import defaultdict
from decimal import Decimal
from io import BytesIO

from shared.reports.resources import Report
Expand Down Expand Up @@ -105,7 +106,13 @@ def _process_file(doc: bytes, report_builder_session: ReportBuilderSession):
if hit == "undefined" or line == "undefined":
continue

cov = int(hit)
if hit.isnumeric():
cov = int(hit)
else:
# Huge ints may be expressed in scientific notation.
# int(float(hit)) may lose precision, but Decimal shouldn't.
cov = int(Decimal(hit))

if cov < -1:
# https://github.com/linux-test-project/lcov/commit/dfec606f3b30e1ac0f4114cfb98b29f91e9edb21
if not _already_informed_of_negative_execution_count:
Expand Down Expand Up @@ -143,8 +150,11 @@ def _process_file(doc: bytes, report_builder_session: ReportBuilderSession):
skip_lines.append(line)
continue

if hit != "":
fh[name] = int(hit)
if hit:
if hit.isnumeric():
fh[name] = int(hit)
else:
fh[name] = int(Decimal(hit))

elif method == "BRDA" and not JS:
"""
Expand Down
19 changes: 17 additions & 2 deletions services/report/languages/tests/unit/test_lcov.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
DA:null,skipped
DA:1,0
DA:=,=
DA:2,1e+0
BRDA:0,0,0,0
BRDA:1,1,1,1
end_of_record
Expand All @@ -64,13 +65,16 @@
FN:2,not_hit
FN:3,_Zalkfjeo
FN:4,_Gsabebra
FN:78,_Zalkfjeo2
FNDA:1,_ln1_is_skipped
FNDA:,not_hit
FNDA:2,ignored
FNDA:3,ignored
FNDA:4,ignored
FNDA:78,1+e0
DA:1,1
DA:77,0
DA:78,1
BRDA:2,1,0,1
BRDA:2,1,1,-
BRDA:2,1,3,0
Expand Down Expand Up @@ -138,10 +142,21 @@ def fixes(path):
[[0, "0/4", ["3:0", "3:1", "4:0", "4:1"], None, None]],
None,
None,
)
),
(
78,
1,
None,
[[0, 1, None, None, None]],
None,
None,
),
# TODO (Thiago): This is out f order compared to the original, verify what happened
],
"file.js": [(1, 1, None, [[0, 1, None, None, None]], None, None)],
"file.js": [
(1, 1, None, [[0, 1, None, None, None]], None, None),
(2, 1, None, [[0, 1, None, None, None]], None, None),
],
"file.ts": [(2, 1, None, [[0, 1, None, None, None]], None, None)],
}

Expand Down

0 comments on commit f87a597

Please sign in to comment.