covered 0.16.9 → 0.17.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
  SHA256:
3
- metadata.gz: c0eb7604139813f68b3d05cda0b32f4cc3cd4de049b7f383481cc7e849eb7a67
4
- data.tar.gz: 1129024c3c747e549da59b45acf8bfb426883385272295bf31dd0a7bb8331fcb
3
+ metadata.gz: d8f090b2435fd102d59fa7c4d7521c3175c63525a41a9031df94437186473d4d
4
+ data.tar.gz: 451c5de36ca41d1036a2114427bf06e52c558d70600a010da17253a5fce351e6
5
5
  SHA512:
6
- metadata.gz: 383bf343bf3fc1ab39cfe105da6e704c4818f75ccb85456b4d9f9d495021809d923287da9080a5385327c32f214ee51be3fc9e1d28b6573e49dd50e86e89b42d
7
- data.tar.gz: 9ad476c9ac2882eeefa12981b183ebb30015fa4b68f377ad41bb67d453d2d7f498145eefe9cfe54a12955d524290868f1b946323166fcf1c21f8525148ca6bbe
6
+ metadata.gz: d69196d6806beed48922c14cd215182fee51319a95e1484f43ab3132d7c71d6caadf058a1391859d80d0830a3c0d52708ff3f96b202fa9fc2107f804eedf9126
7
+ data.tar.gz: 79fbd2fef4c24c606b8534ae55a95dd42a33db25b975a8dd1370f553d2d19876ad71ee5734a8c7c1958c93687631d925d0c714a3c49d53adf3629463a1e38478
checksums.yaml.gz.sig CHANGED
Binary file
@@ -43,10 +43,10 @@ module Covered
43
43
  super
44
44
  end
45
45
 
46
- def execute(path, source, binding: TOPLEVEL_BINDING)
46
+ def execute(source, binding: TOPLEVEL_BINDING)
47
47
  enable
48
48
 
49
- eval(source, binding, path)
49
+ eval(source.code!, binding, source.path)
50
50
  ensure
51
51
  disable
52
52
  end
@@ -21,8 +21,38 @@ module Covered
21
21
  end
22
22
 
23
23
  class Coverage
24
- def initialize(path, counts = [])
25
- @path = path
24
+ Source = Struct.new(:path, :code, :line_offset) do
25
+ def to_s
26
+ "\#<#{self.class} path=#{path}>"
27
+ end
28
+
29
+ def read(&block)
30
+ if block_given?
31
+ File.open(self.path, "r", &block)
32
+ else
33
+ File.read(self.path)
34
+ end
35
+ end
36
+
37
+ def code!
38
+ self.code || self.read
39
+ end
40
+
41
+ def code?
42
+ !!self.code
43
+ end
44
+ end
45
+
46
+ def self.source(path, code = nil, line_offset = 1)
47
+ Source.new(path, code, line_offset)
48
+ end
49
+
50
+ def self.for(path, code = nil, line_offset = 1)
51
+ self.new(Source.new(path, code, line_offset))
52
+ end
53
+
54
+ def initialize(source, counts = [])
55
+ @source = source
26
56
  @counts = counts
27
57
  @total = 0
28
58
 
@@ -32,18 +62,19 @@ module Covered
32
62
  @executed_lines = nil
33
63
  end
34
64
 
35
- attr :path
65
+ def path
66
+ @source.path
67
+ end
68
+
69
+ attr_accessor :source
70
+
36
71
  attr :counts
37
72
  attr :total
38
73
 
39
74
  attr :annotations
40
75
 
41
76
  def read(&block)
42
- if block_given?
43
- File.open(@path, "r", &block)
44
- else
45
- File.read(@path)
46
- end
77
+ @source.read(&block)
47
78
  end
48
79
 
49
80
  def freeze
data/lib/covered/files.rb CHANGED
@@ -23,15 +23,15 @@ module Covered
23
23
  end
24
24
 
25
25
  def mark(path, lineno, value)
26
- coverage = (@paths[path] ||= Coverage.new(path))
26
+ coverage = (@paths[path] ||= Coverage.for(path))
27
27
 
28
28
  coverage.mark(lineno, value)
29
29
 
30
30
  return coverage
31
31
  end
32
32
 
33
- def add(path, source = nil)
34
- @paths[path] ||= Coverage.new(path)
33
+ def add(source)
34
+ @paths[source.path] ||= Coverage.new(source)
35
35
  end
36
36
 
37
37
  def each(&block)
@@ -73,7 +73,7 @@ module Covered
73
73
  end
74
74
 
75
75
  paths.each do |path|
76
- yield Coverage.new(path)
76
+ yield Coverage.for(path)
77
77
  end
78
78
  end
79
79
  end
@@ -40,7 +40,11 @@ module Covered
40
40
  end
41
41
  end
42
42
 
43
- record[:coverage].each_with_index do |count, index|
43
+ if source = record[:source]
44
+ @output.add(source)
45
+ end
46
+
47
+ record[:counts].each_with_index do |count, index|
44
48
  @output.mark(path, index, count) if count
45
49
  end
46
50
  end
