diff --git a/source/client/Dockerfile b/source/client/Dockerfile index 868d4943..aa788e27 100644 --- a/source/client/Dockerfile +++ b/source/client/Dockerfile @@ -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 diff --git a/source/server/differ.rb b/source/server/differ.rb index 240d7191..b5f82246 100644 --- a/source/server/differ.rb +++ b/source/server/differ.rb @@ -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 diff --git a/test/client/lib/coverage.rb b/test/client/lib/coverage.rb index c5bbba57..e899276a 100644 --- a/test/client/lib/coverage.rb +++ b/test/client/lib/coverage.rb @@ -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) diff --git a/test/client/lib/simplecov_formatter_json.rb b/test/client/lib/simplecov_formatter_json.rb index 215dc51e..4507c71c 100644 --- a/test/client/lib/simplecov_formatter_json.rb +++ b/test/client/lib/simplecov_formatter_json.rb @@ -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 diff --git a/test/server/lib/coverage.rb b/test/server/lib/coverage.rb index 68ab75e5..87d119ee 100644 --- a/test/server/lib/coverage.rb +++ b/test/server/lib/coverage.rb @@ -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) diff --git a/test/server/lib/simplecov_formatter_json.rb b/test/server/lib/simplecov_formatter_json.rb index 215dc51e..4507c71c 100644 --- a/test/server/lib/simplecov_formatter_json.rb +++ b/test/server/lib/simplecov_formatter_json.rb @@ -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