coverband 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +60 -84
- data/Rakefile +7 -0
- data/changes.md +20 -4
- data/config.ru +4 -0
- data/coverband.gemspec +0 -1
- data/lib/coverband/adapters/memory_cache_store.rb +16 -16
- data/lib/coverband/collectors/base.rb +1 -1
- data/lib/coverband/collectors/coverage.rb +8 -7
- data/lib/coverband/collectors/trace.rb +17 -7
- data/lib/coverband/configuration.rb +1 -1
- data/lib/coverband/reporters/base.rb +2 -2
- data/lib/coverband/reporters/web.rb +152 -0
- data/lib/coverband/s3_report_writer.rb +1 -0
- data/lib/coverband/tasks.rb +0 -46
- data/lib/coverband/version.rb +1 -1
- data/lib/coverband.rb +1 -1
- data/test/test_helper.rb +0 -5
- data/test/unit/adapters_memory_cache_store_test.rb +40 -30
- data/test/unit/collectors_base_test.rb +3 -1
- data/test/unit/collectors_coverage_test.rb +3 -3
- data/test/unit/collectors_trace_test.rb +3 -1
- data/test/unit/reports_web_test.rb +37 -0
- metadata +6 -22
- data/lib/coverband/baseline.rb +0 -44
- data/lib/coverband/s3_web.rb +0 -62
- data/test/unit/baseline_test.rb +0 -59
- data/test/unit/s3_web_test.rb +0 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d053a25d6140b3254fe2d2f1afa6a92fc06f0d3e
|
|
4
|
+
data.tar.gz: 069d15a21f7c2909fcdcb7a2f955fecc2daef168
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b4dfdbe5797949ab92ac9ec869f4fb4776162b0c681427436733fa4bbc4bdf4bf02be159559e8e1baf613704ecc8044256cd21e8dca3d6f3f575be00e7908f7
|
|
7
|
+
data.tar.gz: de454d222f4545cd6db08d9043fe97a1d5aa71aa339c5c0b9b6cd5694d252cb344fca4183a6cb55c30e052a709ff251de9ebeb2d1e2c79d2572594faa3e1411f
|
data/.gitignore
CHANGED
data/README.md
CHANGED
|
@@ -4,11 +4,13 @@ Build Status: [.
|
|
@@ -17,24 +19,31 @@ Note: Coverband is not intended for test code coverage, for that just check out
|
|
|
17
19
|
|
|
18
20
|
## Key Features
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
The primary goal of Coverband is giving deep insight into your production runtime usage of your application code, while having the least impact on performance possible.
|
|
23
|
+
|
|
24
|
+
* Low performance overhead
|
|
25
|
+
* Various controls from sampling, data collection rate, etc to further control performance
|
|
21
26
|
* Ignore directories to avoid overhead data collection on vendor, lib, etc.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
27
|
+
* Development mode, offers deep insight of code usage details (number of LOC execution during single request, etc) during development.
|
|
28
|
+
* Easy setup for any Ruby Rack based web framework (Rails, Sinatra, etc)
|
|
29
|
+
* Allows for integration with any other Ruby application flows (background jobs, crons, scripts)
|
|
30
|
+
|
|
31
|
+
## Coverband Demo
|
|
32
|
+
|
|
33
|
+
Take Coverband for a spin on the live Heroku deployed [Coverband Demo](https://coverband-demo.herokuapp.com/). The [full source code for the demo](https://github.com/danmayer/coverband_demo) is available to help with configuration and understanding of basic usage.
|
|
24
34
|
|
|
25
35
|
# How To Use
|
|
26
36
|
|
|
27
37
|
Below is my Coverband workflow, which hopefully will help other best use this library.
|
|
28
38
|
|
|
29
|
-
* install coverband
|
|
30
|
-
*
|
|
31
|
-
* validate
|
|
39
|
+
* install coverband
|
|
40
|
+
* start your app and hit a few endpoints
|
|
41
|
+
* validate data collection and code coverage with `rake coverband:coverage`
|
|
32
42
|
* test setup in development (hit endpoints and generate new report)
|
|
33
43
|
* deploy to staging and verify functionality
|
|
34
44
|
* deploy to production and verify functionality
|
|
35
|
-
* every 2 weeks or with major releases
|
|
45
|
+
* every 2 weeks or so, with major releases
|
|
36
46
|
* clear old coverage: `rake coverband:clear`
|
|
37
|
-
* take new baseline: `rake coverband:baseline`
|
|
38
47
|
* deploy and verify coverage is matching expectations
|
|
39
48
|
* __COVERAGE DRIFT__
|
|
40
49
|
* if you never clear you have lines of code drift from when they were recorded
|
|
@@ -138,8 +147,7 @@ require 'coverband/tasks'
|
|
|
138
147
|
This should give you access to a number of Coverband tasks
|
|
139
148
|
|
|
140
149
|
```bash
|
|
141
|
-
|
|
142
|
-
rake coverband:baseline # record coverband coverage baseline
|
|
150
|
+
rake -T coverband
|
|
143
151
|
rake coverband:clear # reset coverband coverage data
|
|
144
152
|
rake coverband:coverage # report runtime coverband code coverage
|
|
145
153
|
```
|
|
@@ -194,10 +202,10 @@ run ActionController::Dispatcher.new
|
|
|
194
202
|
|
|
195
203
|
# Verify Correct Installation
|
|
196
204
|
|
|
197
|
-
*
|
|
198
|
-
* run `
|
|
205
|
+
* boot up your application
|
|
206
|
+
* run `rake coverband:coverage` this will show app initialization coverage
|
|
199
207
|
* run app and hit a controller (hit at least +1 time over your `config.startup_delay` setting default is 0)
|
|
200
|
-
* run `
|
|
208
|
+
* run `rake coverband:coverage` and you should see coverage increasing for the endpoints you hit.
|
|
201
209
|
|
|
202
210
|
## Installation Script
|
|
203
211
|
|
|
@@ -220,7 +228,7 @@ bundle install
|
|
|
220
228
|
|
|
221
229
|
# Make some code so we can look at the coverage
|
|
222
230
|
rails generate scaffold blogs
|
|
223
|
-
|
|
231
|
+
rake db:migrate
|
|
224
232
|
|
|
225
233
|
# open Rakefile, add lines
|
|
226
234
|
require 'coverband'
|
|
@@ -233,10 +241,9 @@ rake -T coverband
|
|
|
233
241
|
# configure config/application.rb
|
|
234
242
|
# copy lines from readme
|
|
235
243
|
|
|
236
|
-
|
|
237
|
-
rake coverband:baseline
|
|
244
|
+
# start up your app
|
|
238
245
|
rake coverband:coverage
|
|
239
|
-
# view
|
|
246
|
+
# view boot up coverage
|
|
240
247
|
|
|
241
248
|
rails s
|
|
242
249
|
|
|
@@ -256,68 +263,14 @@ rake coverband:coverage
|
|
|
256
263
|
- [Sinatra app](https://github.com/danmayer/churn-site)
|
|
257
264
|
- [Non Rack Ruby app](https://github.com/danmayer/coverband_examples)
|
|
258
265
|
|
|
259
|
-
### Coverband Baseline
|
|
260
|
-
|
|
261
|
-
__TLDR:__ Baseline is app initialization coverage, not captured during runtime.
|
|
262
|
-
|
|
263
|
-
Before starting a service verify your baseline by running `rake coverband:baseline` followed by `rake coverband:coverage` to view what your baseline coverage looks like before any runtime traffic has been recorded.
|
|
264
|
-
|
|
265
|
-
The baseline seems to cause some confusion. Basically, when Coverband records code usage, it will not request initial startup code like method definition, it covers what it hit during run time. This would produce a fairly odd view of code usage. To cover things like defining routes, dynamic methods, and the like Coverband records a baseline. The baseline should capture coverage of app initialization and boot up, we don't want to do this on deploy as it can be slow. So we take a recording of boot up as a one time baseline Rake task `bundle exec rake coverband:baseline`.
|
|
266
|
-
|
|
267
|
-
1. Start your server with `rails s` or `rackup config.ru`.
|
|
268
|
-
2. Hit your development server exercising the endpoints you want to verify Coverband is recording (you should see debug outputs in your server console)
|
|
269
|
-
3. Run `rake coverband:coverage` again, previously it should have only shown the baseline data of your app initializing. After using it in development it should show increased coverage from the actions you have exercised.
|
|
270
|
-
|
|
271
|
-
Note: if you use `rails s` and data isn't recorded, make sure it is using your `config.ru`.
|
|
272
|
-
|
|
273
|
-
### Baseline Missing data
|
|
274
|
-
|
|
275
|
-
The default Coverband baseline task will try to detect your app as either Rack or Rails environment. It will load the app to take a baseline reading. The baseline coverage is important because some code is executed during app load, but might not be invoked during any requests, think prefetching, initial cache builds, setting constants, etc. If the baseline task doesn't load your app well you can override the default baseline to create a better baseline yourself. Below for example is how I take a baseline on a pretty simple Sinatra app.
|
|
276
|
-
|
|
277
|
-
```ruby
|
|
278
|
-
namespace :coverband do
|
|
279
|
-
desc "get coverage baseline"
|
|
280
|
-
task :baseline_app do
|
|
281
|
-
Coverband::Reporter.baseline {
|
|
282
|
-
require 'sinatra'
|
|
283
|
-
require './app.rb'
|
|
284
|
-
}
|
|
285
|
-
end
|
|
286
|
-
end
|
|
287
|
-
```
|
|
288
|
-
|
|
289
266
|
### View Coverage
|
|
290
267
|
|
|
291
268
|
You can view the report different ways, but the easiest is the Rake task which opens the SimpleCov formatted HTML.
|
|
292
269
|
|
|
293
|
-
`
|
|
270
|
+
`rake coverband:coverage`
|
|
294
271
|
|
|
295
272
|
This should auto-open in your browser, but if it doesn't the output file should be in `coverage/index.html`
|
|
296
273
|
|
|
297
|
-
### Conflicting .Simplecov: Issue with Missing or 0% Coverage Report
|
|
298
|
-
|
|
299
|
-
If you use SimpleCov to generate code coverage for your tests. You might have setup a `.simplecov` file to help control and focus it's output. Often the settings you want for your test's code coverage report are different than what you want Coverband to be reporting on. Since Coverband uses the SimpleCov HTML formatter to prepare it's report.
|
|
300
|
-
|
|
301
|
-
So if you had something like this in a `.simplecov` file in the root of your project, as reported in [issue 83](https://github.com/danmayer/coverband/issues/83)
|
|
302
|
-
|
|
303
|
-
```
|
|
304
|
-
require 'simplecov'
|
|
305
|
-
|
|
306
|
-
SimpleCov.start do
|
|
307
|
-
add_filter 'app/admin'
|
|
308
|
-
add_filter '/spec/'
|
|
309
|
-
add_filter '/config/'
|
|
310
|
-
add_filter '/vendor/'
|
|
311
|
-
add_filter 'userevents'
|
|
312
|
-
end
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
You could see some confusing results... To avoid this issue Coverband has a Rake task that will ignore all Simplecov filters.
|
|
316
|
-
|
|
317
|
-
`rake coverband:coverage_no_filters`
|
|
318
|
-
|
|
319
|
-
This will build the report after disabling any `.simplecov` applied settings.
|
|
320
|
-
|
|
321
274
|
### Clear Coverage
|
|
322
275
|
|
|
323
276
|
If your code has changed and your coverage line data doesn't seem to match run time. You probably need to clear your old line data... You will need to run this in the environment you wish to clear the data from.
|
|
@@ -525,7 +478,7 @@ Beyond writing to S3 you can host the S3 file with a build in Sintatra app in Co
|
|
|
525
478
|
```
|
|
526
479
|
Rails.application.routes.draw do
|
|
527
480
|
# ... lots of routes
|
|
528
|
-
mount Coverband::
|
|
481
|
+
mount Coverband::Reporters::Web.new, at: '/coverage'
|
|
529
482
|
end
|
|
530
483
|
```
|
|
531
484
|
|
|
@@ -554,11 +507,35 @@ end
|
|
|
554
507
|
Rails.application.routes.draw do
|
|
555
508
|
# ... lots of routes
|
|
556
509
|
constraints basic_constraint do
|
|
557
|
-
mount Coverband::
|
|
510
|
+
mount Coverband::Reporters::Web.new, at: '/coverage'
|
|
558
511
|
end
|
|
559
512
|
end
|
|
560
513
|
```
|
|
561
514
|
|
|
515
|
+
### Conflicting .Simplecov: Issue with Missing or 0% Coverage Report
|
|
516
|
+
|
|
517
|
+
If you use SimpleCov to generate code coverage for your tests. You might have setup a `.simplecov` file to help control and focus it's output. Often the settings you want for your test's code coverage report are different than what you want Coverband to be reporting on. Since Coverband uses the SimpleCov HTML formatter to prepare it's report.
|
|
518
|
+
|
|
519
|
+
So if you had something like this in a `.simplecov` file in the root of your project, as reported in [issue 83](https://github.com/danmayer/coverband/issues/83)
|
|
520
|
+
|
|
521
|
+
```
|
|
522
|
+
require 'simplecov'
|
|
523
|
+
|
|
524
|
+
SimpleCov.start do
|
|
525
|
+
add_filter 'app/admin'
|
|
526
|
+
add_filter '/spec/'
|
|
527
|
+
add_filter '/config/'
|
|
528
|
+
add_filter '/vendor/'
|
|
529
|
+
add_filter 'userevents'
|
|
530
|
+
end
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
You could see some confusing results... To avoid this issue Coverband has a Rake task that will ignore all Simplecov filters.
|
|
534
|
+
|
|
535
|
+
`rake coverband:coverage_no_filters`
|
|
536
|
+
|
|
537
|
+
This will build the report after disabling any `.simplecov` applied settings.
|
|
538
|
+
|
|
562
539
|
# Contributing To Coverband
|
|
563
540
|
|
|
564
541
|
If you are working on adding features, PRs, or bugfixes to Coverband this section should help get you going.
|
|
@@ -567,24 +544,24 @@ If you are working on adding features, PRs, or bugfixes to Coverband this sectio
|
|
|
567
544
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
568
545
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
569
546
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
570
|
-
5. Make sure all tests are passing (run `bundle install`, make sure Redis is running, and then execute `
|
|
547
|
+
5. Make sure all tests are passing (run `bundle install`, make sure Redis is running, and then execute `rake test`)
|
|
571
548
|
6. Create new Pull Request
|
|
572
549
|
|
|
573
550
|
### Tests & Benchmarks
|
|
574
551
|
|
|
575
552
|
If you submit a change please make sure the tests and benchmarks are passing.
|
|
576
553
|
|
|
577
|
-
* run tests: `
|
|
554
|
+
* run tests: `rake`
|
|
578
555
|
* view test coverage: `open coverage/index.html`
|
|
579
556
|
* run the benchmarks before and after your change to see impact
|
|
580
|
-
* `
|
|
557
|
+
* `rake benchmarks`
|
|
581
558
|
|
|
582
559
|
### Known Issues
|
|
583
560
|
|
|
584
561
|
* __total fail__ on front end code, because of the precompiled template step basically coverage doesn't work well for `erb`, `slim`, and the like.
|
|
585
562
|
* related it will try to report something, but the line numbers reported for `ERB` files are often off and aren't considered useful. I recommend filtering out .erb using the `config.ignore` option.
|
|
586
563
|
* If you have SimpleCov filters, you need to clear them prior to generating your coverage report. As the filters will be applied to Coverband as well and can often filter out everything we are recording.
|
|
587
|
-
* coverage doesn't show for Rails `config/application.rb` or `config/boot.rb` as they get loaded when loading the Rake environment prior to starting
|
|
564
|
+
* coverage doesn't show for Rails `config/application.rb` or `config/boot.rb` as they get loaded when loading the Rake environment prior to starting the `Coverage` library.
|
|
588
565
|
|
|
589
566
|
### Debugging Redis Store
|
|
590
567
|
|
|
@@ -655,20 +632,19 @@ Similar format to redis store, but array with integer values
|
|
|
655
632
|
|
|
656
633
|
### Todo
|
|
657
634
|
|
|
658
|
-
*
|
|
635
|
+
* add articles / podcasts like prontos readme https://github.com/prontolabs/pronto
|
|
659
636
|
* graphite adapters (it would allow passing in date ranges on usage)
|
|
660
637
|
* perf test for array vs hash
|
|
661
638
|
* redis pipeline around hash (or batch get then push)
|
|
662
|
-
* pass in namespace to redis (coverage vs baseline)
|
|
663
|
-
* what about having baseline a onetime recording into redis no merge later
|
|
664
639
|
* move to SimpleCov console out, or make similar console tabular output
|
|
665
|
-
*
|
|
640
|
+
* Improve network performance by logging to files that purge later (like NR) (far more time lost in TracePoint than sending files, hence not a high priority, but would be cool)
|
|
666
641
|
* Add support for [zadd](http://redis.io/topics/data-types-intro) so one could determine single call versus multiple calls on a line, letting us determine the most executed code in production.
|
|
667
642
|
* Possibly add ability to record code run for a given route
|
|
643
|
+
* integrate recording with deploy tag or deploy timestamp
|
|
644
|
+
* diff code usage across deployed versions
|
|
668
645
|
* Improve client code api, around manual usage of sampling (like event usage)
|
|
669
646
|
* ability to change the Coverband config at runtime by changing the config pushed to the Redis hash. In memory cache around the changes to only make that call periodically.
|
|
670
647
|
* Opposed to just showing code usage on a route allow 'tagging' events which would record line coverage for that tag (this would allow tagging all code that modified an ActiveRecord model for example
|
|
671
|
-
* mountable rack app to view coverage similar to flipper-ui
|
|
672
648
|
* support runner, active job, etc without needed extra config (improved railtie integration)
|
|
673
649
|
|
|
674
650
|
# Resources
|
data/Rakefile
CHANGED
|
@@ -19,3 +19,10 @@ desc 'load irb with this gem'
|
|
|
19
19
|
task :console do
|
|
20
20
|
exec 'irb -I lib -r coverband'
|
|
21
21
|
end
|
|
22
|
+
|
|
23
|
+
# This is really just for testing and development because without configuration
|
|
24
|
+
# Coverband can't do much
|
|
25
|
+
desc 'start webserver'
|
|
26
|
+
task :server do
|
|
27
|
+
exec 'rackup -I lib'
|
|
28
|
+
end
|
data/changes.md
CHANGED
|
@@ -14,17 +14,33 @@ Will be the fully modern release that drops maintenance legacy support in favor
|
|
|
14
14
|
* built in support for activejob, sidekiq, and other common frameworks
|
|
15
15
|
* code route tracing (entry point to all code executed for example /some_path -> code coverage of that path)
|
|
16
16
|
|
|
17
|
+
# Alpha
|
|
18
|
+
|
|
19
|
+
### ???
|
|
20
|
+
|
|
21
|
+
|
|
17
22
|
# Released
|
|
18
23
|
|
|
24
|
+
### 2.0.2
|
|
25
|
+
|
|
26
|
+
* fix possible nil error on files that changed since initial recording @viktor-silakov
|
|
27
|
+
* add improve error logging in verbose mode (stacktrace) @viktor-silakov
|
|
28
|
+
* improved logging level support @viktor-silakov
|
|
29
|
+
* launch Coverband demo and integrate into Readme / Documentation
|
|
30
|
+
* fix on baseline to show an issue by @viktor-silakov
|
|
31
|
+
* remove all coverband:baseline related features and documentation
|
|
32
|
+
* dropped Sinatra requirement for web mountable page
|
|
33
|
+
* fixes to the MemoryCacheStore by @kbaum
|
|
34
|
+
|
|
19
35
|
### 2.0.1
|
|
20
36
|
|
|
21
37
|
* add support for fine grained S3 configuration via Coverband config, thanks @a0s
|
|
22
|
-
* https://github.com/danmayer/coverband/pull/98
|
|
38
|
+
* https://github.com/danmayer/coverband/pull/98
|
|
23
39
|
* Using the file argument to self.configure in lib/coverband.rb, thanks @ThomasOwens
|
|
24
40
|
* https://github.com/danmayer/coverband/pull/100
|
|
25
|
-
* added redis improvements allowing namespace and TTL thx @oded-zahavi
|
|
26
|
-
* fix warnings about duplicate method definition
|
|
27
|
-
* Add support for safe_reload_files based on full file path
|
|
41
|
+
* added redis improvements allowing namespace and TTL thx @oded-zahavi
|
|
42
|
+
* fix warnings about duplicate method definition
|
|
43
|
+
* Add support for safe_reload_files based on full file path
|
|
28
44
|
* Add support for Sinatra admin control endpoints
|
|
29
45
|
* improved documentation
|
|
30
46
|
|
data/config.ru
ADDED
data/coverband.gemspec
CHANGED
|
@@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
|
|
|
26
26
|
spec.add_development_dependency 'rack'
|
|
27
27
|
spec.add_development_dependency 'rack-test'
|
|
28
28
|
spec.add_development_dependency 'rake'
|
|
29
|
-
spec.add_development_dependency 'sinatra'
|
|
30
29
|
spec.add_development_dependency 'test-unit'
|
|
31
30
|
spec.add_development_dependency 'redis'
|
|
32
31
|
spec.add_development_dependency 'benchmark-ips'
|
|
@@ -9,16 +9,18 @@ module Coverband
|
|
|
9
9
|
class MemoryCacheStore < Base
|
|
10
10
|
attr_accessor :store
|
|
11
11
|
|
|
12
|
+
@@files_cache = {}
|
|
13
|
+
|
|
12
14
|
def initialize(store)
|
|
13
15
|
@store = store
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
def self.
|
|
17
|
-
files_cache.clear
|
|
18
|
+
def self.clear!
|
|
19
|
+
@@files_cache.clear
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
def clear!
|
|
21
|
-
self.class.
|
|
23
|
+
self.class.clear!
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
def save_report(files)
|
|
@@ -26,28 +28,26 @@ module Coverband
|
|
|
26
28
|
store.save_report(filtered_files) if filtered_files.any?
|
|
27
29
|
end
|
|
28
30
|
|
|
29
|
-
# rubocop:disable Lint/IneffectiveAccessModifier
|
|
30
31
|
private
|
|
31
32
|
|
|
32
|
-
def self.files_cache
|
|
33
|
-
@files_cache ||= {}
|
|
34
|
-
end
|
|
35
|
-
|
|
36
33
|
def files_cache
|
|
37
|
-
|
|
34
|
+
@@files_cache
|
|
38
35
|
end
|
|
39
36
|
|
|
40
37
|
def filter(files)
|
|
41
|
-
files.each_with_object({}) do |(file,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
line_cache.include?(line) ? true : (line_cache << line && false)
|
|
38
|
+
files.each_with_object({}) do |(file, covered_lines), filtered_file_hash|
|
|
39
|
+
if covered_lines != cached_file(file)
|
|
40
|
+
files_cache[file] = covered_lines
|
|
41
|
+
filtered_file_hash[file] = covered_lines
|
|
46
42
|
end
|
|
47
|
-
filtered_file_hash[file] = lines if lines.any?
|
|
48
43
|
end
|
|
49
44
|
end
|
|
50
|
-
|
|
45
|
+
|
|
46
|
+
def cached_file(file)
|
|
47
|
+
files_cache[file] ||= store.covered_lines_for_file(file).each_with_object({}) do |(line_number, value), hash|
|
|
48
|
+
hash[line_number.to_i] = value.to_i
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
end
|
|
@@ -87,7 +87,7 @@ module Coverband
|
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
def output_file_line_usage
|
|
90
|
-
@logger.
|
|
90
|
+
@logger.debug 'coverband debug coverband file:line usage:'
|
|
91
91
|
@file_line_usage.sort_by { |_key, value| value.length }.each do |pair|
|
|
92
92
|
file = pair.first
|
|
93
93
|
lines = pair.last
|
|
@@ -18,7 +18,7 @@ module Coverband
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
if failed_recently?
|
|
21
|
-
@logger.
|
|
21
|
+
@logger.error 'coverage reporting standing-by because of recent failure' if @verbose
|
|
22
22
|
return
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -31,7 +31,7 @@ module Coverband
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
if @verbose
|
|
34
|
-
@logger.
|
|
34
|
+
@logger.debug "coverband file usage: #{file_usage.inspect}"
|
|
35
35
|
output_file_line_usage if @verbose == 'debug'
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -39,8 +39,8 @@ module Coverband
|
|
|
39
39
|
@store.save_report(@file_line_usage)
|
|
40
40
|
@file_line_usage.clear
|
|
41
41
|
elsif @verbose
|
|
42
|
-
@logger.
|
|
43
|
-
@logger.
|
|
42
|
+
@logger.debug 'coverage report: '
|
|
43
|
+
@logger.debug @file_line_usage.inspect
|
|
44
44
|
end
|
|
45
45
|
# StandardError might be better option
|
|
46
46
|
# coverband previously had RuntimeError here
|
|
@@ -49,15 +49,16 @@ module Coverband
|
|
|
49
49
|
rescue StandardError => err
|
|
50
50
|
failed!
|
|
51
51
|
if @verbose
|
|
52
|
-
@logger.
|
|
53
|
-
@logger.
|
|
52
|
+
@logger.error 'coverage missing'
|
|
53
|
+
@logger.error "error: #{err.inspect} #{err.message}"
|
|
54
|
+
@logger.error err.backtrace
|
|
54
55
|
end
|
|
55
56
|
end
|
|
56
57
|
|
|
57
58
|
private
|
|
58
59
|
|
|
59
60
|
def array_diff(latest, original)
|
|
60
|
-
latest.map.with_index { |v, i| v ? v - original[i] : nil }
|
|
61
|
+
latest.map.with_index { |v, i| (v && original[i]) ? v - original[i] : nil }
|
|
61
62
|
end
|
|
62
63
|
|
|
63
64
|
def previous_results
|
|
@@ -2,8 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
module Coverband
|
|
4
4
|
module Collectors
|
|
5
|
+
###
|
|
6
|
+
# NOTE: While this still works it is slower than Coverage.
|
|
7
|
+
# I recommend using the Coverage adapter.
|
|
8
|
+
# As baseline is removed the Trace collector also doesn't have a good way
|
|
9
|
+
# to collect initial code usage during app boot up.
|
|
10
|
+
#
|
|
11
|
+
# I am leaving Trace around as I believe there are some interesting use cases
|
|
12
|
+
# also, it illustrates an alternative collector, and I have some others I would like to implement
|
|
13
|
+
###
|
|
5
14
|
class Trace < Base
|
|
6
|
-
|
|
7
15
|
def reset_instance
|
|
8
16
|
super
|
|
9
17
|
@tracer_set = false
|
|
@@ -21,8 +29,9 @@ module Coverband
|
|
|
21
29
|
rescue RuntimeError => err
|
|
22
30
|
failed!
|
|
23
31
|
if @verbose
|
|
24
|
-
@logger.
|
|
25
|
-
@logger.
|
|
32
|
+
@logger.error 'error stating recording coverage'
|
|
33
|
+
@logger.error "error: #{err.inspect} #{err.message}"
|
|
34
|
+
@logger.error err.backtrace
|
|
26
35
|
end
|
|
27
36
|
end
|
|
28
37
|
|
|
@@ -39,12 +48,12 @@ module Coverband
|
|
|
39
48
|
unset_tracer
|
|
40
49
|
|
|
41
50
|
if failed_recently?
|
|
42
|
-
@logger.
|
|
51
|
+
@logger.error 'coverage reporting standing-by because of recent failure' if @verbose
|
|
43
52
|
return
|
|
44
53
|
end
|
|
45
54
|
|
|
46
55
|
if @verbose
|
|
47
|
-
@logger.
|
|
56
|
+
@logger.debug "coverband file usage: #{file_usage.inspect}"
|
|
48
57
|
output_file_line_usage if @verbose == 'debug'
|
|
49
58
|
end
|
|
50
59
|
|
|
@@ -58,8 +67,9 @@ module Coverband
|
|
|
58
67
|
rescue RuntimeError => err
|
|
59
68
|
failed!
|
|
60
69
|
if @verbose
|
|
61
|
-
@logger.
|
|
62
|
-
@logger.
|
|
70
|
+
@logger.error 'coverage missing'
|
|
71
|
+
@logger.error "error: #{err.inspect} #{err.message}"
|
|
72
|
+
@logger.error err.backtrace
|
|
63
73
|
end
|
|
64
74
|
end
|
|
65
75
|
|
|
@@ -71,7 +71,7 @@ module Coverband
|
|
|
71
71
|
@store = Coverband::Adapters::RedisStore.new(redis, ttl: Coverband.configuration.redis_ttl,
|
|
72
72
|
redis_namespace: Coverband.configuration.redis_namespace)
|
|
73
73
|
elsif store.is_a?(String)
|
|
74
|
-
@store = Coverband::Adapters::FileStore.new(
|
|
74
|
+
@store = Coverband::Adapters::FileStore.new(store)
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
end
|
|
@@ -9,13 +9,13 @@ module Coverband
|
|
|
9
9
|
|
|
10
10
|
if Coverband.configuration.verbose
|
|
11
11
|
Coverband.configuration.logger.info "fixing root: #{roots.join(', ')}"
|
|
12
|
-
Coverband.configuration.logger.
|
|
12
|
+
Coverband.configuration.logger.debug "additional data:\n #{additional_coverage_data}"
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
scov_style_report = report_scov_with_additional_data(store, additional_coverage_data, roots)
|
|
16
16
|
|
|
17
17
|
if Coverband.configuration.verbose
|
|
18
|
-
Coverband.configuration.logger.
|
|
18
|
+
Coverband.configuration.logger.debug "report:\n #{scov_style_report.inspect}"
|
|
19
19
|
end
|
|
20
20
|
scov_style_report
|
|
21
21
|
end
|