@@ -49,8 +53,9 @@ module Covered
49
53
  {
50
54
  # We want to use relative paths so that moving the repo won't break everything:
51
55
  path: relative_path(coverage.path),
52
- coverage: coverage.counts,
53
56
  mtime: File.mtime(coverage.path).to_f,
57
+ counts: coverage.counts,
58
+ source: coverage.source,
54
59
  }
55
60
  end
56
61
 
@@ -128,6 +133,9 @@ module Covered
128
133
  packer = MessagePack::Packer.new(io)
129
134
  packer.register_type(0x00, Symbol, :to_msgpack_ext)
130
135
  packer.register_type(0x01, Time) {|object| object.to_s}
136
+ packer.register_type(0x0F, Coverage::Source) do |object|
137
+ object.to_a.to_msgpack
138
+ end
131
139
 
132
140
  return packer
133
141
  end
@@ -136,6 +144,9 @@ module Covered
136
144
  unpacker = MessagePack::Unpacker.new(io)
137
145
  unpacker.register_type(0x00, Symbol, :from_msgpack_ext)
138
146
  unpacker.register_type(0x01, Time, :parse)
147
+ unpacker.register_type(0x0F) do |data|
148
+ Coverage::Source.new(*MessagePack.unpack(data))
149
+ end
139
150
 
140
151
  return unpacker
141
152
  end
@@ -11,16 +11,9 @@ require 'parser/current'
11
11
  module Covered
12
12
  # The source map, loads the source file, parses the AST to generate which lines contain executable code.
13
13
  class Source < Wrapper
14
- Script = Struct.new(:path, :source, :line_offset)
15
-
16
14
  def initialize(output)
17
15
  super(output)
18
16
 
19
- @paths = {}
20
- @mutex = Mutex.new
21
-
22
- @annotations = {}
23
-
24
17
  begin
25
18
  @trace = TracePoint.new(:script_compiled) do |trace|
26
19
  instruction_sequence = trace.instruction_sequence
@@ -28,10 +21,8 @@ module Covered
28
21
  # We only track source files which begin at line 1, as these represent whole files instead of monkey patches.
29
22
  if instruction_sequence.first_lineno <= 1
30
23
  # Extract the source path and source itself and save it for later:
31
- if path = instruction_sequence.path and source = trace.eval_script
32
- @mutex.synchronize do
33
- @paths[path] = Script.new(path, source, instruction_sequence.first_lineno)
34
- end
24
+ if path = instruction_sequence.path and script = trace.eval_script
25
+ self.add(Coverage::Source.new(path, script, instruction_sequence.first_lineno))
35
26
  end
36
27
  end
37
28
  end
@@ -135,30 +126,31 @@ module Covered
135
126
  end
136
127
  end
137
128
 
138
- def add(path, source = nil)
129
+ def add(source)
139
130
  if coverage = super
140
- top = Parser::CurrentRuby.parse(source)
141
- self.expand(top, coverage)
131
+ if top = self.parse(source)
132
+ self.expand(top, coverage)
133
+ end
142
134
  end
143
135
 
144
136
  return coverage
145
137
  end
146
138
 
147
- def parse(path)
148
- if script = @paths[path]
149
- Parser::CurrentRuby.parse(script.source, script.path, script.line_offset)
150
- elsif File.exist?(path)
139
+ def parse(source)
140
+ if source.code?
141
+ Parser::CurrentRuby.parse(source.code, source.path, source.line_offset)
142
+ elsif path = source.path and File.exist?(path)
151
143
  Parser::CurrentRuby.parse_file(path)
152
144
  else
153
145
  # warn "Couldn't parse #{path}, file doesn't exist?"
154
146
  end
155
147
  rescue
156
- warn "Couldn't parse #{path}: #{$!}"
148
+ warn "Couldn't parse #{source}: #{$!}"
157
149
  end
158
150
 
159
151
  def each(&block)
160
152
  @output.each do |coverage|
161
- if top = parse(coverage.path)
153
+ if top = parse(coverage.source)
162
154
  self.expand(top, coverage)
163
155
  end
164
156
 
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2018-2022, by Samuel Williams.
5
5
 
6
6
  module Covered
7
- VERSION = "0.16.9"
7
+ VERSION = "0.17.0"
8
8
  end
@@ -21,7 +21,7 @@ module Covered
21
21
  def mark(path, lineno, value)
22
22
  end
23
23
 
24
- def add(path, source = nil)
24
+ def add(source)
25
25
  end
26
26
 
27
27
  def each
@@ -63,8 +63,8 @@ module Covered
63
63
  @output.mark(path, lineno, value)
64
64
  end
65
65
 
66
- def add(path, source = nil)
67
- @output.add(path, source = nil)
66
+ def add(source)
67
+ @output.add(source)
68
68
  end
69
69
 
70
70
  # @yield [Coverage] the path to the file, and the execution counts.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: covered
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.9
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -41,7 +41,7 @@ cert_chain:
41
41
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
42
42
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
43
43
  -----END CERTIFICATE-----
44
- date: 2022-09-19 00:00:00.000000000 Z
44
+ date: 2022-09-20 00:00:00.000000000 Z
45
45
  dependencies:
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: async-rest
metadata.gz.sig CHANGED
Binary file