-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SimpleCov reporting with GitHub Job Summary
This GitHub Job Summary is very simple for now.
- Loading branch information
Showing
12 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
/.gem_rbs_collection | ||
/tmp | ||
/gemfiles/*.lock | ||
/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"lib/*.rb": { | ||
"type": "lib", | ||
"alternate": "spec/{}_spec.rb", | ||
"related": [ | ||
"sig/{}.rbs" | ||
] | ||
}, | ||
"test/*_test.rb": { | ||
"type": "test", | ||
"dispatch": "bundle exec ruby -Itest {file}", | ||
"alternate": "lib/{}.rb", | ||
"related": [ | ||
"sig/{}.rbs" | ||
] | ||
}, | ||
"spec/*_spec.rb": { | ||
"type": "spec", | ||
"dispatch": "bundle exec ruby -Ispec {file}", | ||
"alternate": "lib/{}.rb", | ||
"related": [ | ||
"sig/{}.rbs" | ||
] | ||
}, | ||
"sig/*.rbs": { | ||
"type": "sig", | ||
"alternate": "lib/{}.rb", | ||
"related": [ | ||
"spec/{}_spec.rb", | ||
"test/{}_test.rb" | ||
] | ||
}, | ||
"README.md": { | ||
"type": "doc" | ||
}, | ||
"*": { | ||
"make": "bundle exec rake", | ||
"console": "bundle exec irb -rgraft" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "spec_helper/simplecov" | ||
require_relative "spec_helper/minitest/reporter" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
if %w[y yes true 1].include? ENV["COVERAGE"] | ||
require "simplecov" | ||
require "simplecov_json_formatter" | ||
require_relative "simplecov/formatters/markdown_formatter" | ||
|
||
SimpleCov.configure do | ||
add_filter %r{(?:spec|test|bin)} | ||
|
||
SimpleCov.formatters = [ | ||
SimpleCov::Formatter::HTMLFormatter, | ||
SimpleCov::Formatter::JSONFormatter, | ||
SimpleCov::Formatter::MarkdownFormatter | ||
] | ||
|
||
# Ruby 2.5+ | ||
enable_coverage :branch | ||
primary_coverage :branch | ||
|
||
# Ruby 3.2+ | ||
enable_coverage_for_eval | ||
end | ||
|
||
SimpleCov.start | ||
end |
57 changes: 57 additions & 0 deletions
57
spec/spec_helper/simplecov/formatters/markdown_formatter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
# Ensure we are using a compatible version of SimpleCov | ||
major, minor, patch = SimpleCov::VERSION.scan(/\d+/).first(3).map(&:to_i) | ||
if major < 0 || minor < 9 || patch < 0 | ||
raise "The version of SimpleCov you are using is too old. " \ | ||
"Please update with `gem install simplecov` or `bundle update simplecov`" | ||
end | ||
|
||
require "simplecov-html" | ||
|
||
module SimpleCov | ||
module Formatter | ||
class MarkdownFormatter < HTMLFormatter | ||
def initialize | ||
@branchable_result = SimpleCov.branch_coverage? | ||
@templates = {} | ||
end | ||
|
||
def format(result) | ||
File.open(File.join(output_path, "coverage.md"), "wb") do |file| | ||
file.puts template("layout").result(binding) | ||
end | ||
|
||
# TODO: disabled til `views/source_file.md.erb` is implemented | ||
# result.source_files.each do |source_file| | ||
# path = File.dirname(File.join(output_path, shortened_filename(source_file))) | ||
# | ||
# FileUtils.mkdir_p(path) | ||
# | ||
# File.open(File.join(output_path, shortened_filename(source_file)) + ".md", "wb") do |file| | ||
# file.puts formatted_source_file(source_file) | ||
# end | ||
# end | ||
|
||
puts output_message(result) | ||
end | ||
|
||
def output_message(result) | ||
str = "Markdown coverage report generated for #{result.command_name} to #{output_path}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered." | ||
str += " #{result.covered_branches} / #{result.total_branches} branches (#{result.coverage_statistics[:branch].percent.round(2)}%) covered." if branchable_result? | ||
str | ||
end | ||
|
||
private | ||
|
||
# Returns the an erb instance for the template of given name | ||
def template(name) | ||
@templates[name] ||= ERB.new(File.read(File.join(File.dirname(__FILE__), "./views/", "#{name}.md.erb"))) | ||
end | ||
|
||
def link_to_source_file(source_file) | ||
shortened_filename source_file | ||
end | ||
end | ||
end | ||
end |
1 change: 1 addition & 0 deletions
1
spec/spec_helper/simplecov/formatters/views/covered_percent.md.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= percent.round(2) %>% |
10 changes: 10 additions & 0 deletions
10
spec/spec_helper/simplecov/formatters/views/file_list.md.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# All Files ( <%= covered_percent(source_files.covered_percent) %> covered at <%= source_files.covered_strength.round(2) %> ) hits / line | ||
|
||
**<%= source_files.length %>** files in total. | ||
**<%= source_files.lines_of_code %>** relevant lines, **<%= source_files.covered_lines %>** lines covered and **<%= source_files.missed_lines %>** lines missed. (<%= covered_percent(source_files.covered_percent) %>)<% if branchable_result? %> | ||
**<%= source_files.total_branches %>** total branches, **<%= source_files.covered_branches %>** branches covered and **<%= source_files.missed_branches %>** branches missed. (<%= covered_percent(source_files.branch_covered_percent) %>)<% end %> | ||
|
||
| File | % covered | Lines | Relevant Lines | Lines covered | Lines missed | Avg. Hits / Line | <% if branchable_result? %> Branch Coverage | Branches | Covered branches | Missed branches | <% end %> | ||
| ---- | --------: | ----: | -------------: | ------------: | -----------: | ---------------: | <% if branchable_result? %> --------------: | -------: | ---------------: | --------------: | <% end %> | ||
<% source_files.each do |source_file| %>| <%= link_to_source_file(source_file) %> | <%= sprintf("%.2f", source_file.covered_percent.round(2)) %> % | <%= source_file.lines.count %> | <%= source_file.covered_lines.count + source_file.missed_lines.count %> | <%= source_file.covered_lines.count %> | <%= source_file.missed_lines.count %> | <%= sprintf("%.2f", source_file.covered_strength.round(2)) %> |<% if branchable_result? %> <%= sprintf("%.2f", source_file.branches_coverage_percent.round(2)) %> % | <%= source_file.total_branches.count %> | <%= source_file.covered_branches.count %> | <%= source_file.missed_branches.count %> |<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!-- Generated <%= Time.now %> --> | ||
<%= formatted_file_list("All Files", result.source_files) %> | ||
|
||
<% result.groups.each do |name, files| %> | ||
<%= formatted_file_list(name, files) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= shortened_filename source_file %> |