covered 0.10.5 → 0.11.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: 3e3b91d1e1b95b11caade1f15c09cff1e0e9e0d198f7b742fd46ff59b465e83f
4
- data.tar.gz: d367447379742fee41271f512b9e9b0388c53655ecc985c167ba58b0defdd7b3
3
+ metadata.gz: 58f32d0b3917b373713212f99cec0a6d205ce16c46f744169a202d284eb413e7
4
+ data.tar.gz: b66f5175e13cacaed2a454f5d3e8449c04971fbbdfdf15fa28cf3ab46486ae0c
5
5
  SHA512:
6
- metadata.gz: '0926c0a0b461e11dd6a4abf83c24dd5c0250241c607aabd114fdb20aae3a1fae1e4d4b96483cc8be68a20053eb48d761e5a5b3b99fd5a4ea44a1890a8ac496dc'
7
- data.tar.gz: 3d69f523f37c5591a07aa8f0d51eb26bb6c1884efb859c3be203fe31d28811bd959c9befa1df2e6275ace7382cee4adc63dabac6befcfc51a22a0c3e4477d754
6
+ metadata.gz: eb761996f33000c60701075e727573303710ec5fde4639021788860c38942c899f889b4d6c8f05124dc7b1b3e1320c0bb59b4ce048695e87ca885b90d917404b
7
+ data.tar.gz: 2b3efafdd32173f24d8b4b57ca26ce2b1cad85a800be76ae79af319da680efb08c6fcadef795b5db8baa002fb6344001556878954745c7ed8fa2fc0a179206cb
@@ -0,0 +1,11 @@
1
+
2
+ ENV['COVERAGE'] ||= 'PartialSummary'
3
+ require 'covered/policy/default'
4
+
5
+ $covered.enable
6
+
7
+ require_relative 'test'
8
+
9
+ $covered.disable
10
+
11
+ $covered.call($stdout)
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pry'
4
+ require 'parser/current'
5
+
6
+ ast = Parser::CurrentRuby.parse_file('test.rb')
7
+ # ast.location.expression.source
8
+
9
+ def print_methods(ast)
10
+ if ast.is_a? Parser::AST::Node
11
+ if ast.type == :send
12
+ puts "Calling #{ast.children[1]} on #{ast.location.line}"
13
+ end
14
+
15
+ ast.children.each do |child|
16
+ print_methods(child)
17
+ end
18
+ end
19
+ end
20
+
21
+ print_methods(ast)
22
+
23
+ binding.pry
@@ -0,0 +1,7 @@
1
+
2
+ require 'simplecov'
3
+
4
+ SimpleCov.command_name 'Example'
5
+ SimpleCov.start
6
+
7
+ require_relative 'test'
@@ -0,0 +1,8 @@
1
+
2
+ puts "Hello World"
3
+
4
+ all_the_things = []
5
+
6
+ if all_the_things.any?
7
+ puts "I've got all the things"
8
+ end
@@ -0,0 +1,9 @@
1
+
2
+
3
+ trace_point = TracePoint.new(:call, :line) do |trace|
4
+ puts [trace.path, trace.lineno].join(":")
5
+ end
6
+
7
+ trace_point.enable
8
+
9
+ require_relative 'test'
@@ -27,7 +27,7 @@ module Covered
27
27
  def initialize(output)
28
28
  super(output)
29
29
 
30
- @trace = TracePoint.new(:line, :call) do |event|
30
+ @trace = TracePoint.new(:line, :call, :c_call) do |event|
31
31
  if path = event.path
32
32
  @output.mark(path, event.lineno, 1)
33
33
  end
@@ -26,7 +26,9 @@ require 'set'
26
26
 
27
27
  module Covered
28
28
  class Persist < Wrapper
29
- def initialize(output, path = ".covered.msgpack")
29
+ DEFAULT_PATH = ".covered.db"
30
+
31
+ def initialize(output, path = DEFAULT_PATH)
30
32
  super(output)
31
33
 
32
34
  @path = path
@@ -18,17 +18,19 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
+ require_relative '../policy'
22
+
21
23
  $covered = Covered.policy do
22
24
  cache!
23
25
 
24
26
  # Only files in the root would be tracked:
