coverband 1.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8438c95988521edfcb5911828e1b75b4a83d625
4
- data.tar.gz: 8a92bc7880429005fb1ba837b273e4968bda8a7d
3
+ metadata.gz: 596cbfbecac5e0b49abfb79b09b10a8b68913c48
4
+ data.tar.gz: 340cbd1d66d93036dfa88ba2ea28072862bb26a6
5
5
  SHA512:
6
- metadata.gz: 78922ea8ccdad5cc0b71ff9096d5e2928777b3ba58156bb3a637c46fe5fd43faa011d9f575e193c380209eebdf1920cd29cb3c958167f1d262dd830b92f2d782
7
- data.tar.gz: b75a40fac79fb36c18bed97bb4f6f8e345ad94c21204d003ddc5cc03f25846ea6265b86b026e07bbe655b4ee999799e89fc265c4e143070128215dfde2c9c8c4
6
+ metadata.gz: 7d12ac9b92ca27079ceef0cac971295f85808f2b4ca75f6ed8e150f1bc4302012402ab6be91c8084ce1ac5e46182eea4bce921d1fee448117203179532866480
7
+ data.tar.gz: bec658051aa2b3f324e8b5aa0d04bf5d1a4a163dda65cbe2304f78c924fe8c7837657f057a4cfd248d3aa9016c0b94c282f6f8e9fa525d2050123e98c1f35223
@@ -1,4 +1,5 @@
1
1
  require 'singleton'
2
+ require 'set'
2
3
 
3
4
  module Coverband
4
5
  class Base
@@ -38,9 +39,8 @@ module Coverband
38
39
  @project_directory = File.expand_path(Coverband.configuration.root)
39
40
  @enabled = false
40
41
  @tracer_set = false
41
- @files = {}
42
- @file_usage = Hash.new(0)
43
42
  @file_line_usage = {}
43
+ @ignored_files = Set.new
44
44
  @startup_delay = Coverband.configuration.startup_delay
45
45
  @ignore_patterns = Coverband.configuration.ignore + ["internal:prelude"]
46
46
  @ignore_patterns += ['gems'] unless Coverband.configuration.include_gems
@@ -88,13 +88,8 @@ module Coverband
88
88
 
89
89
  unset_tracer
90
90
 
91
- @files.reject!{|file, lines| !track_file?(file) }
92
-
93
- #make lines uniq
94
- @files.each{|file, lines| lines.uniq!}
95
-
96
91
  if @verbose
97
- @logger.info "coverband file usage: #{@file_usage.sort_by {|_key, value| value}.inspect}"
92
+ @logger.info "coverband file usage: #{file_usage.inspect}"
98
93
  if @verbose=="debug"
99
94
  output_file_line_usage
100
95
  end
@@ -103,21 +98,17 @@ module Coverband
103
98
  if @reporter
104
99
  if @stats
105
100
  @before_time = Time.now
106
- @stats.count "coverband.files.recorded_files", @files.length
101
+ @stats.count "coverband.files.recorded_files", @file_line_usage.length
107
102
  end
108
- @reporter.store_report(@files)
103
+ @reporter.store_report(@file_line_usage)
109
104
  if @stats
110
105
  @time_spent = Time.now - @before_time
111
106
  @stats.timing "coverband.files.recorded_time", @time_spent
112
107
  end
113
- @files.clear
114
- if @verbose
115
- @file_usage.clear
116
- @file_line_usage.clear
117
- end
108
+ @file_line_usage.clear
118
109
  elsif @verbose
119
110
  @logger.info "coverage report: "
120
- @logger.info @files.inspect
111
+ @logger.info @file_line_usage.inspect
121
112
  end
122
113
  rescue RuntimeError => err
123
114
  if @verbose
@@ -156,18 +147,30 @@ module Coverband
156
147
 
157
148
  private
158
149
 
150
+ def file_usage
151
+ hash = {}
152
+ @file_line_usage.each do |file, lines|
153
+ hash[file] = lines.values.inject(0, :+)
154
+ end
155
+ hash.sort_by {|_key, value| value}
156
+ end
157
+
158
+ def add_file(file, line)
159
+ @file_line_usage[file] = Hash.new(0) unless @file_line_usage.include?(file)
160
+ @file_line_usage[file][line] += 1
161
+ end
162
+
159
163
  def create_trace_point
160
164
  TracePoint.new(*Coverband.configuration.trace_point_events) do |tp|
161
165
  if Thread.current == @current_thread
162
166
  file = tp.path
163
- line = tp.lineno
164
- if @verbose
165
- @file_usage[file] += 1
166
- @file_line_usage[file] = Hash.new(0) unless @file_line_usage.include?(file)
167
- @file_line_usage[file][line] += 1
167
+ if !@ignored_files.include?(file)
168
+ if track_file?(file)
169
+ add_file(file, tp.lineno)
170
+ else
171
+ @ignored_files << file
172
+ end
168
173
  end
169
- file_lines = (@files[file] ||= [])
170
- file_lines.push(line) unless file_lines.include?(line)
171
174
  end
172
175
  end
173
176
  end
@@ -10,7 +10,7 @@ module Coverband
10
10
  store_array('coverband', report.keys)
11
11
 
