deep-cover 0.6.2 → 0.6.3.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.rspec +2 -1
  4. data/.rspec_all +2 -1
  5. data/.rubocop.yml +8 -9
  6. data/Gemfile +2 -0
  7. data/Rakefile +32 -6
  8. data/bin/cov +3 -3
  9. data/deep_cover.gemspec +3 -16
  10. data/exe/deep-cover +5 -0
  11. data/lib/deep_cover/cli/debugger.rb +1 -1
  12. data/lib/deep_cover/cli/exec.rb +1 -1
  13. data/lib/deep_cover/cli/instrumented_clone_reporter.rb +5 -3
  14. data/lib/deep_cover/cli/runner.rb +2 -2
  15. data/lib/deep_cover/{tools/dump_covered_code.rb → dump_covered_code.rb} +2 -0
  16. metadata +10 -203
  17. data/lib/deep-cover.rb +0 -3
  18. data/lib/deep_cover.rb +0 -22
  19. data/lib/deep_cover/analyser.rb +0 -23
  20. data/lib/deep_cover/analyser/base.rb +0 -104
  21. data/lib/deep_cover/analyser/branch.rb +0 -41
  22. data/lib/deep_cover/analyser/covered_code_source.rb +0 -21
  23. data/lib/deep_cover/analyser/function.rb +0 -14
  24. data/lib/deep_cover/analyser/node.rb +0 -54
  25. data/lib/deep_cover/analyser/per_char.rb +0 -38
  26. data/lib/deep_cover/analyser/per_line.rb +0 -41
  27. data/lib/deep_cover/analyser/ruby25_like_branch.rb +0 -211
  28. data/lib/deep_cover/analyser/statement.rb +0 -33
  29. data/lib/deep_cover/analyser/stats.rb +0 -54
  30. data/lib/deep_cover/analyser/subset.rb +0 -27
  31. data/lib/deep_cover/auto_run.rb +0 -71
  32. data/lib/deep_cover/autoload_tracker.rb +0 -215
  33. data/lib/deep_cover/backports.rb +0 -22
  34. data/lib/deep_cover/base.rb +0 -117
  35. data/lib/deep_cover/basics.rb +0 -22
  36. data/lib/deep_cover/builtin_takeover.rb +0 -10
  37. data/lib/deep_cover/config.rb +0 -104
  38. data/lib/deep_cover/config_setter.rb +0 -33
  39. data/lib/deep_cover/core_ext/autoload_overrides.rb +0 -112
  40. data/lib/deep_cover/core_ext/coverage_replacement.rb +0 -61
  41. data/lib/deep_cover/core_ext/exec_callbacks.rb +0 -27
  42. data/lib/deep_cover/core_ext/instruction_sequence_load_iseq.rb +0 -32
  43. data/lib/deep_cover/core_ext/load_overrides.rb +0 -19
  44. data/lib/deep_cover/core_ext/require_overrides.rb +0 -28
  45. data/lib/deep_cover/coverage.rb +0 -125
  46. data/lib/deep_cover/coverage/analysis.rb +0 -42
  47. data/lib/deep_cover/coverage/persistence.rb +0 -84
  48. data/lib/deep_cover/covered_code.rb +0 -145
  49. data/lib/deep_cover/custom_requirer.rb +0 -187
  50. data/lib/deep_cover/flag_comment_associator.rb +0 -68
  51. data/lib/deep_cover/load.rb +0 -66
  52. data/lib/deep_cover/memoize.rb +0 -48
  53. data/lib/deep_cover/module_override.rb +0 -39
  54. data/lib/deep_cover/node.rb +0 -23
  55. data/lib/deep_cover/node/arguments.rb +0 -51
  56. data/lib/deep_cover/node/assignments.rb +0 -273
  57. data/lib/deep_cover/node/base.rb +0 -155
  58. data/lib/deep_cover/node/begin.rb +0 -27
  59. data/lib/deep_cover/node/block.rb +0 -61
  60. data/lib/deep_cover/node/branch.rb +0 -32
  61. data/lib/deep_cover/node/case.rb +0 -113
  62. data/lib/deep_cover/node/collections.rb +0 -31
  63. data/lib/deep_cover/node/const.rb +0 -12
  64. data/lib/deep_cover/node/def.rb +0 -40
  65. data/lib/deep_cover/node/empty_body.rb +0 -32
  66. data/lib/deep_cover/node/exceptions.rb +0 -79
  67. data/lib/deep_cover/node/if.rb +0 -73
  68. data/lib/deep_cover/node/keywords.rb +0 -86
  69. data/lib/deep_cover/node/literals.rb +0 -100
  70. data/lib/deep_cover/node/loops.rb +0 -74
  71. data/lib/deep_cover/node/mixin/can_augment_children.rb +0 -65
  72. data/lib/deep_cover/node/mixin/check_completion.rb +0 -18
  73. data/lib/deep_cover/node/mixin/child_can_be_empty.rb +0 -27
  74. data/lib/deep_cover/node/mixin/executed_after_children.rb +0 -15
  75. data/lib/deep_cover/node/mixin/execution_location.rb +0 -66
  76. data/lib/deep_cover/node/mixin/filters.rb +0 -47
  77. data/lib/deep_cover/node/mixin/flow_accounting.rb +0 -71
  78. data/lib/deep_cover/node/mixin/has_child.rb +0 -145
  79. data/lib/deep_cover/node/mixin/has_child_handler.rb +0 -75
  80. data/lib/deep_cover/node/mixin/has_tracker.rb +0 -46
  81. data/lib/deep_cover/node/mixin/is_statement.rb +0 -20
  82. data/lib/deep_cover/node/mixin/rewriting.rb +0 -35
  83. data/lib/deep_cover/node/mixin/wrapper.rb +0 -15
  84. data/lib/deep_cover/node/module.rb +0 -66
  85. data/lib/deep_cover/node/root.rb +0 -20
  86. data/lib/deep_cover/node/send.rb +0 -161
  87. data/lib/deep_cover/node/short_circuit.rb +0 -42
  88. data/lib/deep_cover/node/splat.rb +0 -15
  89. data/lib/deep_cover/node/variables.rb +0 -16
  90. data/lib/deep_cover/parser_ext/range.rb +0 -21
  91. data/lib/deep_cover/problem_with_diagnostic.rb +0 -63
  92. data/lib/deep_cover/reporter.rb +0 -10
  93. data/lib/deep_cover/reporter/base.rb +0 -68
  94. data/lib/deep_cover/reporter/html.rb +0 -15
  95. data/lib/deep_cover/reporter/html/base.rb +0 -14
  96. data/lib/deep_cover/reporter/html/index.rb +0 -59
  97. data/lib/deep_cover/reporter/html/site.rb +0 -70
  98. data/lib/deep_cover/reporter/html/source.rb +0 -136
  99. data/lib/deep_cover/reporter/html/template/assets/32px.png +0 -0
  100. data/lib/deep_cover/reporter/html/template/assets/40px.png +0 -0
  101. data/lib/deep_cover/reporter/html/template/assets/deep_cover.css.sass +0 -336
  102. data/lib/deep_cover/reporter/html/template/assets/jquery-3.2.1.min.js +0 -4
  103. data/lib/deep_cover/reporter/html/template/assets/jquery-3.2.1.min.map +0 -1
  104. data/lib/deep_cover/reporter/html/template/assets/jstree.css +0 -1108
  105. data/lib/deep_cover/reporter/html/template/assets/jstree.js +0 -8424
  106. data/lib/deep_cover/reporter/html/template/assets/jstreetable.js +0 -1069
  107. data/lib/deep_cover/reporter/html/template/assets/throbber.gif +0 -0
  108. data/lib/deep_cover/reporter/html/template/index.html.erb +0 -75
  109. data/lib/deep_cover/reporter/html/template/source.html.erb +0 -35
  110. data/lib/deep_cover/reporter/istanbul.rb +0 -184
  111. data/lib/deep_cover/reporter/text.rb +0 -58
  112. data/lib/deep_cover/reporter/tree/util.rb +0 -86
  113. data/lib/deep_cover/tools.rb +0 -22
  114. data/lib/deep_cover/tools/blank.rb +0 -25
  115. data/lib/deep_cover/tools/builtin_coverage.rb +0 -55
  116. data/lib/deep_cover/tools/camelize.rb +0 -13
  117. data/lib/deep_cover/tools/content_tag.rb +0 -11
  118. data/lib/deep_cover/tools/covered.rb +0 -9
  119. data/lib/deep_cover/tools/execute_sample.rb +0 -34
  120. data/lib/deep_cover/tools/format.rb +0 -18
  121. data/lib/deep_cover/tools/format_char_cover.rb +0 -19
  122. data/lib/deep_cover/tools/format_generated_code.rb +0 -27
  123. data/lib/deep_cover/tools/indent_string.rb +0 -26
  124. data/lib/deep_cover/tools/merge.rb +0 -16
  125. data/lib/deep_cover/tools/number_lines.rb +0 -22
  126. data/lib/deep_cover/tools/our_coverage.rb +0 -11
  127. data/lib/deep_cover/tools/profiling.rb +0 -68
  128. data/lib/deep_cover/tools/render_template.rb +0 -13
  129. data/lib/deep_cover/tools/require_relative_dir.rb +0 -12
  130. data/lib/deep_cover/tools/scan_match_datas.rb +0 -10
  131. data/lib/deep_cover/tools/silence_warnings.rb +0 -18
  132. data/lib/deep_cover/tools/slice.rb +0 -9
  133. data/lib/deep_cover/tools/strip_heredoc.rb +0 -18
  134. data/lib/deep_cover/tools/truncate_backtrace.rb +0 -32
  135. data/lib/deep_cover/tracker_bucket.rb +0 -50
  136. data/lib/deep_cover/tracker_hits_per_path.rb +0 -35
  137. data/lib/deep_cover/tracker_storage.rb +0 -76
  138. data/lib/deep_cover/tracker_storage_per_path.rb +0 -34
  139. data/lib/deep_cover/version.rb +0 -5
