Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM cyberdojo/sinatra-base:759c4e9@sha256:d5f87f343a9f88a598b810c0f02b81db0bb67319701a956aec3577cbd51c1c24
FROM ghcr.io/cyber-dojo/sinatra-base:5ab6a10@sha256:c096154011cc1cef9cc69e8be948fb4329543f9670d4fb4fd3851a8aa016630d
LABEL maintainer=jon@jaggersoft.com

ARG COMMIT_SHA
Expand Down
8 changes: 4 additions & 4 deletions source/server/differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ def diff_summary(was_files:, now_files:)
diff_plus(was_files, now_files, lines: false)
end

# :nocov:
# simplecov:disable
def diff_lines_files(was_files:, now_files:)
diff_plus(was_files, now_files, lines: true)
end
# :nocov:
# simplecov:enable

# :nocov:
# simplecov:disable
def diff_summary_files(was_files:, now_files:)
diff_plus(was_files, now_files, lines: false)
end
# :nocov:
# simplecov:enable

private

Expand Down
10 changes: 5 additions & 5 deletions test/client/lib/coverage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
SimpleCov.start do
enable_coverage :branch
filters.clear
add_filter('test/lib/id58_test_base.rb')
skip('test/lib/id58_test_base.rb')
coverage_dir(ENV.fetch('COVERAGE_ROOT', nil))
root(APP_DIR)

test_tab = ENV.fetch('COVERAGE_TEST_TAB_NAME')
code_tab = ENV.fetch('COVERAGE_CODE_TAB_NAME')
# add_group('debug') { |the| puts the.filename; false }
add_group(test_tab) { |the| the.filename.start_with?("#{APP_DIR}/test/") }
add_group(code_tab) { |the| the.filename.start_with?("#{APP_DIR}/source/") }
# group('debug') { |path| puts path.filename; false }
group(test_tab) { |path| path.filename.start_with?("#{APP_DIR}/test/") }
group(code_tab) { |path| path.filename.start_with?("#{APP_DIR}/source/") }
end

formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::JSONFormatter
CoverageMetricsFormatter
]
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(formatters)
89 changes: 45 additions & 44 deletions test/client/lib/simplecov_formatter_json.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
require 'simplecov'
require 'json'

module SimpleCov
module Formatter
class JSONFormatter
# based on https://github.com/vicentllongo/simplecov-json

def format(result)
data = {
timestamp: result.created_at.to_i,
command_name: result.command_name
# A SimpleCov formatter writing coverage_metrics.json, which check_metrics.rb
# reads. SimpleCov ships its own JSON formatter, shaped per file rather than
# per group, so this one carries its own name rather than reopening that class
# and redefining its format method. Redefining it makes ruby -w report the
# redefinition.
#
# based on https://github.com/vicentllongo/simplecov-json
class CoverageMetricsFormatter
def format(result)
data = {
timestamp: result.created_at.to_i,
command_name: result.command_name
}
result.groups.each do |name, file_list|
# name == 'code' or name == 'test'
data[name] = {
lines: {
total: file_list.lines_of_code,
covered: file_list.covered_lines,
missed: file_list.missed_lines
},
branches: {
total: file_list.total_branches,
covered: file_list.covered_branches,
missed: file_list.missed_branches
}
result.groups.each do |name, file_list|
# name == 'code' or name == 'test'
data[name] = {
lines: {
total: file_list.lines_of_code,
covered: file_list.covered_lines,
missed: file_list.missed_lines
},
branches: {
total: file_list.total_branches,
covered: file_list.covered_branches,
missed: file_list.missed_branches
}
}
end
File.open(output_filepath, 'w+') do |file|
file.print(JSON.pretty_generate(data))
end
puts output_message(result)
data.to_json
end
}
end
File.open(output_filepath, 'w+') do |file|
file.print(JSON.pretty_generate(data))
end
puts output_message(result)
data.to_json
end

def output_filepath
File.join(output_path, output_filename)
end
def output_filepath
File.join(output_path, output_filename)
end

def output_filename
'coverage_metrics.json'
end
def output_filename
'coverage_metrics.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."
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."
end

private
private

def output_path
SimpleCov.coverage_path
end
end
def output_path
SimpleCov.coverage_path
end
end
10 changes: 5 additions & 5 deletions test/server/lib/coverage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
SimpleCov.start do
enable_coverage :branch
filters.clear
add_filter('test/lib/id58_test_base.rb')
skip('test/lib/id58_test_base.rb')
coverage_dir(ENV.fetch('COVERAGE_ROOT'))
root(APP_DIR)

test_tab = ENV.fetch('COVERAGE_TEST_TAB_NAME')
code_tab = ENV.fetch('COVERAGE_CODE_TAB_NAME')
# add_group('debug') { |the| puts the.filename; false }
add_group(test_tab) { |the| the.filename.start_with?("#{APP_DIR}/test/") }
add_group(code_tab) { |the| the.filename.start_with?("#{APP_DIR}/source/") }
# group('debug') { |path| puts path.filename; false }
group(test_tab) { |path| path.filename.start_with?("#{APP_DIR}/test/") }
group(code_tab) { |path| path.filename.start_with?("#{APP_DIR}/source/") }
end

formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::JSONFormatter
CoverageMetricsFormatter
]
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(formatters)
89 changes: 45 additions & 44 deletions test/server/lib/simplecov_formatter_json.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
require 'simplecov'
require 'json'

module SimpleCov
module Formatter
class JSONFormatter
# based on https://github.com/vicentllongo/simplecov-json

def format(result)
data = {
timestamp: result.created_at.to_i,
command_name: result.command_name
# A SimpleCov formatter writing coverage_metrics.json, which check_metrics.rb
# reads. SimpleCov ships its own JSON formatter, shaped per file rather than
# per group, so this one carries its own name rather than reopening that class
# and redefining its format method. Redefining it makes ruby -w report the
# redefinition.
#
# based on https://github.com/vicentllongo/simplecov-json
class CoverageMetricsFormatter
def format(result)
data = {
timestamp: result.created_at.to_i,
command_name: result.command_name
}
result.groups.each do |name, file_list|
# name == 'code' or name == 'test'
data[name] = {
lines: {
total: file_list.lines_of_code,
covered: file_list.covered_lines,
missed: file_list.missed_lines
},
branches: {
total: file_list.total_branches,
covered: file_list.covered_branches,
missed: file_list.missed_branches
}
result.groups.each do |name, file_list|
# name == 'code' or name == 'test'
data[name] = {
lines: {
total: file_list.lines_of_code,
covered: file_list.covered_lines,
missed: file_list.missed_lines
},
branches: {
total: file_list.total_branches,
covered: file_list.covered_branches,
missed: file_list.missed_branches
}
}
end
File.open(output_filepath, 'w+') do |file|
file.print(JSON.pretty_generate(data))
end
puts output_message(result)
data.to_json
end
}
end
File.open(output_filepath, 'w+') do |file|
file.print(JSON.pretty_generate(data))
end
puts output_message(result)
data.to_json
end

def output_filepath
File.join(output_path, output_filename)
end
def output_filepath
File.join(output_path, output_filename)
end

def output_filename
'coverage_metrics.json'
end
def output_filename
'coverage_metrics.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."
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."
end

private
private

def output_path
SimpleCov.coverage_path
end
end
def output_path
SimpleCov.coverage_path
end
end
Loading