coverband 6.1.2 → 6.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +1 -0
- data/.rubocop.yml +5 -0
- data/README.md +6 -14
- data/changes.md +21 -0
- data/coverband.gemspec +5 -4
- data/lib/coverband/adapters/base.rb +5 -22
- data/lib/coverband/adapters/file_store.rb +0 -4
- data/lib/coverband/adapters/hash_redis_store.rb +20 -106
- data/lib/coverband/adapters/memcached_store.rb +0 -4
- data/lib/coverband/adapters/null_store.rb +0 -4
- data/lib/coverband/adapters/redis_store.rb +9 -22
- data/lib/coverband/adapters/stdout_store.rb +0 -4
- data/lib/coverband/collectors/abstract_tracker.rb +7 -2
- data/lib/coverband/collectors/coverage.rb +7 -18
- data/lib/coverband/collectors/delta.rb +1 -1
- data/lib/coverband/collectors/view_tracker.rb +6 -2
- data/lib/coverband/configuration.rb +7 -21
- data/lib/coverband/integrations/background.rb +2 -0
- data/lib/coverband/integrations/sidekiq_swarm.rb +8 -0
- data/lib/coverband/reporters/base.rb +2 -2
- data/lib/coverband/reporters/console_report.rb +13 -3
- data/lib/coverband/reporters/json_report.rb +36 -2
- data/lib/coverband/utils/dead_methods.rb +1 -1
- data/lib/coverband/utils/html_formatter.rb +18 -1
- data/lib/coverband/utils/results.rb +13 -0
- data/lib/coverband/utils/source_file.rb +4 -3
- data/lib/coverband/utils/tasks.rb +97 -15
- data/lib/coverband/version.rb +1 -1
- data/lib/coverband.rb +4 -2
- data/test/benchmarks/benchmark.rake +0 -1
- data/test/coverband/adapters/base_test.rb +1 -4
- data/test/coverband/adapters/hash_redis_store_test.rb +0 -51
- data/test/coverband/adapters/memecached_store_test.rb +26 -0
- data/test/coverband/adapters/redis_store_test.rb +0 -8
- data/test/coverband/collectors/coverage_test.rb +0 -42
- data/test/coverband/collectors/delta_test.rb +24 -26
- data/test/coverband/collectors/route_tracker_test.rb +1 -1
- data/test/coverband/collectors/view_tracker_test.rb +17 -4
- data/test/coverband/configuration_test.rb +6 -23
- data/test/coverband/integrations/resque_worker_test.rb +3 -1
- data/test/coverband/reporters/base_test.rb +0 -1
- data/test/coverband/reporters/json_test.rb +11 -0
- data/test/coverband/reporters/web_test.rb +52 -54
- data/test/rails5_dummy/config/coverband.rb +0 -1
- data/test/rails5_dummy/config/coverband_missing_redis.rb +0 -1
- data/test/test_helper.rb +10 -3
- data/views/source_file.erb +1 -1
- metadata +35 -18
@@ -37,7 +37,7 @@ module Coverband
|
|
37
37
|
|
38
38
|
# apply coverband filters
|
39
39
|
report_files.each_pair do |file, data|
|
40
|
-
next if Coverband.configuration.ignore.any? { |i| file.match(i) }
|
40
|
+
next if Coverband.configuration.ignore.any? { |i| file.match?(i) }
|
41
41
|
|
42
42
|
filtered_report_files[report_name][file] = data
|
43
43
|
end
|
@@ -93,7 +93,7 @@ module Coverband
|
|
93
93
|
scov_style_report = {}
|
94
94
|
store.get_coverage_report(options).each_pair do |name, data|
|
95
95
|
data.each_pair do |key, line_data|
|
96
|
-
next if Coverband.configuration.ignore.any? { |i| key.match(i) }
|
96
|
+
next if Coverband.configuration.ignore.any? { |i| key.match?(i) }
|
97
97
|
next unless line_data
|
98
98
|
|
99
99
|
scov_style_report[name] = {} unless scov_style_report.key?(name)
|
@@ -7,11 +7,21 @@ module Coverband
|
|
7
7
|
###
|
8
8
|
class ConsoleReport < Base
|
9
9
|
def self.report(store, options = {})
|
10
|
-
|
11
|
-
|
10
|
+
coverband_reports = Coverband::Reporters::Base.report(store, options)
|
11
|
+
fix_reports(coverband_reports)
|
12
|
+
result = Coverband::Utils::Results.new(coverband_reports)
|
13
|
+
source_files = result.source_files
|
14
|
+
|
15
|
+
Coverband.configuration.logger.info "total_files: #{source_files.length}"
|
16
|
+
Coverband.configuration.logger.info "lines_of_code: #{source_files.lines_of_code}"
|
17
|
+
Coverband.configuration.logger.info "lines_covered: #{source_files.covered_lines}"
|
18
|
+
Coverband.configuration.logger.info "lines_missed: #{source_files.missed_lines}"
|
19
|
+
Coverband.configuration.logger.info "covered_percent: #{source_files.covered_percent}"
|
20
|
+
|
21
|
+
coverband_reports[:merged].each_pair do |file, usage|
|
12
22
|
Coverband.configuration.logger.info "#{file}: #{usage["data"]}"
|
13
23
|
end
|
14
|
-
|
24
|
+
coverband_reports
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
@@ -5,13 +5,16 @@
|
|
5
5
|
module Coverband
|
6
6
|
module Reporters
|
7
7
|
class JSONReport < Base
|
8
|
-
attr_accessor :filtered_report_files, :options, :page, :as_report, :store, :filename, :base_path
|
8
|
+
attr_accessor :filtered_report_files, :options, :page, :as_report, :store, :filename, :base_path, :line_coverage,
|
9
|
+
:for_merged_report
|
9
10
|
|
10
11
|
def initialize(store, options = {})
|
11
12
|
self.options = options
|
12
13
|
self.page = options.fetch(:page) { nil }
|
13
14
|
self.filename = options.fetch(:filename) { nil }
|
14
15
|
self.as_report = options.fetch(:as_report) { false }
|
16
|
+
self.line_coverage = options.fetch(:line_coverage) { false }
|
17
|
+
self.for_merged_report = options.fetch(:for_merged_report) { false }
|
15
18
|
self.base_path = options.fetch(:base_path) { "./" }
|
16
19
|
self.store = store
|
17
20
|
|
@@ -28,6 +31,33 @@ module Coverband
|
|
28
31
|
report_as_json
|
29
32
|
end
|
30
33
|
|
34
|
+
def merge_reports(first_report, second_report, options = {})
|
35
|
+
merged_data = {}
|
36
|
+
merged_data[Coverband::RUNTIME_TYPE.to_s] = Coverband::Adapters::Base.new.send(
|
37
|
+
:merge_reports,
|
38
|
+
first_report[Coverband::RUNTIME_TYPE.to_s],
|
39
|
+
second_report[Coverband::RUNTIME_TYPE.to_s],
|
40
|
+
{skip_expansion: true}
|
41
|
+
)
|
42
|
+
if first_report[Coverband::EAGER_TYPE.to_s] && second_report[Coverband::EAGER_TYPE.to_s]
|
43
|
+
merged_data[Coverband::EAGER_TYPE.to_s] = Coverband::Adapters::Base.new.send(
|
44
|
+
:merge_reports,
|
45
|
+
first_report[Coverband::EAGER_TYPE.to_s],
|
46
|
+
second_report[Coverband::EAGER_TYPE.to_s],
|
47
|
+
{skip_expansion: true}
|
48
|
+
)
|
49
|
+
end
|
50
|
+
if first_report[Coverband::MERGED_TYPE.to_s] && second_report[Coverband::MERGED_TYPE.to_s]
|
51
|
+
merged_data[Coverband::MERGED_TYPE.to_s] = Coverband::Adapters::Base.new.send(
|
52
|
+
:merge_reports,
|
53
|
+
first_report[Coverband::MERGED_TYPE.to_s],
|
54
|
+
second_report[Coverband::MERGED_TYPE.to_s],
|
55
|
+
{skip_expansion: true}
|
56
|
+
)
|
57
|
+
end
|
58
|
+
merged_data
|
59
|
+
end
|
60
|
+
|
31
61
|
private
|
32
62
|
|
33
63
|
def coverage_css_class(covered_percent)
|
@@ -43,6 +73,8 @@ module Coverband
|
|
43
73
|
end
|
44
74
|
|
45
75
|
def report_as_json
|
76
|
+
return filtered_report_files.to_json if for_merged_report
|
77
|
+
|
46
78
|
result = Coverband::Utils::Results.new(filtered_report_files)
|
47
79
|
source_files = result.source_files
|
48
80
|
|
@@ -97,7 +129,7 @@ module Coverband
|
|
97
129
|
def coverage_files(result, source_files)
|
98
130
|
source_files.each_with_object({}) do |source_file, hash|
|
99
131
|
runtime_coverage = result.file_with_type(source_file, Coverband::RUNTIME_TYPE)&.covered_lines_count || 0
|
100
|
-
|
132
|
+
data = {
|
101
133
|
filename: source_file.filename,
|
102
134
|
hash: Digest::SHA1.hexdigest(source_file.filename),
|
103
135
|
never_loaded: source_file.never_loaded,
|
@@ -109,6 +141,8 @@ module Coverband
|
|
109
141
|
covered_percent: source_file.covered_percent,
|
110
142
|
covered_strength: source_file.covered_strength
|
111
143
|
}
|
144
|
+
data[:coverage] = source_file.coverage if line_coverage
|
145
|
+
hash[source_file.short_name] = data
|
112
146
|
end
|
113
147
|
end
|
114
148
|
end
|
@@ -150,6 +150,14 @@ module Coverband
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
+
def missed_lines_css_class(count)
|
154
|
+
if count == 0
|
155
|
+
"green"
|
156
|
+
else
|
157
|
+
"red"
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
153
161
|
# Return a (kind of) unique id for the source file given. Uses SHA1 on path for the id
|
154
162
|
def id(source_file)
|
155
163
|
Digest::SHA1.hexdigest(source_file.filename)
|
@@ -169,7 +177,16 @@ module Coverband
|
|
169
177
|
|
170
178
|
def link_to_source_file(source_file)
|
171
179
|
data_loader_url = "#{base_path}load_file_details?filename=#{source_file.filename}"
|
172
|
-
%(<a href="##{id source_file}" class="src_link" title="#{shortened_filename source_file}" data-loader-url="#{data_loader_url}" onclick="src_link_click(this)">#{shortened_filename
|
180
|
+
%(<a href="##{id source_file}" class="src_link" title="#{shortened_filename source_file}" data-loader-url="#{data_loader_url}" onclick="src_link_click(this)">#{truncate(shortened_filename(source_file))}</a>)
|
181
|
+
end
|
182
|
+
|
183
|
+
def truncate(text, length: 50)
|
184
|
+
if text.length <= length
|
185
|
+
text
|
186
|
+
else
|
187
|
+
omission = "..."
|
188
|
+
"#{text[0, length - omission.length]}#{omission}"
|
189
|
+
end
|
173
190
|
end
|
174
191
|
end
|
175
192
|
end
|
@@ -73,6 +73,19 @@ module Coverband
|
|
73
73
|
get_results(type).respond_to?(method)
|
74
74
|
end
|
75
75
|
|
76
|
+
# Note: small set of hacks for static html simplecov report (groups, created_at, & command_name)
|
77
|
+
def groups
|
78
|
+
@groups ||= {}
|
79
|
+
end
|
80
|
+
|
81
|
+
def created_at
|
82
|
+
@created_at ||= Time.now
|
83
|
+
end
|
84
|
+
|
85
|
+
def command_name
|
86
|
+
@command_name ||= "Coverband"
|
87
|
+
end
|
88
|
+
|
76
89
|
private
|
77
90
|
|
78
91
|
def get_eager_file(source_file)
|
@@ -191,7 +191,9 @@ module Coverband
|
|
191
191
|
end
|
192
192
|
|
193
193
|
def lines_strength
|
194
|
-
lines.
|
194
|
+
lines.sum do |line|
|
195
|
+
line.coverage || 0
|
196
|
+
end
|
195
197
|
end
|
196
198
|
|
197
199
|
def relevant_lines
|
@@ -256,8 +258,7 @@ module Coverband
|
|
256
258
|
# was at the start of the file name
|
257
259
|
# I had previously patched this in my local Rails app
|
258
260
|
def short_name
|
259
|
-
filename.
|
260
|
-
.gsub(%r{^\.\/}, "")
|
261
|
+
filename.delete_prefix("#{Coverband.configuration.root}/")
|
261
262
|
end
|
262
263
|
|
263
264
|
def relative_path
|
@@ -12,21 +12,100 @@ namespace :coverband do
|
|
12
12
|
FileUtils.cp(config_template, "./config/coverband.rb")
|
13
13
|
end
|
14
14
|
|
15
|
-
desc "report
|
15
|
+
desc "console formated report of Coverband code coverage"
|
16
16
|
task :coverage do
|
17
|
+
require "coverband/utils/html_formatter"
|
18
|
+
require "coverband/utils/result"
|
19
|
+
require "coverband/utils/file_list"
|
20
|
+
require "coverband/utils/source_file"
|
21
|
+
require "coverband/utils/lines_classifier"
|
22
|
+
require "coverband/utils/results"
|
17
23
|
Coverband::Reporters::ConsoleReport.report(Coverband.configuration.store)
|
18
24
|
end
|
19
25
|
|
20
|
-
|
21
|
-
|
26
|
+
desc "JSON formated report of Coverband code coverage"
|
27
|
+
task :coverage_json do
|
28
|
+
require "coverband/utils/html_formatter"
|
29
|
+
require "coverband/utils/result"
|
30
|
+
require "coverband/utils/file_list"
|
31
|
+
require "coverband/utils/source_file"
|
32
|
+
require "coverband/utils/lines_classifier"
|
33
|
+
require "coverband/utils/results"
|
34
|
+
require "coverband/reporters/json_report"
|
22
35
|
|
23
|
-
|
24
|
-
|
25
|
-
|
36
|
+
report = Coverband::Reporters::JSONReport.new(Coverband.configuration.store, {
|
37
|
+
for_merged_report: !!ENV["FOR_MERGED_REPORT"],
|
38
|
+
line_coverage: true
|
39
|
+
}).report
|
40
|
+
`mkdir -p coverage`
|
41
|
+
File.write("coverage/coverage.json.#{Time.now.to_f}", report)
|
42
|
+
end
|
43
|
+
|
44
|
+
###
|
45
|
+
# The Coverband UI now requires the dynamic rack server, however
|
46
|
+
# Coverband can still generate a SimpleCov compatible JSON report
|
47
|
+
# for use with the SimpleCov HTML formatter.
|
48
|
+
#
|
49
|
+
# To use this your project Gemfile must include simplecov and simplecov-html
|
50
|
+
# gem "simplecov", require: false
|
51
|
+
# gem "simplecov-html", require: false
|
52
|
+
# the file is written to coverage/index.html
|
53
|
+
###
|
54
|
+
desc "static HTML formated report of Coverband code coverage"
|
55
|
+
task :coverage_html do
|
56
|
+
require "coverband/utils/html_formatter"
|
57
|
+
require "coverband/utils/result"
|
58
|
+
require "coverband/utils/file_list"
|
59
|
+
require "coverband/utils/source_file"
|
60
|
+
require "coverband/utils/lines_classifier"
|
61
|
+
require "coverband/utils/results"
|
62
|
+
|
63
|
+
require "simplecov"
|
64
|
+
require "simplecov-html"
|
65
|
+
`mkdir -p coverage`
|
66
|
+
# For a fully static HTML that can be copied to artifacts are part of CI
|
67
|
+
# we generate with inline assets
|
68
|
+
ENV["SIMPLECOV_INLINE_ASSETS"] = "true"
|
69
|
+
coverband_reports = Coverband::Reporters::Base.report(Coverband.configuration.store)
|
70
|
+
Coverband::Reporters::Base.fix_reports(coverband_reports)
|
71
|
+
result = Coverband::Utils::Results.new(coverband_reports)
|
72
|
+
SimpleCov::Formatter::HTMLFormatter.new.format(result)
|
73
|
+
end
|
74
|
+
|
75
|
+
####
|
76
|
+
# This task can aggregate multiple coverage files into a single coverage report
|
77
|
+
# * `FOR_MERGED_REPORT=true bundle exec rake coverband:coverage_json` to generate the JSON files
|
78
|
+
# * collect all the files over time in some system or as artifacts in CI, then run...
|
79
|
+
# * `bundle exec rake coverband:aggregate_coverage` to merge the files
|
80
|
+
# * the output will include a timestamp of when it was output...
|
81
|
+
####
|
82
|
+
task :aggregate_coverage do |task, args|
|
83
|
+
require "coverband/utils/result"
|
84
|
+
require "coverband/utils/file_list"
|
85
|
+
require "coverband/utils/source_file"
|
86
|
+
require "coverband/utils/lines_classifier"
|
87
|
+
require "coverband/utils/results"
|
88
|
+
require "coverband/reporters/json_report"
|
89
|
+
|
90
|
+
directory = "./coverage"
|
91
|
+
pattern = "coverage.json*"
|
92
|
+
|
93
|
+
# Use Dir.glob to find files matching the pattern in the specified directory
|
94
|
+
files = Dir.glob(File.join(directory, pattern))
|
95
|
+
|
96
|
+
report = {}
|
97
|
+
files.each do |file|
|
98
|
+
data = JSON.parse(File.read(file))
|
99
|
+
report = if report.empty?
|
100
|
+
data
|
101
|
+
else
|
102
|
+
Coverband::Reporters::JSONReport.new(Coverband.configuration.store).merge_reports(report, data)
|
103
|
+
end
|
26
104
|
end
|
105
|
+
File.write("coverage/coverage_merged.json.#{Time.now.to_f}", report.to_json)
|
27
106
|
end
|
28
107
|
|
29
|
-
desc "report
|
108
|
+
desc "Run a simple rack app to report Coverband code coverage"
|
30
109
|
task :coverage_server do
|
31
110
|
if Rake::Task.task_defined?("environment")
|
32
111
|
Rake.application["environment"].invoke
|
@@ -38,6 +117,17 @@ namespace :coverband do
|
|
38
117
|
Port: ENV.fetch("COVERBAND_COVERAGE_PORT", 9022).to_i
|
39
118
|
end
|
40
119
|
|
120
|
+
# experimental dead method detection using RubyVM::AbstractSyntaxTree
|
121
|
+
# combined with the coverband coverage.
|
122
|
+
if defined?(RubyVM::AbstractSyntaxTree)
|
123
|
+
require "coverband/utils/dead_methods"
|
124
|
+
|
125
|
+
desc "Output all dead methods"
|
126
|
+
task :dead_methods do
|
127
|
+
Coverband::Utils::DeadMethods.output_all
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
41
131
|
###
|
42
132
|
# clear data helpful for development or after configuration issues
|
43
133
|
###
|
@@ -54,12 +144,4 @@ namespace :coverband do
|
|
54
144
|
trackers = Coverband.configuration.trackers
|
55
145
|
trackers.each(&:reset_recordings)
|
56
146
|
end
|
57
|
-
|
58
|
-
###
|
59
|
-
# Updates the data in the coverband store from one format to another
|
60
|
-
###
|
61
|
-
desc "upgrade previous Coverband datastore to latest format"
|
62
|
-
task :migrate do
|
63
|
-
Coverband.configuration.store.migrate!
|
64
|
-
end
|
65
147
|
end
|
data/lib/coverband/version.rb
CHANGED
data/lib/coverband.rb
CHANGED
@@ -5,7 +5,6 @@ require "json"
|
|
5
5
|
require "redis"
|
6
6
|
require "coverband/version"
|
7
7
|
require "coverband/at_exit"
|
8
|
-
require "coverband/configuration"
|
9
8
|
require "coverband/utils/relative_file_converter"
|
10
9
|
require "coverband/utils/absolute_file_converter"
|
11
10
|
require "coverband/adapters/base"
|
@@ -14,6 +13,7 @@ require "coverband/adapters/hash_redis_store"
|
|
14
13
|
require "coverband/adapters/file_store"
|
15
14
|
require "coverband/adapters/stdout_store"
|
16
15
|
require "coverband/adapters/null_store"
|
16
|
+
require "coverband/adapters/memcached_store"
|
17
17
|
require "coverband/utils/file_hasher"
|
18
18
|
require "coverband/collectors/coverage"
|
19
19
|
require "coverband/collectors/abstract_tracker"
|
@@ -26,6 +26,7 @@ require "coverband/reporters/console_report"
|
|
26
26
|
require "coverband/integrations/background"
|
27
27
|
require "coverband/integrations/background_middleware"
|
28
28
|
require "coverband/integrations/rack_server_check"
|
29
|
+
require "coverband/configuration"
|
29
30
|
|
30
31
|
Coverband::Adapters::RedisStore = Coverband::Adapters::HashRedisStore if ENV["COVERBAND_HASH_REDIS_STORE"]
|
31
32
|
|
@@ -51,7 +52,7 @@ module Coverband
|
|
51
52
|
elsif File.exist?(configuration_file)
|
52
53
|
load configuration_file
|
53
54
|
else
|
54
|
-
configuration.logger.debug("using default configuration")
|
55
|
+
configuration.logger.debug("using default configuration") if Coverband.configuration.verbose
|
55
56
|
end
|
56
57
|
@@configured = true
|
57
58
|
coverage_instance.reset_instance
|
@@ -116,6 +117,7 @@ module Coverband
|
|
116
117
|
start
|
117
118
|
end
|
118
119
|
require "coverband/integrations/resque" if defined? ::Resque
|
120
|
+
require "coverband/integrations/sidekiq_swarm" if defined? ::Sidekiq::Enterprise::Swarm
|
119
121
|
rescue Redis::CannotConnectError => error
|
120
122
|
Coverband.configuration.logger.info "Redis is not available (#{error}), Coverband not configured"
|
121
123
|
Coverband.configuration.logger.info "If this is a setup task like assets:precompile feel free to ignore"
|
@@ -4,7 +4,7 @@ require File.expand_path("../../test_helper", File.dirname(__FILE__))
|
|
4
4
|
|
5
5
|
class AdaptersBaseTest < Minitest::Test
|
6
6
|
def test_abstract_methods
|
7
|
-
abstract_methods = %w[clear! clear_file!
|
7
|
+
abstract_methods = %w[clear! clear_file! size save_coverage coverage]
|
8
8
|
abstract_methods.each do |method|
|
9
9
|
assert_raises RuntimeError do
|
10
10
|
Coverband::Adapters::Base.new.send(method.to_sym)
|
@@ -26,9 +26,6 @@ class AdaptersBaseTest < Minitest::Test
|
|
26
26
|
assert_equal [8, 11, nil, nil], Coverband::Adapters::Base.new.send(:array_add, latest, original)
|
27
27
|
Coverband.configuration.stubs(:use_oneshot_lines_coverage).returns(true)
|
28
28
|
assert_equal [1, 1, nil, nil], Coverband::Adapters::Base.new.send(:array_add, latest, original)
|
29
|
-
Coverband.configuration.stubs(:use_oneshot_lines_coverage).returns(false)
|
30
|
-
Coverband.configuration.stubs(:simulate_oneshot_lines_coverage).returns(true)
|
31
|
-
assert_equal [1, 1, nil, nil], Coverband::Adapters::Base.new.send(:array_add, latest, original)
|
32
29
|
end
|
33
30
|
|
34
31
|
describe "Coverband::Adapters::Base using file" do
|
@@ -192,57 +192,6 @@ class HashRedisStoreTest < Minitest::Test
|
|
192
192
|
assert_nil @store.get_coverage_report[:merged]["./dog.rb"]
|
193
193
|
end
|
194
194
|
|
195
|
-
def test_get_coverage_cache
|
196
|
-
@store = Coverband::Adapters::HashRedisStore.new(
|
197
|
-
@redis,
|
198
|
-
redis_namespace: "coverband_test",
|
199
|
-
relative_file_converter: MockRelativeFileConverter,
|
200
|
-
get_coverage_cache: true
|
201
|
-
)
|
202
|
-
@store.get_coverage_cache.stubs(:deferred_time).returns(0)
|
203
|
-
@store.get_coverage_cache.clear!
|
204
|
-
mock_file_hash
|
205
|
-
yesterday = DateTime.now.prev_day.to_time
|
206
|
-
mock_time(yesterday)
|
207
|
-
@store.save_report(
|
208
|
-
"app_path/dog.rb" => [0, 1, 2]
|
209
|
-
)
|
210
|
-
assert_equal(
|
211
|
-
{
|
212
|
-
"first_updated_at" => yesterday.to_i,
|
213
|
-
"last_updated_at" => yesterday.to_i,
|
214
|
-
"file_hash" => "abcd",
|
215
|
-
"data" => [0, 1, 2],
|
216
|
-
"timedata" => [nil, Time.at(yesterday.to_i), Time.at(yesterday.to_i)]
|
217
|
-
},
|
218
|
-
@store.coverage["./dog.rb"]
|
219
|
-
)
|
220
|
-
@store.save_report(
|
221
|
-
"app_path/dog.rb" => [0, 1, 2]
|
222
|
-
)
|
223
|
-
assert_equal(
|
224
|
-
{
|
225
|
-
"first_updated_at" => yesterday.to_i,
|
226
|
-
"last_updated_at" => yesterday.to_i,
|
227
|
-
"file_hash" => "abcd",
|
228
|
-
"data" => [0, 1, 2],
|
229
|
-
"timedata" => [nil, Time.at(yesterday.to_i), Time.at(yesterday.to_i)]
|
230
|
-
},
|
231
|
-
@store.coverage["./dog.rb"]
|
232
|
-
)
|
233
|
-
sleep 0.1 # wait caching thread finish
|
234
|
-
assert_equal(
|
235
|
-
{
|
236
|
-
"first_updated_at" => yesterday.to_i,
|
237
|
-
"last_updated_at" => yesterday.to_i,
|
238
|
-
"file_hash" => "abcd",
|
239
|
-
"data" => [0, 2, 4],
|
240
|
-
"timedata" => [nil, Time.at(yesterday.to_i), Time.at(yesterday.to_i)]
|
241
|
-
},
|
242
|
-
@store.coverage["./dog.rb"]
|
243
|
-
)
|
244
|
-
end
|
245
|
-
|
246
195
|
def test_split_coverage
|
247
196
|
@store = Coverband::Adapters::HashRedisStore.new(
|
248
197
|
@redis,
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("../../test_helper", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
if ENV["COVERBAND_MEMCACHED"]
|
6
|
+
require "active_support"
|
7
|
+
require "dalli"
|
8
|
+
|
9
|
+
class MemcachedTest < Minitest::Test
|
10
|
+
def setup
|
11
|
+
super
|
12
|
+
@store = Coverband::Adapters::MemcachedStore.new(ActiveSupport::Cache::MemCacheStore.new)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_coverage
|
16
|
+
@store.clear!
|
17
|
+
mock_file_hash
|
18
|
+
expected = basic_coverage
|
19
|
+
@store.save_report(expected)
|
20
|
+
assert_equal expected.keys, @store.coverage.keys
|
21
|
+
@store.coverage.each_pair do |key, data|
|
22
|
+
assert_equal expected[key], data["data"]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -79,14 +79,6 @@ unless ENV["COVERBAND_HASH_REDIS_STORE"]
|
|
79
79
|
assert_equal example_line, @store.coverage["app_path/dog.rb"]["data"]
|
80
80
|
end
|
81
81
|
|
82
|
-
def test_coverage_with_simulate_oneshot_lines_coverage
|
83
|
-
Coverband.configuration.stubs(:simulate_oneshot_lines_coverage).returns(true)
|
84
|
-
mock_file_hash
|
85
|
-
expected = basic_coverage
|
86
|
-
@store.save_report(expected)
|
87
|
-
assert_equal example_line, @store.get_coverage_report[:runtime]["app_path/dog.rb"]["data"]
|
88
|
-
end
|
89
|
-
|
90
82
|
def test_coverage_when_null
|
91
83
|
assert_nil @store.coverage["app_path/dog.rb"]
|
92
84
|
end
|
@@ -92,46 +92,4 @@ class CollectorsCoverageTest < Minitest::Test
|
|
92
92
|
::Coverage.expects(:resume)
|
93
93
|
Coverband::Collectors::Coverage.send(:new)
|
94
94
|
end
|
95
|
-
|
96
|
-
test "one shot line coverage disabled for ruby >= 2.6" do
|
97
|
-
return unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5.0")
|
98
|
-
::Coverage.expects(:respond_to?).returns(false)
|
99
|
-
|
100
|
-
Coverband::Collectors::Coverage.expects(:ruby_version_greater_than_or_equal_to?).with("2.6.0").returns(true)
|
101
|
-
::Coverage.expects(:running?).returns(false)
|
102
|
-
::Coverage.expects(:start).with(oneshot_lines: false)
|
103
|
-
Coverband::Collectors::Coverage.send(:new)
|
104
|
-
end
|
105
|
-
|
106
|
-
test "one shot line coverage enabled for ruby >= 2.6" do
|
107
|
-
return unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5.0")
|
108
|
-
::Coverage.expects(:respond_to?).returns(false)
|
109
|
-
|
110
|
-
Coverband.configuration.expects(:use_oneshot_lines_coverage).returns(true)
|
111
|
-
Coverband::Collectors::Coverage.expects(:ruby_version_greater_than_or_equal_to?).with("2.6.0").returns(true)
|
112
|
-
::Coverage.expects(:running?).returns(false)
|
113
|
-
::Coverage.expects(:start).with(oneshot_lines: true)
|
114
|
-
Coverband::Collectors::Coverage.send(:new)
|
115
|
-
end
|
116
|
-
|
117
|
-
test "one shot line coverage for ruby >= 2.6 when already running" do
|
118
|
-
return unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5.0")
|
119
|
-
::Coverage.expects(:respond_to?).returns(false)
|
120
|
-
|
121
|
-
Coverband::Collectors::Coverage.expects(:ruby_version_greater_than_or_equal_to?).with("2.6.0").returns(true)
|
122
|
-
::Coverage.expects(:running?).returns(true)
|
123
|
-
::Coverage.expects(:start).never
|
124
|
-
Coverband::Collectors::Coverage.send(:new)
|
125
|
-
end
|
126
|
-
|
127
|
-
test "no one shot line coverage for ruby < 2.6" do
|
128
|
-
return unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5.0")
|
129
|
-
::Coverage.expects(:respond_to?).returns(false)
|
130
|
-
|
131
|
-
Coverband::Collectors::Coverage.expects(:ruby_version_greater_than_or_equal_to?).with("2.6.0").returns(false)
|
132
|
-
Coverband::Collectors::Coverage.expects(:ruby_version_greater_than_or_equal_to?).with("2.5.0").returns(true)
|
133
|
-
::Coverage.expects(:running?).returns(false)
|
134
|
-
::Coverage.expects(:start).with
|
135
|
-
Coverband::Collectors::Coverage.send(:new)
|
136
|
-
end
|
137
95
|
end
|
@@ -92,35 +92,33 @@ class CollectorsDeltaTest < Minitest::Test
|
|
92
92
|
assert_equal({"car.rb" => [nil, 0, 2, 0]}, results)
|
93
93
|
end
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
}
|
95
|
+
test "oneshot coverage calls clear" do
|
96
|
+
Coverband.configuration.stubs(:use_oneshot_lines_coverage).returns(true)
|
97
|
+
current_coverage = {
|
98
|
+
"car.rb" => [1, 5]
|
99
|
+
}
|
101
100
|
|
102
|
-
|
103
|
-
|
104
|
-
|
101
|
+
::Coverage.expects(:result).with(clear: true, stop: false).returns(current_coverage)
|
102
|
+
Coverband::Collectors::Delta::RubyCoverage.results
|
103
|
+
end
|
105
104
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
105
|
+
test "one shot lines results" do
|
106
|
+
Coverband.configuration.stubs(:use_oneshot_lines_coverage).returns(true)
|
107
|
+
current_coverage = {}
|
108
|
+
results = Coverband::Collectors::Delta.results(mock_coverage(current_coverage))
|
109
|
+
assert_equal(current_coverage, results)
|
111
110
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
}
|
116
|
-
}
|
117
|
-
Coverband::Collectors::Delta.class_variable_set(:@@project_directory, "dealership.rb")
|
118
|
-
::Coverage.expects(:line_stub).with("dealership.rb").returns([nil, 0, 0, nil])
|
119
|
-
results = Coverband::Collectors::Delta.results(mock_coverage(current_coverage))
|
120
|
-
expected = {
|
121
|
-
"dealership.rb" => [nil, 1, 1, nil]
|
111
|
+
current_coverage = {
|
112
|
+
"dealership.rb" => {
|
113
|
+
oneshot_lines: [2, 3]
|
122
114
|
}
|
123
|
-
|
124
|
-
|
115
|
+
}
|
116
|
+
Coverband::Collectors::Delta.class_variable_set(:@@project_directory, "dealership.rb")
|
117
|
+
::Coverage.expects(:line_stub).with("dealership.rb").returns([nil, 0, 0, nil])
|
118
|
+
results = Coverband::Collectors::Delta.results(mock_coverage(current_coverage))
|
119
|
+
expected = {
|
120
|
+
"dealership.rb" => [nil, 1, 1, nil]
|
121
|
+
}
|
122
|
+
assert_equal(expected, results)
|
125
123
|
end
|
126
124
|
end
|
@@ -174,7 +174,7 @@ class RouterTrackerTest < Minitest::Test
|
|
174
174
|
method: "GET"
|
175
175
|
}
|
176
176
|
store.raw_store.expects(:del).with(tracker_key)
|
177
|
-
store.raw_store.expects(:del).with("
|
177
|
+
store.raw_store.expects(:del).with("#{tracker_key}_time")
|
178
178
|
tracker = Coverband::Collectors::RouteTracker.new(store: store, roots: "dir")
|
179
179
|
tracker.track_key(payload)
|
180
180
|
tracker.reset_recordings
|