covered 0.12.0 → 0.13.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b72bc8a2cb3795c9b240f61f4d65f2d147f4c9ce63115200b6900c0c176f4a7
4
- data.tar.gz: 1e450d66f9dff150c7538a4e29586bb6dc10a3983ad11d7cf4ea0dcd625045aa
3
+ metadata.gz: 207e7d403aa0d5e2e726aea8b87afd7632e951b874d5fea251af9dc8e979b064
4
+ data.tar.gz: 0e3a010f8cade8119c2b8bfd55556a984208b99cb7b529181f537de3ddf351df
5
5
  SHA512:
6
- metadata.gz: 0fb3b30a00cb9b69e7400ba155576aa2cea483b1a9324f2b3b90201ad54ed742006a11843cff57b5e5d9e641793719ccb5f97206355f5d73e03b47af581b1565
7
- data.tar.gz: a315a3cd4553e4468283317fe2745746e359bcde354469783f6a0686c0befb97c16f32a9620591d03569d0dbd6d38f5f140052f0c80294c794ced806539aa354
6
+ metadata.gz: 371e5d865b5cc02ffc87f3b457e1b8243d24a56965022482a3fb9c86d7a2a1485ba899b72e012132cd274699a247d19f9d477b71780fd378d11fb52431009690
7
+ data.tar.gz: fb7be0ffc88ddbe8ad9d5fd2e8bfb09efff89f1d91edef63e4b5d52e6f17b3d1881d5cb0ae0563bffa4e8c221c7bfadaf9bdbb1bc208480290ad860bd0ff74e5
data/covered.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "rainbow"
21
+ spec.add_dependency "event", "~> 1.5"
22
22
  spec.add_dependency "parser"
23
23
  spec.add_dependency "msgpack"
24
24
 
@@ -21,7 +21,7 @@
21
21
  require_relative 'statistics'
22
22
  require_relative 'wrapper'
23
23
 
24
- require 'rainbow'
24
+ require 'event/terminal'
25
25
 
26
26
  module Covered
27
27
  class Summary
@@ -29,6 +29,24 @@ module Covered
29
29
  @threshold = threshold
30
30
  end
31
31
 
32
+ def terminal(output)
33
+ Event::Terminal.for(output).tap do |terminal|
34
+ terminal[:path] ||= terminal.style(nil, nil, :bold, :underline)
35
+ terminal[:brief_path] ||= terminal.style(:yellow)
36
+
37
+ terminal[:uncovered_prefix] ||= terminal.style(:red)
38
+ terminal[:covered_prefix] ||= terminal.style(:green)
39
+ terminal[:ignored_prefix] ||= terminal.style(nil, nil, :faint)
40
+ terminal[:header_prefix] ||= terminal.style(nil, nil, :faint)
41
+
42
+ terminal[:uncovered_code] ||= terminal.style(:red)
43
+ terminal[:covered_code] ||= terminal.style(:green)
44
+ terminal[:ignored_code] ||= terminal.style(nil, nil, :faint)
45
+
46
+ terminal[:annotations] ||= terminal.style(:blue)
47
+ end
48
+ end
49
+
32
50
  def each(wrapper)
33
51
  statistics = Statistics.new
34
52
 
@@ -43,49 +61,64 @@ module Covered
43
61
  return statistics
44
62
  end
45
63
 
46
- def print_annotations(output, coverage, line, line_offset)
64
+ def print_annotations(terminal, coverage, line, line_offset)
47
65
  if annotations = coverage.annotations[line_offset]
48
- output.write("#{line_offset}|".rjust(8))
49
- output.write("*|".rjust(8))
66
+ prefix = "#{line_offset}|".rjust(8) + "*|".rjust(8)
67
+ terminal.write prefix, style: :ignored_prefix
50
68
 
51
- output.write line.match(/^\s+/)
52
- output.write '# '
53
-
54
- output.puts Rainbow(annotations.join(", ")).bright
69
+ terminal.write line.match(/^\s+/)
70
+ terminal.puts "\# #{annotations.join(", ")}", style: :annotations
71
+ end
72
+ end
73
+
74
+ def print_line_header(terminal)
75
+ prefix = "Line|".rjust(8) + "Hits|".rjust(8)
76
+
77
+ terminal.puts prefix, style: :header_prefix
78
+ end
79
+
80
+ def print_line(terminal, line, line_offset, count)
81
+ prefix = "#{line_offset}|".rjust(8) + "#{count}|".rjust(8)
82
+
83
+ if count == nil
84
+ terminal.write prefix, style: :ignored_prefix
85
+ terminal.write line, style: :ignored_code
86
+ elsif count == 0
87
+ terminal.write prefix, style: :uncovered_prefix
88
+ terminal.write line, style: :uncovered_code
89
+ else
90
+ terminal.write prefix, style: :covered_prefix
91
+ terminal.write line, style: :covered_code
92
+ end
93
+
94
+ # If there was no newline at end of file, we add one:
95
+ unless line.end_with? $/
96
+ terminal.puts
55
97
  end
56
98
  end
57
99
 
58
100
  # A coverage array gives, for each line, the number of line execution by the interpreter. A nil value means coverage is disabled for this line (lines like else and end).
59
101
  def call(wrapper, output = $stdout)
