-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcoverage.jl
57 lines (44 loc) · 1.36 KB
/
coverage.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using Coverage
using Pkg
using Snowflurry
function print_missed_lines(fcs::Vector{FileCoverage})
for fc in fcs
print_missed_lines(fc)
end
end
function print_missed_lines(fc::FileCoverage; num_char_to_print::Integer = 100)
coverage = fc.coverage
a = open("$(fc.filename)", "r")
lines = readlines(a)
for (i, counts) in enumerate(coverage)
if counts == 0
print("File: $(fc.filename):")
printstyled("$(i)", color = :red)
printstyled(
" : $(
lines[i][1:minimum([num_char_to_print,length(lines[i])])])\n",
color = :cyan,
)
end
end
end
# Run tests with coverage
Pkg.test(coverage = true)
# process '*.cov' files
coverage = process_folder("src")
# process '*.info' files, if you collected them
coverage = merge_coverage_counts(coverage, LCOV.readfolder("test"))
LCOV.writefile("lcov.info", coverage)
# Get total coverage for all Julia files
covered_lines, total_lines = get_summary(coverage)
#clean .cov files
clean_folder("src")
clean_folder("test")
# Print summaru
println("Covered lines: $(covered_lines)")
println("Total lines: $(total_lines)")
println("Coverage percentage: $(covered_lines/total_lines)")
if ~(isapprox(covered_lines / total_lines, 1.0))
println("\n\tDetailed results, missed lines: \n")
print_missed_lines(coverage)
end