-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify generating and gathering test coverage metrics
- Loading branch information
Showing
14 changed files
with
181 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM cyberdojo/docker-base:9f558cc | ||
FROM cyberdojo/docker-base:b3a6744 | ||
LABEL [email protected] | ||
|
||
RUN gem install --no-document 'concurrent-ruby' | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM cyberdojo/docker-base:9f558cc | ||
FROM cyberdojo/docker-base:b3a6744 | ||
LABEL [email protected] | ||
|
||
WORKDIR /runner | ||
|
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,61 @@ | ||
|
||
# Uses data from two json files: | ||
# - reports/client/test_metrics.json generated in slim_json_reporter.rb by minitest. See id58_test_base.rb | ||
# - reports/client/coverage_metrics.json generated in simplecov_formatter_json.rb by simplecov. See coverage.rb | ||
|
||
require 'json' | ||
|
||
def coloured(tf) | ||
red = 31 | ||
green = 32 | ||
colourize(tf ? green : red, tf) | ||
end | ||
|
||
def colourize(code, word) | ||
"\e[#{code}m #{word} \e[0m" | ||
end | ||
|
||
def table_data | ||
cov_root = ENV['COVERAGE_ROOT'] | ||
stats = JSON.parse(IO.read("#{cov_root}/test_metrics.json")) | ||
|
||
cov_json = JSON.parse(IO.read("#{cov_root}/coverage_metrics.json")) | ||
test_cov = cov_json['groups'][ENV['COVERAGE_TEST_TAB_NAME']] | ||
code_cov = cov_json['groups'][ENV['COVERAGE_CODE_TAB_NAME']] | ||
|
||
[ | ||
[ nil ], | ||
[ 'test.count', stats['test_count'], '>=', 67 ], | ||
[ 'test.duration', stats['total_time'], '<=', 100 ], | ||
[ nil ], | ||
[ 'test.failures', stats['failure_count'], '<=', 0 ], | ||
[ 'test.errors', stats['error_count' ], '<=', 0 ], | ||
[ 'test.skips', stats['skip_count' ], '<=', 0 ], | ||
[ nil ], | ||
[ 'test.lines.total', test_cov['lines' ]['total' ], '<=', 518 ], | ||
[ 'test.lines.missed', test_cov['lines' ]['missed'], '<=', 0 ], | ||
[ 'test.branches.total', test_cov['branches']['total' ], '<=', 5 ], | ||
[ 'test.branches.missed', test_cov['branches']['missed'], '<=', 0 ], | ||
[ nil ], | ||
[ 'code.lines.total', code_cov['lines' ]['total' ], '<=', 122 ], | ||
[ 'code.lines.missed', code_cov['lines' ]['missed'], '<=', 1 ], | ||
[ 'code.branches.total', code_cov['branches']['total' ], '<=', 6 ], | ||
[ 'code.branches.missed', code_cov['branches']['missed'], '<=', 0 ], | ||
] | ||
end | ||
|
||
results = [] | ||
table_data.each do |name, value, op, limit| | ||
if name.nil? | ||
puts | ||
next | ||
end | ||
# puts "name=#{name}, value=#{value}, op=#{op}, limit=#{limit}" # debug | ||
result = eval("#{value} #{op} #{limit}") | ||
puts "%s | %s %s %s | %s" % [ | ||
name.rjust(25), value.to_s.rjust(5), " #{op}", limit.to_s.rjust(5), coloured(result) | ||
] | ||
results << result | ||
end | ||
puts | ||
exit results.all? |
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,61 @@ | ||
|
||
# Uses data from two json files: | ||
# - reports/server/test_metrics.json generated in slim_json_reporter.rb by minitest. See id58_test_base.rb | ||
# - reports/server/coverage_metrics.json generated in simplecov_formatter_json.rb by simplecov. See coverage.rb | ||
|
||
require 'json' | ||
|
||
def coloured(tf) | ||
red = 31 | ||
green = 32 | ||
colourize(tf ? green : red, tf) | ||
end | ||
|
||
def colourize(code, word) | ||
"\e[#{code}m #{word} \e[0m" | ||
end | ||
|
||
def table_data | ||
cov_root = ENV['COVERAGE_ROOT'] | ||
stats = JSON.parse(IO.read("#{cov_root}/test_metrics.json")) | ||
|
||
cov_json = JSON.parse(IO.read("#{cov_root}/coverage_metrics.json")) | ||
test_cov = cov_json['groups'][ENV['COVERAGE_TEST_TAB_NAME']] | ||
code_cov = cov_json['groups'][ENV['COVERAGE_CODE_TAB_NAME']] | ||
|
||
[ | ||
[ nil ], | ||
[ 'test.count', stats['test_count'], '>=', 99 ], | ||
[ 'test.duration', stats['total_time'], '<=', 10 ], | ||
[ nil ], | ||
[ 'test.failures', stats['failure_count'], '<=', 0 ], | ||
[ 'test.errors', stats['error_count' ], '<=', 0 ], | ||
[ 'test.skips', stats['skip_count' ], '<=', 0 ], | ||
[ nil ], | ||
[ 'test.lines.total', test_cov['lines' ]['total' ], '<=', 967 ], | ||
[ 'test.lines.missed', test_cov['lines' ]['missed'], '<=', 0 ], | ||
[ 'test.branches.total', test_cov['branches']['total' ], '<=', 0 ], | ||
[ 'test.branches.missed', test_cov['branches']['missed'], '<=', 0 ], | ||
[ nil ], | ||
[ 'code.lines.total', code_cov['lines' ]['total' ], '<=', 549 ], | ||
[ 'code.lines.missed', code_cov['lines' ]['missed'], '<=', 1 ], | ||
[ 'code.branches.total', code_cov['branches']['total' ], '<=', 66 ], | ||
[ 'code.branches.missed', code_cov['branches']['missed'], '<=', 2 ], | ||
] | ||
end | ||
|
||
results = [] | ||
table_data.each do |name, value, op, limit| | ||
if name.nil? | ||
puts | ||
next | ||
end | ||
# puts "name=#{name}, value=#{value}, op=#{op}, limit=#{limit}" # debug | ||
result = eval("#{value} #{op} #{limit}") | ||
puts "%s | %s %s %s | %s" % [ | ||
name.rjust(25), value.to_s.rjust(5), " #{op}", limit.to_s.rjust(5), coloured(result) | ||
] | ||
results << result | ||
end | ||
puts | ||
exit results.all? |
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
require 'json' | ||
require 'minitest/reporters' | ||
|
||
class Minitest::Reporters::SlimJsonReporter < Minitest::Reporters::BaseReporter | ||
|
||
def report | ||
super | ||
filename = "#{ENV.fetch('COVERAGE_ROOT')}/test_metrics.json" | ||
metrics = { | ||
"total_time": "%.2f" % total_time, | ||
"assertion_count": assertions, | ||
"test_count": count, | ||
"failure_count": failures, | ||
"error_count": errors, | ||
"skip_count": skips | ||
} | ||
File.write(filename, JSON.pretty_generate(metrics)) | ||
end | ||
|
||
end |