12
12
  report.each do |file, lines|
13
- store_array("coverband.#{file}", lines)
13
+ store_array("coverband.#{file}", lines.keys)
14
14
  end
15
15
  end
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module Coverband
2
- VERSION = "1.2"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -75,7 +75,7 @@ class BaseTest < Test::Unit::TestCase
75
75
  coverband.instance_variable_set("@verbose", true)
76
76
  store = Coverband::RedisStore.new(Redis.new)
77
77
  coverband.instance_variable_set("@reporter", store)
78
- store.expects(:store_report).once.with(has_entries(dog_file => [3]) )
78
+ store.expects(:store_report).once.with(has_entries(dog_file => { 3 => 5 }) )
79
79
  assert_equal false, coverband.instance_variable_get("@enabled")
80
80
  coverband.start
81
81
  5.times { Dog.new.bark }
@@ -83,12 +83,12 @@ class BaseTest < Test::Unit::TestCase
83
83
  coverband.save
84
84
  end
85
85
 
86
- test "tracer should collect uniq line numbers" do
86
+ test "tracer should count line numbers" do
87
87
  dog_file = File.expand_path('./dog.rb', File.dirname(__FILE__))
88
88
  coverband = Coverband::Base.instance.reset_instance
89
89
  coverband.start
90
90
  100.times { Dog.new.bark }
91
- assert_equal 1, coverband.instance_variable_get("@files")[dog_file].select{ |i| 3 == i }.count
91
+ assert_equal 100, coverband.instance_variable_get("@file_line_usage")[dog_file][3]
92
92
  coverband.stop
93
93
  coverband.save
94
94
  end
@@ -9,12 +9,14 @@ module Coverband
9
9
  @memory_store = MemoryCacheStore.new(@store)
10
10
  end
11
11
 
12
+ def data
13
+ {
14
+ 'file1' => { 3 => 1, 5 => 2 },
15
+ 'file2' => { 1 => 1, 2 => 1 }
16
+ }
17
+ end
12
18
 
13
19
  test 'it passes data into store' do
14
- data = {
15
- 'file1' => [ 3, 5 ],
16
- 'file2' => [1, 2]
17
- }
18
20
  @store.expects(:store_report).with data
19
21
  @store.expects(:covered_lines_for_file).with('file1').returns []
20
22
  @store.expects(:covered_lines_for_file).with('file2').returns []
@@ -22,10 +24,6 @@ module Coverband
22
24
  end
23
25
 
24
26
  test 'it passes data into store only once' do
25
- data = {
26
- 'file1' => [ 3, 5 ],
27
- 'file2' => [1, 2]
28
- }
29
27
  @store.expects(:store_report).once.with data
30
28
  @store.expects(:covered_lines_for_file).with('file1').returns []
31
29
  @store.expects(:covered_lines_for_file).with('file2').returns []
@@ -33,32 +31,24 @@ module Coverband
33
31
  end
34
32
 
35
33
  test 'it only passes files and lines we have not hit yet' do
36
- first_data = {
37
- 'file1' => [ 3, 5 ],
38
- 'file2' => [1, 2]
39
- }
40
34
  second_data = {
41
- 'file1' => [ 3, 5, 10 ],
42
- 'file2' => [1, 2]
35
+ 'file1' => { 3 => 1, 5 => 1, 10 => 1 },
36
+ 'file2' => { 1 => 1, 2 => 1 }
43
37
  }
44
38
  @store.expects(:covered_lines_for_file).with('file1').returns []
45
39
  @store.expects(:covered_lines_for_file).with('file2').returns []
46
- @store.expects(:store_report).once.with first_data
40
+ @store.expects(:store_report).once.with data
47
41
  @store.expects(:store_report).once.with(
48
- 'file1' => [10]
42
+ 'file1' => { 10 => 1 }
49
43
  )
50
- @memory_store.store_report first_data
44
+ @memory_store.store_report data
51
45
  @memory_store.store_report second_data
52
46
  end
53
47
 
54
48
  test 'it initializes cache with what is in store' do
55
- data = {
56
- 'file1' => [ 3, 5 ],
57
- 'file2' => [1, 2]
58
- }
59
49
  @store.expects(:covered_lines_for_file).with('file1').returns [3,5]
60
50
  @store.expects(:covered_lines_for_file).with('file2').returns [2]
61
- @store.expects(:store_report).with( 'file2' => [1] )
51
+ @store.expects(:store_report).with('file2' => { 1 => 1 })
62
52
  @memory_store.store_report data
63
53
  end
64
54
 
@@ -22,8 +22,8 @@ class RedisTest < Test::Unit::TestCase
22
22
 
23
23
  def test_data
24
24
  {
25
- "/Users/danmayer/projects/cover_band_server/app.rb"=>[54, 55],
26
- "/Users/danmayer/projects/cover_band_server/server.rb"=>[5]
25
+ "/Users/danmayer/projects/cover_band_server/app.rb" => { 54 => 1, 55 => 2 },
26
+ "/Users/danmayer/projects/cover_band_server/server.rb" => { 5 => 1 }
27
27
  }
28
28
  end
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coverband
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Mayer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-12 00:00:00.000000000 Z
11
+ date: 2016-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler