Skip to content

Commit 1150c47

Browse files
committed
fix: report line coverage instead of function coverage
It seems that the raw output of llvm-cov changed at some point, and we ended upcomparing functoin coverage instead of line coverage. Fix this by instead using the new json output, which will hopefully prevent such goofs in the future. Fixes #170 Signed-off-by: Patrick Roy <[email protected]>
1 parent 2122417 commit 1150c47

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

integration_tests/test_coverage.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _get_current_coverage(coverage_config, no_cleanup, test_scope):
7777
shutil.rmtree(cov_build_dir, ignore_errors=True)
7878

7979
llvm_cov_command = (
80-
f"CARGO_TARGET_DIR={cov_build_dir} cargo llvm-cov test --summary-only"
80+
f"CARGO_TARGET_DIR={cov_build_dir} cargo llvm-cov test --json --summary-only"
8181
)
8282

8383
additional_exclude_path = coverage_config["exclude_path"]
@@ -97,13 +97,8 @@ def _get_current_coverage(coverage_config, no_cleanup, test_scope):
9797
llvm_cov_command, shell=True, check=True, input=b"", stdout=subprocess.PIPE
9898
)
9999

100-
summary = result.stdout.split(b"\n")[-2]
101-
# Output of llvm-cov is like
102-
# TOTAL 743 153 79.41% 185 50 72.97% 1531 125 91.84% 0 0 -
103-
# where the first three numbers are related to region coverage, and next three to line coverage (what we want)
104-
# and the last three to branch coverage (which is not yet supported). Below grabs the line coverage, and strips
105-
# off the '%'.
106-
coverage = float(summary.split()[6][:-1])
100+
summary = json.loads(result.stdout)
101+
coverage = summary["data"][0]["totals"]["lines"]["percent"]
107102

108103
shutil.rmtree(cov_build_dir, ignore_errors=True)
109104

0 commit comments

Comments
 (0)