25
- root Dir.pwd
27
+ root(Dir.pwd)
26
28
 
27
29
  # We will ignore any files in the test or spec directory:
28
- skip /^.*\/(test|spec|vendor)\//
30
+ skip(/^.*\/(test|spec|vendor)\//)
29
31
 
30
32
  # We will include all files under lib, even if they aren't loaded:
31
- include "lib/**/*.rb"
33
+ include("lib/**/*.rb")
32
34
 
33
35
  persist!
34
36
 
@@ -18,11 +18,9 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require_relative 'eval'
22
21
  require_relative 'wrapper'
23
22
 
24
23
  require 'thread'
25
-
26
24
  require 'parser/current'
27
25
 
28
26
  module Covered
@@ -35,30 +33,34 @@ module Covered
35
33
  @mutex = Mutex.new
36
34
 
37
35
  @annotations = {}
36
+
37
+ begin
38
+ @trace = TracePoint.new(:script_compiled) do |event|
39
+ if path = event.instruction_sequence&.path and source = event.eval_script
40
+ @mutex.synchronize do
41
+ @paths[path] = source
42
+ end
43
+ end
44
+ end
45
+ rescue ArgumentError
46
+ @trace = nil
47
+ end
38
48
  end
39
49
 
40
50
  def enable
41
51
  super
42
52
 
43
- Eval::enable(self)
53
+ @trace&.enable
44
54
  end
45
55
 
46
56
  def disable
47
- Eval::disable(self)
57
+ @trace&.disable
48
58
 
49
59
  super
50
60
  end
51
61
 
52
62
  attr :paths
53
63
 
54
- def intercept_eval(string, binding = nil, filename = nil, lineno = 1)
55
- return unless filename
56
-
57
- @mutex.synchronize do
58
- @paths[filename] = string
59
- end
60
- end
61
-
62
64
  def executable?(node)
63
65
  node.type == :send
64
66
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Covered
22
- VERSION = "0.10.5"
22
+ VERSION = "0.11.0"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: covered
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.5
4
+ version: 0.11.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-02-03 00:00:00.000000000 Z
11
+ date: 2019-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -151,11 +151,15 @@ files:
151
151
  - README.md
152
152
  - Rakefile
153
153
  - covered.gemspec
154
+ - examples/coverage/covered.rb
155
+ - examples/coverage/parser.rb
156
+ - examples/coverage/simplecov.rb
157
+ - examples/coverage/test.rb
158
+ - examples/coverage/tracepoint.rb
154
159
  - lib/covered.rb
155
160
  - lib/covered/capture.rb
156
161
  - lib/covered/coverage.rb
157
162
  - lib/covered/coveralls.rb
158
- - lib/covered/eval.rb
159
163
  - lib/covered/files.rb
160
164
  - lib/covered/minitest.rb
161
165
  - lib/covered/persist.rb
data/lib/covered/eval.rb DELETED
@@ -1,78 +0,0 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'thread'
22
-
23
- module Covered
24
- module Eval
25
- @mutex = Mutex.new
26
- @handler = nil
27
-
28
- def self.enable(handler)
29
- @mutex.synchronize do
30
- @handler = handler
31
- end
32
- end
33
-
34
- def self.disable(handler)
35
- @mutex.synchronize do
36
- @handler = nil
37
- end
38
- end
39
-
40
- def self.intercept_eval(*args)
41
- @mutex.synchronize do
42
- @handler.intercept_eval(*args) if @handler
43
- end
44
- end
45
- end
46
- end
47
-
48
- module Kernel
49
- class << self
50
- alias_method :__eval__, :eval
51
-
52
- def eval(*args)
53
- Covered::Eval.intercept_eval(*args)
54
-
55
- __eval__(*args)
56
- end
57
- end
58
-
59
- private
60
-
61
- alias_method :__eval__, :eval
62
-
63
- def eval(*args)
64
- Covered::Eval.intercept_eval(*args)
65
-
66
- __eval__(*args)
67
- end
68
- end
69
-
70
- class Binding
71
- alias_method :__eval__, :eval
72
-
73
- def eval(*args)
74
- Covered::Eval.intercept_eval(*args)
75
-
76
- __eval__(*args)
77
- end
78
- end