@@ -1,155 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module DeepCover
4
- # Base class to handle covered nodes.
5
- class Node
6
- include Mixin
7
- include HasTracker
8
- include HasChild
9
- include HasChildHandler
10
- include CanAugmentChildren
11
- include Rewriting
12
- extend CheckCompletion
13
- include FlowAccounting
14
- include IsStatement
15
- include ExecutionLocation
16
- include ChildCanBeEmpty
17
- include Filters
18
- extend Filters::ClassMethods
19
-
20
- attr_reader :index, :parent, :children, :base_node
21
-
22
- def initialize(base_node, parent:, index: 0, base_children: base_node.children)
23
- @base_node = base_node
24
- @parent = parent
25
- @index = index
26
- @children = []
27
- begin
28
- @children = augment_children(base_children)
29
- initialize_siblings
30
- super()
31
- rescue StandardError => e
32
- diagnose(e)
33
- end
34
- end
35
-
36
- ### Public API
37
-
38
- # Search self and descendants for a particular Class or type
39
- def find_all(lookup)
40
- case lookup
41
- when ::Module
42
- each_node.grep(lookup)
43
- when ::Symbol
44
- each_node.find_all { |n| n.type == lookup }
45
- when ::String
46
- each_node.find_all { |n| n.source == lookup }
47
- when ::Regexp
48
- each_node.find_all { |n| n.source =~ lookup }
49
- else
50
- raise ::TypeError, "Expected class or symbol, got #{lookup.class}: #{lookup.inspect}"
51
- end
52
- end
53
-
54
- # Shortcut to access children
55
- def [](lookup)
56
- if lookup.is_a?(Integer)
57
- children.fetch(lookup)
58
- else
59
- found = find_all(lookup)
60
- case found.size
61
- when 1
62
- found.first
63
- when 0
64
- raise "No children of type #{lookup}"
65
- else
66
- raise "Ambiguous lookup #{lookup}, found #{found}."
67
- end
68
- end
69
- end
70
-
71
- # Shortcut to create a node from source code
72
- def self.[](source)
73
- CoveredCode.new(source: source).execute_code.covered_ast
74
- end
75
-
76
- def children_nodes
77
- children.select { |c| c.is_a? Node }
78
- end
79
- alias_method :children_nodes_in_flow_order, :children_nodes
80
-
81
- attr_accessor :next_sibling
82
- attr_accessor :previous_sibling
83
- protected :next_sibling=, :previous_sibling=
84
- def initialize_siblings
85
- children_nodes_in_flow_order.each_cons(2) do |child, next_child|
86
- child.next_sibling = next_child
87
- next_child.previous_sibling = child
88
- end
89
- end
90
- private :initialize_siblings
91
-
92
- # Adapted from https://github.com/whitequark/ast/blob/master/lib/ast/node.rb
93
- def to_s(indent = 0)
94
- [
95
- ' ' * indent,
96
- '(',
97
- fancy_type,
98
- *children.map do |child, idx|
99
- if child.is_a?(Node)
100
- "\n#{child.to_s(indent + 1)}"
101
- else
102
- " #{child.inspect}"
103
- end
104
- end,
105
- ')',
106
- ].join
107
- end
108
-
109
- alias_method :inspect, :to_s
110
- ### Internal API
111
-
112
- def covered_code
113
- parent.covered_code
114
- end
115
-
116
- def type
117
- return base_node.type if base_node.respond_to? :type
118
- self.class.name.split('::').last.to_sym
119
- end
120
-
121
- def each_node(order = :postorder, &block)
122
- return to_enum :each_node, order unless block_given?
123
- yield self unless order == :postorder
124
- children_nodes.each do |child|
125
- child.each_node(order, &block)
126
- end
127
- yield self if order == :postorder
128
- self
129
- end
130
-
131
- def fancy_type
132
- class_name = self.class.to_s.gsub(/^DeepCover::/, '').gsub(/^Node::/, '')
133
- t = type.to_s
134
- t.casecmp(class_name) == 0 ? t : "#{t}[#{class_name}]"
135
- end
136
-
137
- private
138
-
139
- def diagnose(exception)
140
- msg = if self.class == Node
141
- "Unknown node type encountered: #{base_node.type}"
142
- else
143
- "Node class #{self.class} incorrectly defined"
144
- end
145
- warn [msg,
146
- 'Attempting to continue, but this node will not be handled properly',
147
- ('Its subnodes will be ignored' if children.empty?),
148
- 'Source:',
149
- expression,
150
- 'Original exception:',
151
- exception.inspect,
152
- ].join("\n")
153
- end
154
- end
155
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module DeepCover
4
- class Node
5
- class Begin < Node
6
- has_extra_children expressions: Node,
7
- is_statement: true
8
-
9
- def is_statement
10
- false
11
- end
12
-
13
- def executed_loc_keys
14
- # Begin is a generic grouping used in different contexts.
15
- case loc_hash[:begin] && loc_hash[:begin].source
16
- when nil, '(', 'begin'
17
- []
18
- when 'else', '#{'
19
- %i[begin end]
20
- else
21
- warn 'Unknown context for Begin node'
22
- []
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'send'
4
- require_relative 'keywords'
5
-
6
- module DeepCover
7
- class Node
8
- module WithBlock
9
- def flow_completion_count
10
- parent.flow_completion_count
11
- end
12
-
13
- def execution_count
14
- last = children_nodes.last
15
- return last.flow_completion_count if last
16
- super
17
- end
18
- end
19
-
20
- class SendWithBlock < SendBase
21
- include WithBlock
22
- end
23
-
24
- class SuperWithBlock < Node
25
- include WithBlock
26
- has_extra_children arguments: Node
27
- end
28
-
29
- class Block < Node
30
- check_completion
31
- has_tracker :body
32
- has_child call: {send: SendWithBlock, zsuper: SuperWithBlock, super: SuperWithBlock, csend: Csend}
33
- has_child args: Args
34
- has_child body: Node,
35
- can_be_empty: -> { base_node.loc.end.begin },
36
- rewrite: '%{body_tracker};%{local}=nil;%{node}',
37
- flow_entry_count: :body_tracker_hits,
38
- is_statement: true
39
- executed_loc_keys # none
40
-
41
- def children_nodes_in_flow_order
42
- [call, args] # Similarly to a def, the body is actually not part of the flow of this node...
43
- end
44
-
45
- alias_method :rewrite_for_completion, :rewrite
46
- def rewrite
47
- if call.is_a?(Csend)
48
- rewrite_for_completion.gsub('%{node}', Csend::REWRITE_SUFFIX)
49
- else
50
- rewrite_for_completion
51
- end
52
- end
53
- end
54
-
55
- # &foo
56
- class BlockPass < Node
57
- has_child block: Node
58
- # TODO
59
- end
60
- end
61
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'empty_body'
4
-
5
- module DeepCover
6
- class Node
7
- module Branch
8
- def flow_completion_count
9
- branches.map(&:flow_completion_count).inject(0, :+)
10
- end
11
-
12
- # Define in sublasses:
13
- def branches
14
- raise NotImplementedError
15
- end
16
-
17
- # Also define flow_entry_count
18
- end
19
-
20
- class TrivialBranch < Node::EmptyBody
21
- def initialize(other_branch:, condition:, position: true)
22
- @condition = condition
23
- @other_branch = other_branch
24
- super(nil, parent: condition.parent, position: position)
25
- end
26
-
27
- def flow_entry_count
28
- @condition.flow_completion_count - @other_branch.flow_entry_count
29
- end
30
- end
31
- end
32
- end
@@ -1,113 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'branch'
4
-
5
- module DeepCover
6
- class Node
7
- class WhenCondition < Node
8
- include Wrapper
9
- has_tracker :entry
10
- # Using && instead of ; solves a weird bug in jruby 9.1.7.0 and 9.1.9.0 (probably before too).
11
- # The following will only print 'test' once
12
- # class EqEqEq; def ===(other); puts 'test'; end; end
13
- # eqeqeq = EqEqEq.new
14
- # case 1; when eqeqeq; end
15
- # case 1; when (3;eqeqeq); end
16
- # See https://github.com/jruby/jruby/issues/4804
17
- # This is solved in jruby 9.2.0.0, better keep the workaround
18
- # for compatibility.
19
- has_child condition: Node, rewrite: '((%{entry_tracker}) && %{node})',
20
- flow_entry_count: :entry_tracker_hits
21
- executed_loc_keys []
22
-
23
- def flow_entry_count
24
- entry_tracker_hits
25
- end
26
-
27
- def flow_completion_count
28
- condition.flow_completion_count
29
- end
30
-
31
- def loc_hash
32
- condition.loc_hash
33
- end
34
- end
35
-
36
- class WhenSplatCondition < Node
37
- has_tracker :entry
38
- check_completion inner: '(%{entry_tracker};[%{node}])', outer: '*%{node}'
39
- has_child receiver: Node
40
-
41
- def flow_entry_count
42
- entry_tracker_hits
43
- end
44
- end
45
-
46
- class When < Node
47
- has_tracker :body_entry
48
- has_extra_children matches: {splat: WhenSplatCondition, Parser::AST::Node => WhenCondition}
49
- has_child body: Node,
50
- can_be_empty: -> {
51
- if (after_then = base_node.loc.begin)
52
- after_then.end
53
- else
54
- base_node.loc.expression.end.succ
55
- end
56
- },
57
- rewrite: '%{body_entry_tracker};%{local}=nil;%{node}',
58
- is_statement: true,
59
- flow_entry_count: :body_entry_tracker_hits
60
-
61
- def flow_entry_count
62
- matches.first.flow_entry_count
63
- end
64
-
65
- def execution_count
66
- matches.first.flow_completion_count
67
- end
68
-
69
- def flow_completion_count
70
- body.flow_completion_count + next_sibling.flow_entry_count
71
- end
72
- end
73
-
74
- class Case < Node
75
- include Branch
76
- has_tracker :else_entry
77
- has_child evaluate: [Node, nil]
78
- has_extra_children whens: When
79
- has_child else: Node,
80
- can_be_empty: -> { base_node.loc.end.begin },
81
- rewrite: -> { "#{'else;' unless has_else?}(%{else_entry_tracker};%{local}=nil;%{node})" },
82
- executed_loc_keys: [:else],
83
- is_statement: true,
84
- flow_entry_count: :else_entry_tracker_hits
85
-
86
- executed_loc_keys :begin, :keyword
87
-
88
- def branches
89
- whens.map(&:body) << self.else
90
- end
91
-
92
- def branches_summary(of_branches = branches)
93
- texts = []
94
- n = of_branches.size
95
- if of_branches.include? self.else
96
- texts << "#{'implicit ' unless has_else?}else"
97
- n -= 1
98
- end
99
- texts.unshift "#{n} when clause#{'s' if n > 1}" if n > 0
100
- texts.join(' and ')
101
- end
102
-
103
- def execution_count
104
- return evaluate.flow_completion_count if evaluate
105
- flow_entry_count
106
- end
107
-
108
- def has_else?
109
- !!base_node.loc.to_hash[:else]
110
- end
111
- end
112
- end
113
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'splat'
4
-
5
- module DeepCover
6
- class Node
7
- module SimpleIfEmpty
8
- def simple_literal?
9
- children.empty?
10
- end
11
- end
12
-
13
- class Array < Node
14
- include SimpleIfEmpty
15
- has_extra_children elements: Node
16
- executed_loc_keys :begin, :end
17
- end
18
-
19
- class Pair < Node
20
- has_child key: Node
21
- has_child value: Node
22
- executed_loc_keys :operator
23
- end
24
-
25
- class Hash < Node
26
- include SimpleIfEmpty
27
- has_extra_children elements: [Pair, Kwsplat]
28
- executed_loc_keys :begin, :end
29
- end
30
- end
31
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module DeepCover
4
- class Node::Const < Node
5
- check_completion
6
- has_child scope: [Node, nil]
7
- has_child const_name: Symbol
8
- end
9
-
10
- class Node::Cbase < Node
11
- end
12
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'arguments'
4
-
5
- module DeepCover
6
- class Node::Def < Node
7
- check_completion
8
- has_tracker :method_call
9
- has_child method_name: Symbol
10
- has_child signature: Args
11
- has_child body: Node,
12
- rewrite: '%{method_call_tracker};%{local}=nil;%{node}',
13
- can_be_empty: -> { base_node.loc.end.begin },
14
- is_statement: true,
15
- flow_entry_count: :method_call_tracker_hits
16
- executed_loc_keys :keyword, :name
17
-
18
- def children_nodes_in_flow_order
19
- []
20
- end
21
- end
22
-
23
- class Node::Defs < Node
24
- check_completion
25
- has_tracker :method_call
26
- has_child singleton: Node, rewrite: '(%{node})'
27
- has_child method_name: Symbol
28
- has_child signature: Args
29
- has_child body: Node,
30
- rewrite: '%{method_call_tracker};%{local}=nil;%{node}',
31
- can_be_empty: -> { base_node.loc.end.begin },
32
- is_statement: true,
33
- flow_entry_count: :method_call_tracker_hits
34
- executed_loc_keys :keyword, :name, :operator
35
-
36
- def children_nodes_in_flow_order
37
- [singleton]
38
- end
39
- end
40
- end