-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make code/test coverage a thing we care about
It's not perfect, but it is something. Full line coverage, full branch coverage, checked for every PR.
- Loading branch information
1 parent
fb00037
commit ba324e4
Showing
8 changed files
with
149 additions
and
9 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# frozen_string_literal: true | ||
|
||
require "simplecov" | ||
require "json" | ||
|
||
class SimpleCovCheckActionFormatter | ||
SourceFile = Data.define(:source_file) do | ||
def covered_strength = source_file.covered_strength | ||
def covered_percent = source_file.covered_percent | ||
|
||
def to_json(*) | ||
{ | ||
filename: source_file.filename, | ||
covered_percent: covered_percent.nan? ? 0.0 : covered_percent, | ||
coverage: source_file.coverage_data, | ||
covered_strength: covered_strength.nan? ? 0.0 : covered_strength, | ||
covered_lines: source_file.covered_lines.count, | ||
lines_of_code: source_file.lines_of_code | ||
}.to_json | ||
end | ||
end | ||
|
||
Result = Data.define(:result) do | ||
def included?(source_file) = result.filenames.include?(source_file.filename) | ||
|
||
def files | ||
result.files.filter_map do |source_file| | ||
next unless result.filenames.include? source_file.filename | ||
|
||
SourceFile.new(source_file) | ||
end | ||
end | ||
|
||
def to_json(*) # rubocop:disable Metrics/AbcSize | ||
{ | ||
timestamp: result.created_at.to_i, | ||
command_name: result.command_name, | ||
files: files, | ||
metrics: { | ||
covered_percent: result.covered_percent, | ||
covered_strength: result.covered_strength.nan? ? 0.0 : result.covered_strength, | ||
covered_lines: result.covered_lines, | ||
total_lines: result.total_lines | ||
} | ||
}.to_json | ||
end | ||
end | ||
|
||
FormatterWithOptions = Data.define(:formatter) do | ||
def new = formatter | ||
end | ||
|
||
class << self | ||
def with_options(...) | ||
FormatterWithOptions.new(new(...)) | ||
end | ||
end | ||
|
||
def initialize(output_filename: "coverage.json", output_directory: SimpleCov.coverage_path) | ||
@output_filename = output_filename | ||
@output_directory = output_directory | ||
end | ||
|
||
attr_reader :output_filename, :output_directory | ||
|
||
def output_filepath = File.join(output_directory, output_filename) | ||
|
||
def format(result_data) | ||
result = Result.new(result_data) | ||
json = result.to_json | ||
File.write(output_filepath, json) | ||
puts output_message(result_data) | ||
json | ||
end | ||
|
||
def output_message(result) | ||
"Coverage report generated for #{result.command_name} to #{output_filepath}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered." # rubocop:disable Layout/LineLength | ||
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
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ def resolve | |
def update? | ||
post.user == user | ||
end | ||
alias edit? update? | ||
|
||
def destroy? | ||
false | ||
|