Skip to content

Commit c845bb9

Browse files
committed
Add a more detailed test coverage report
1 parent 195fdd0 commit c845bb9

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

script/cibuild

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ if [ "$RSPEC_TEST" = "true" ]; then
105105
if [ "$exitcode" -ne 0 ]; then RSPEC_EXITCODE="$exitcode"; fi
106106

107107
# Quick coverage report
108-
cat "$DIR/coverage/coverage.json" \
109-
| jq -r '.files[] | select(.covered_percent < 100) | (.covered_percent|tostring) + ": " + .filename'
108+
"$DIR/script/display-coverage-report" "$DIR/coverage/coverage.json"
110109
echo ""
111110

112111
# To avoid travis getting hung if it gets confused, we'll run each of these

script/display-coverage-report

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env ruby
2+
3+
# Quick hacky script to parse the coverage JSON report and display it in human-readable terms.
4+
# Usage: display-coverage-report <JSON_FILE>
5+
6+
require 'json'
7+
require 'pathname'
8+
9+
# Arg handling and validation
10+
json_file = ARGV.first
11+
unless json_file
12+
raise "Usage: #{__FILE__} <json_coverage_file>"
13+
end
14+
15+
unless File.file?(json_file)
16+
raise "Error: Provided file #{json_file} does not exist"
17+
end
18+
19+
# Find files with < 100% coverage
20+
result = {}
21+
data = JSON.parse(File.read(json_file))
22+
data['files'].each do |data|
23+
next if data['covered_percent'] == 100
24+
25+
result[data['filename']] = { covered: data['covered_percent'], lines: [] }
26+
data['coverage'].each_with_index do |cov, index|
27+
next if cov.nil?
28+
result[data['filename']][:lines] << (index + 1) if cov == 0
29+
end
30+
end
31+
32+
# Display results
33+
if result.empty?
34+
puts "100% Coverage - You're all set, friend! :sparkles:"
35+
exit 0
36+
end
37+
38+
puts ""
39+
puts "-------------------------------------------------------------"
40+
puts "Test coverage report"
41+
puts "-------------------------------------------------------------"
42+
43+
basedir = Pathname.new(File.expand_path('..', File.dirname(__FILE__)))
44+
result.keys.sort.each do |filename|
45+
data = result[filename]
46+
relative_path = Pathname.new(filename).relative_path_from(basedir).to_s
47+
printf "* %s: %0.02f%% (missed: %s)", relative_path, data[:covered], data[:lines].join(",")
48+
end
49+
50+
puts ""
51+
exit 1

0 commit comments

Comments
 (0)