102
+ terminal = self.terminal(output)
103
+
60
104
  statistics = self.each(wrapper) do |coverage|
61
105
  line_offset = 1
62
106
 
63
107
  path = wrapper.relative_path(coverage.path)
64
- output.puts "", Rainbow(path).bold.underline
108
+ terminal.puts ""
109
+ terminal.puts path, style: :path
65
110
 
66
111
  counts = coverage.counts
67
112
 
68
113
  coverage.read do |file|
114
+ print_line_header(terminal)
115
+
69
116
  file.each_line do |line|
70
117
  count = counts[line_offset]
71
118
 
72
- print_annotations(output, coverage, line, line_offset)
73
-
74
- output.write("#{line_offset}|".rjust(8))
75
- output.write("#{count}|".rjust(8))
119
+ print_annotations(terminal, coverage, line, line_offset)
76
120
 
77
- if count == nil
78
- output.write Rainbow(line).faint
79
- elsif count == 0
80
- output.write Rainbow(line).red
81
- else
82
- output.write Rainbow(line).green
83
- end
84
-
85
- # If there was no newline at end of file, we add one:
86
- unless line.end_with? $/
87
- output.puts
88
- end
121
+ print_line(terminal, line, line_offset, count)
89
122
 
90
123
  line_offset += 1
91
124
  end
@@ -100,24 +133,26 @@ module Covered
100
133
 
101
134
  class BriefSummary < Summary
102
135
  def call(wrapper, output = $stdout, before: 4, after: 4)
136
+ terminal = self.terminal(output)
137
+
103
138
  ordered = []
104
139
 
105
140
  statistics = self.each(wrapper) do |coverage|
106
141
  ordered << coverage unless coverage.complete?
107
142
  end
108
143
 
109
- output.puts
144
+ terminal.puts
110
145
  statistics.print(output)
111
146
 
112
147
  if ordered.any?
113
- output.puts "", "Least Coverage:"
148
+ terminal.puts "", "Least Coverage:"
114
149
  ordered.sort_by!(&:missing_count).reverse!
115
150
 
116
151
  ordered.first(5).each do |coverage|
117
152
  path = wrapper.relative_path(coverage.path)
118
153
 
119
- output.write Rainbow(path).orange
120
- output.puts ": #{coverage.missing_count} lines not executed!"
154
+ terminal.write path, style: :brief_path
155
+ terminal.puts ": #{coverage.missing_count} lines not executed!"
121
156
  end
122
157
  end
123
158
  end
@@ -125,16 +160,21 @@ module Covered
125
160
 
126
161
  class PartialSummary < Summary
127
162
  def call(wrapper, output = $stdout, before: 4, after: 4)
163
+ terminal = self.terminal(output)
164
+
128
165
  statistics = self.each(wrapper) do |coverage|
129
166
  line_offset = 1
130
167
 
131
168
  path = wrapper.relative_path(coverage.path)
132
- output.puts "", Rainbow(path).bold.underline
169
+ terminal.puts ""
170
+ terminal.puts path, style: :path
133
171
 
134
172
  counts = coverage.counts
135
173
  last_line = nil
136
174
 
137
175
  unless coverage.zero?
176
+ print_line_header(terminal)
177
+
138
178
  coverage.read do |file|
139
179
  file.each_line do |line|
140
180
  range = Range.new([line_offset - before, 0].max, line_offset+after)
@@ -143,28 +183,11 @@ module Covered
143
183
  count = counts[line_offset]
144
184
 
145
185
  if last_line and last_line != line_offset-1
146
- output.puts ":".rjust(16)
186
+ terminal.puts ":".rjust(16)
147
187
  end
148
188
 
149
- print_annotations(output, coverage, line, line_offset)
150
-
151
- prefix = "#{line_offset}|".rjust(8) + "#{count}|".rjust(8)
152
-
153
- if count == nil
154
- output.write prefix
155
- output.write Rainbow(line).faint
156
- elsif count == 0
157
- output.write Rainbow(prefix).background(:darkred)
158
- output.write Rainbow(line).red
159
- else
160
- output.write Rainbow(prefix).background(:darkgreen)
161
- output.write Rainbow(line).green
162
- end
163
-
164
- # If there was no newline at end of file, we add one:
165
- unless line.end_with? $/
166
- output.puts
167
- end
189
+ print_annotations(terminal, coverage, line, line_offset)
190
+ print_line(terminal, line, line_offset, count)
168
191
 
169
192
  last_line = line_offset
170
193
  end
@@ -177,7 +200,7 @@ module Covered
177
200
  coverage.print(output)
178
201
  end
179
202
 
180
- output.puts
203
+ terminal.puts
181
204
  statistics.print(output)
182
205
  end
183
206
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Covered
22
- VERSION = "0.12.0"
22
+ VERSION = "0.13.0"
23
23
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: covered
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-14 00:00:00.000000000 Z
11
+ date: 2019-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rainbow
14
+ name: event
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: parser
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  - !ruby/object:Gem::Version
193
193
  version: '0'
194
194
  requirements: []
195
- rubygems_version: 3.0.2
195
+ rubygems_version: 3.0.3
196
196
  signing_key:
197
197
  specification_version: 4
198
198
  summary: A modern approach to code coverage.