From 6dfd139ac2917b80637eaec527bcf3f36fc9eed0 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 7 Mar 2019 14:16:46 +0100 Subject: [PATCH] Let amend_coverage_from_src! skip partially covered code This is meant to fix issue #187 --- src/Coverage.jl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Coverage.jl b/src/Coverage.jl index 35d1476..429eef8 100644 --- a/src/Coverage.jl +++ b/src/Coverage.jl @@ -178,10 +178,19 @@ module Coverage flines = function_body_lines(ast) if !isempty(flines) flines .+= linestart-1 + + if any(l -> l > length(coverage), flines) + error("source file is longer than .cov file; source might have changed") + end + + # If any line has coverage, assume that Julia executed this code, and + # don't modify any coverage data. This works around issues with inlined + # code, see https://github.com/JuliaCI/Coverage.jl/issues/187 + if any(l -> coverage[l] != nothing, flines) + continue + end + for l in flines - if l > length(coverage) - error("source file is longer than .cov file; source might have changed") - end if coverage[l] === nothing coverage[l] = 0 end