Skip to content

Commit 8aaf971

Browse files
committed
coverage: ensure definition line is also counted
Closes #36825
1 parent 42a1d34 commit 8aaf971

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

src/codegen.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6532,6 +6532,13 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
65326532
Value *sync_bytes = nullptr;
65336533
if (do_malloc_log(true))
65346534
sync_bytes = ctx.builder.CreateCall(prepare_call(diff_gc_total_bytes_func), {});
6535+
{ // coverage for the function definition line number
6536+
const auto &topinfo = linetable.at(0);
6537+
if (topinfo == linetable.at(1))
6538+
current_lineinfo.push_back(1);
6539+
if (do_coverage(topinfo.is_user_code))
6540+
coverageVisitLine(ctx, topinfo.file, topinfo.line);
6541+
}
65356542

65366543
find_next_stmt(0);
65376544
while (cursor != -1) {

test/cmdlineargs.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ let exename = `$(Base.julia_cmd()) --startup-file=no`
258258
mktempdir() do dir
259259
helperdir = joinpath(@__DIR__, "testhelpers")
260260
inputfile = joinpath(helperdir, "coverage_file.jl")
261-
expected = replace(read(joinpath(helperdir, "coverage_file.info"), String),
261+
expected = replace(read(joinpath(helperdir, "coverage_file.info.bad"), String),
262+
"<FILENAME>" => realpath(inputfile))
263+
expected_good = replace(read(joinpath(helperdir, "coverage_file.info"), String),
262264
"<FILENAME>" => realpath(inputfile))
263265
covfile = replace(joinpath(dir, "coverage.info"), "%" => "%%")
264266
@test !isfile(covfile)
@@ -276,18 +278,21 @@ let exename = `$(Base.julia_cmd()) --startup-file=no`
276278
got = read(covfile, String)
277279
rm(covfile)
278280
@test occursin(expected, got) || (expected, got)
281+
@test_broken occursin(expected_good, got)
279282
@test readchomp(`$exename -E "Base.JLOptions().code_coverage" -L $inputfile
280283
--code-coverage=$covfile --code-coverage=user`) == "1"
281284
@test isfile(covfile)
282285
got = read(covfile, String)
283286
rm(covfile)
284287
@test occursin(expected, got) || (expected, got)
288+
@test_broken occursin(expected_good, got)
285289
@test readchomp(`$exename -E "Base.JLOptions().code_coverage" -L $inputfile
286290
--code-coverage=$covfile --code-coverage=all`) == "2"
287291
@test isfile(covfile)
288292
got = read(covfile, String)
289293
rm(covfile)
290294
@test occursin(expected, got) || (expected, got)
295+
@test_broken occursin(expected_good, got)
291296
end
292297

293298
# --track-allocation
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
SF:<FILENAME>
2+
DA:3,1
23
DA:4,1
34
DA:5,0
45
DA:7,1
@@ -8,6 +9,9 @@ DA:11,1
89
DA:12,1
910
DA:14,0
1011
DA:17,1
11-
LH:7
12-
LF:9
12+
DA:19,1
13+
DA:20,1
14+
DA:22,1
15+
LH:10
16+
LF:13
1317
end_of_record
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SF:<FILENAME>
2+
DA:3,1
3+
DA:4,1
4+
DA:5,0
5+
DA:7,1
6+
DA:8,1
7+
DA:9,5
8+
DA:11,1
9+
DA:12,1
10+
DA:14,0
11+
DA:17,1
12+
DA:18,0
13+
DA:19,1
14+
DA:20,1
15+
DA:22,1
16+
DA:1234,0
17+
LH:11
18+
LF:15
19+
end_of_record

test/testhelpers/coverage_file.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ function code_coverage_test()
1414
not_reached
1515
end
1616

17-
short_form_func_coverage_test(x) = x*x
17+
@eval short_form_func_coverage_test(x) = begin
18+
$(Expr(:line, 1234))
19+
y() = begin
20+
x
21+
end
22+
x * y()
23+
end
1824

1925
success = code_coverage_test() == [1, 2, 3] &&
2026
short_form_func_coverage_test(2) == 4

0 commit comments

Comments
 (0)