path_coverage 0.4.0 → 0.5.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.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +286 -199
  3. data/exe/path_coverage_report +4 -0
  4. data/lib/path_coverage/call_trace.rb +88 -0
  5. data/lib/path_coverage/calls.rb +49 -43
  6. data/lib/path_coverage/card_context.rb +104 -0
  7. data/lib/path_coverage/card_forks.rb +44 -0
  8. data/lib/path_coverage/card_gaps.rb +125 -0
  9. data/lib/path_coverage/card_scopes.rb +37 -0
  10. data/lib/path_coverage/card_tree.rb +79 -66
  11. data/lib/path_coverage/card_way_lists.rb +72 -0
  12. data/lib/path_coverage/card_ways.rb +123 -67
  13. data/lib/path_coverage/{html_syntax.rb → code_tokens.rb} +35 -33
  14. data/lib/path_coverage/condition.rb +14 -14
  15. data/lib/path_coverage/configuration.rb +7 -4
  16. data/lib/path_coverage/configuration_limits.rb +52 -0
  17. data/lib/path_coverage/configuration_paths.rb +7 -7
  18. data/lib/path_coverage/console_summary.rb +24 -22
  19. data/lib/path_coverage/{site.rb → decision.rb} +2 -2
  20. data/lib/path_coverage/decision_locations.rb +76 -0
  21. data/lib/path_coverage/{site_paths.rb → decision_paths.rb} +13 -11
  22. data/lib/path_coverage/{site_tree.rb → decision_tree.rb} +25 -16
  23. data/lib/path_coverage/fold_branches.rb +18 -0
  24. data/lib/path_coverage/fold_cells.rb +42 -0
  25. data/lib/path_coverage/{html_tree.rb → fold_rows.rb} +42 -71
  26. data/lib/path_coverage/gaps.rb +33 -15
  27. data/lib/path_coverage/json_reader.rb +54 -19
  28. data/lib/path_coverage/json_reports.rb +102 -0
  29. data/lib/path_coverage/json_writer.rb +27 -12
  30. data/lib/path_coverage/kernel.rb +56 -58
  31. data/lib/path_coverage/kinds/base.rb +16 -16
  32. data/lib/path_coverage/kinds/block.rb +16 -15
  33. data/lib/path_coverage/kinds/case.rb +14 -12
  34. data/lib/path_coverage/kinds/chain.rb +40 -11
  35. data/lib/path_coverage/kinds/choice.rb +4 -3
  36. data/lib/path_coverage/kinds/contains.rb +40 -32
  37. data/lib/path_coverage/kinds/safe.rb +38 -26
  38. data/lib/path_coverage/kinds/write.rb +6 -6
  39. data/lib/path_coverage/kinds.rb +2 -2
  40. data/lib/path_coverage/leaving.rb +44 -0
  41. data/lib/path_coverage/loop_forks.rb +57 -0
  42. data/lib/path_coverage/loop_nodes.rb +55 -0
  43. data/lib/path_coverage/manifest.rb +92 -58
  44. data/lib/path_coverage/manifest_blocks.rb +5 -26
  45. data/lib/path_coverage/manifest_case.rb +2 -2
  46. data/lib/path_coverage/manifest_chains.rb +8 -8
  47. data/lib/path_coverage/manifest_choices.rb +23 -20
  48. data/lib/path_coverage/manifest_disabled.rb +97 -0
  49. data/lib/path_coverage/manifest_folding.rb +43 -40
  50. data/lib/path_coverage/manifest_ignoring.rb +6 -6
  51. data/lib/path_coverage/manifest_writes.rb +11 -10
  52. data/lib/path_coverage/measured_by.rb +20 -0
  53. data/lib/path_coverage/merge.rb +7 -7
  54. data/lib/path_coverage/method_loops.rb +128 -0
  55. data/lib/path_coverage/method_statements.rb +130 -127
  56. data/lib/path_coverage/method_ways.rb +142 -0
  57. data/lib/path_coverage/paths_report.rb +16 -16
  58. data/lib/path_coverage/recorder.rb +57 -36
  59. data/lib/path_coverage/recorder_blocks.rb +17 -17
  60. data/lib/path_coverage/recorder_cases.rb +12 -11
  61. data/lib/path_coverage/recorder_chains.rb +12 -12
  62. data/lib/path_coverage/recorder_writes.rb +9 -9
  63. data/lib/path_coverage/render.rb +58 -51
  64. data/lib/path_coverage/result.rb +32 -31
  65. data/lib/path_coverage/rewriter.rb +39 -27
  66. data/lib/path_coverage/rewriter_nested.rb +13 -13
  67. data/lib/path_coverage/runs_report.rb +84 -0
  68. data/lib/path_coverage/source_lines.rb +16 -16
  69. data/lib/path_coverage/source_report.rb +100 -0
  70. data/lib/path_coverage/stable_leaves.rb +162 -0
  71. data/lib/path_coverage/statement_arms.rb +31 -30
  72. data/lib/path_coverage/summary.rb +4 -62
  73. data/lib/path_coverage/totals.rb +10 -8
  74. data/lib/path_coverage/version.rb +1 -1
  75. data/lib/path_coverage/walk.rb +106 -0
  76. data/lib/path_coverage/way_algebras.rb +127 -0
  77. data/lib/path_coverage/ways_report.rb +91 -0
  78. data/lib/path_coverage/ways_totals.rb +46 -0
  79. data/lib/path_coverage/within_methods.rb +135 -80
  80. metadata +33 -28
  81. data/lib/path_coverage/card.rb +0 -14
  82. data/lib/path_coverage/html/file.html +0 -33
  83. data/lib/path_coverage/html/index.html +0 -29
  84. data/lib/path_coverage/html/settings.js +0 -50
  85. data/lib/path_coverage/html/side.js +0 -599
  86. data/lib/path_coverage/html/sort.js +0 -34
  87. data/lib/path_coverage/html/style.css +0 -484
  88. data/lib/path_coverage/html/tabs.js +0 -15
  89. data/lib/path_coverage/html/theme.js +0 -27
  90. data/lib/path_coverage/html_branch.rb +0 -30
  91. data/lib/path_coverage/html_cards.rb +0 -88
  92. data/lib/path_coverage/html_cells.rb +0 -71
  93. data/lib/path_coverage/html_file.rb +0 -123
  94. data/lib/path_coverage/html_index.rb +0 -128
  95. data/lib/path_coverage/html_index_head.rb +0 -29
  96. data/lib/path_coverage/html_labels.rb +0 -16
  97. data/lib/path_coverage/html_methods.rb +0 -66
  98. data/lib/path_coverage/html_nav.rb +0 -67
  99. data/lib/path_coverage/html_report.rb +0 -131
  100. data/lib/path_coverage/html_statements.rb +0 -186
  101. data/lib/path_coverage/html_tabs.rb +0 -26
  102. data/lib/path_coverage/html_template.rb +0 -26
@@ -1,7 +1,7 @@
1
1
  require_relative 'condition'
2
2
 
3
3
  module PathCoverage
4
- # The part of the manifest's visitor that builds a case site,
4
+ # The part of the manifest's visitor that builds a case decision,
5
5
  # named case: its arms are its whens, each holding a when
6
6
  # condition of its patterns, and its else. It relies on its
7
7
  # includer's extent_of and statement_arm.
@@ -10,7 +10,7 @@ module PathCoverage
10
10
  # subject, as each pattern is then matched against it, and
11
11
  # no splat among its patterns, whose items cannot each be
12
12
  # stood in for.
13
- def case_site?(node)
13
+ def case_decision?(node)
14
14
  return false if node.predicate.nil?
15
15
 
16
16
  patterns = node.conditions.flat_map(&:conditions)
@@ -1,7 +1,7 @@
1
1
  require_relative 'condition'
2
2
 
3
3
  module PathCoverage
4
- # The part of the manifest's visitor that builds the sites of
4
+ # The part of the manifest's visitor that builds the decisions of
5
5
  # safe-navigation chains, eg user&.account&.owner. It relies
6
6
  # on its includer's extent_of.
7
7
  module ManifestChains
@@ -23,7 +23,7 @@ module PathCoverage
23
23
  chain_calls(node).any?(&:safe_navigation?)
24
24
  end
25
25
 
26
- # A call that is a site as a Condition: a &. chain's, or a
26
+ # A call that is a decision as a Condition: a &. chain's, or a
27
27
  # block method call's. It relies on its includer's
28
28
  # block_condition.
29
29
  def call_condition(node)
@@ -36,23 +36,23 @@ module PathCoverage
36
36
  # receivers of its &. calls, innermost first, each nil or
37
37
  # not nil, and, with value, the whole chain's value last, as
38
38
  # when it is an operand of an && or an if's predicate. Any
39
- # site in a call's arguments or block, or in the chain's
40
- # first receiver, is a site of its own. A chain that is no
39
+ # decision in a call's arguments or block, or in the chain's
40
+ # first receiver, is a decision of its own. A chain that is no
41
41
  # bare argument, eg a command call, is noted among the
42
- # site's commands, to be parenthesised.
42
+ # decision's commands, to be parenthesised.
43
43
  def chain_condition(node, value:)
44
44
  calls = chain_calls(node)
45
45
  visit_chain(calls)
46
46
  safe = calls.select(&:safe_navigation?).reverse
47
47
  receivers = safe.map { |call| receiver_of(call) }
48
48
  extent = extent_of(node)
49
- @notes[:commands] << extent if Manifest.command?(node)
49
+ @notes[:commands] << extent if Manifest.bare_less?(node)
50
50
  operands = value ? [*receivers, extent] : receivers
51
51
  Condition.new(operator: SAFE, operands:, extent:)
52
52
  end
53
53
 
54
54
  # The byte range of a &. call's receiver, noted among its
55
- # site's fixed leaves as :present, never nil, when it is a
55
+ # decision's fixed leaves as :present, never nil, when it is a
56
56
  # call to a method treated as present.
57
57
  def receiver_of(call)
58
58
  receiver = call.receiver
@@ -63,7 +63,7 @@ module PathCoverage
63
63
  range
64
64
  end
65
65
 
66
- # Visits the sites inside a chain's calls' arguments and
66
+ # Visits the decisions inside a chain's calls' arguments and
67
67
  # blocks, and inside its first receiver, eg (a || b) in
68
68
  # (a || b)&.size, but never a call of the chain itself.
69
69
  def visit_chain(calls)
@@ -1,7 +1,8 @@
1
1
  require_relative 'condition'
2
+ require_relative 'leaving'
2
3
 
3
4
  module PathCoverage
4
- # The part of the manifest's visitor that builds the sites
5
+ # The part of the manifest's visitor that builds the decisions
5
6
  # whose predicate picks an arm: a ternary, named ?:, an if,
6
7
  # named if, and an unless, named unless. It relies on its
7
8
  # includer's condition_of, extent_of, grouped, leaf and
@@ -11,12 +12,12 @@ module PathCoverage
11
12
  # being an if_node with no if keyword.
12
13
  CHOICE_TYPES = %i[if_node unless_node].freeze
13
14
 
14
- # Where node's site is named: a &. chain's start; a block
15
+ # Where node's decision is named: a &. chain's start; a block
15
16
  # method's call at its method; a ternary at its ?, so it never
16
- # shares the name of a site starting where it does, eg its
17
+ # shares the name of a decision starting where it does, eg its
17
18
  # predicate; an if's or an unless's keyword, which a
18
19
  # modifier's statement comes before; anything else's own start.
19
- def site_loc(node)
20
+ def decision_loc(node)
20
21
  return node.location if safe_chain?(node)
21
22
  return node.message_loc if node.type == :call_node
22
23
  return node.location unless CHOICE_TYPES.include?(node.type)
@@ -72,16 +73,18 @@ module PathCoverage
72
73
  end
73
74
 
74
75
  # An if's arm, statements its code, which never folds into
75
- # the if's site; as a new scope, any site inside it is a site
76
- # of its own. An arm with no statements has no extent.
76
+ # the if's decision; as a new scope, any decision inside it
77
+ # is a decision of its own. An arm with no statements has no
78
+ # extent.
77
79
  def statement_arm(kind, statements)
78
80
  scoped { statements&.accept(self) }
79
81
  extent = statements ? extent_of(statements) : nil
80
- Arm.new(kind:, extent:, body: nil)
82
+ leaves = Leaving.of(statements)
83
+ Arm.new(kind:, extent:, body: nil, leaves:)
81
84
  end
82
85
 
83
86
  # An if's else arm, from subsequent: an else's statements,
84
- # or an elsif, which is a site of its own; none for none.
87
+ # or an elsif, which is a decision of its own; none for none.
85
88
  def else_arm(subsequent)
86
89
  return [] if subsequent.nil?
87
90
  if subsequent.type == :else_node
@@ -90,7 +93,7 @@ module PathCoverage
90
93
 
91
94
  scoped { subsequent.accept(self) }
92
95
  extent = extent_of(subsequent)
93
- [Arm.new(kind: :else, extent:, body: nil)]
96
+ [Arm.new(kind: :else, extent:, body: nil, leaves: nil)]
94
97
  end
95
98
 
96
99
  # A ternary's predicate, then its then and else arms.
@@ -104,32 +107,32 @@ module PathCoverage
104
107
 
105
108
  # One arm of a ternary, statements its code: a ternary, or a
106
109
  # block method's call whose value follows from its path, is a
107
- # site of its own, as an if's arm holding an if is, so the arm
110
+ # decision of its own, as an if's arm holding an if is, so the arm
108
111
  # is plain; another condition folds in as its body, being part
109
- # of the one expression, as does a plain arm with sites inside
112
+ # of the one expression, as does a plain arm with decisions inside
110
113
  # it, its value its last leaf; a plain arm with none has no
111
114
  # body.
112
115
  def arm_of(kind, statements)
113
116
  written = grouped(statements.body.first)
114
117
  extent = extent_of(statements)
115
118
  body = if ternary?(written) || valued?(written)
116
- own_site(statements)
119
+ own_decision(statements)
117
120
  else
118
121
  arm_body(written, statements, extent)
119
122
  end
120
- Arm.new(kind:, extent:, body:)
123
+ Arm.new(kind:, extent:, body:, leaves: Leaving.of(statements))
121
124
  end
122
125
 
123
- # No body, for an arm, statements its code, whose one site is
124
- # a site of its own: visited in a new scope, so noted as one.
125
- def own_site(statements)
126
+ # No body, for an arm, statements its code, whose one decision is
127
+ # a decision of its own: visited in a new scope, so noted as one.
128
+ def own_decision(statements)
126
129
  scoped { statements.accept(self) }
127
130
  nil
128
131
  end
129
132
 
130
133
  # The body of a ternary's arm, statements its code, written its
131
134
  # one expression, extent its byte range: the condition written
132
- # is, when it folds; else the sites inside it, contained, nil
135
+ # is, when it folds; else the decisions inside it, contained, nil
133
136
  # for none.
134
137
  def arm_body(written, statements, extent)
135
138
  return condition_of(written) if foldable?(written)
@@ -138,7 +141,7 @@ module PathCoverage
138
141
  inner.empty? ? nil : contained(inner, extent)
139
142
  end
140
143
 
141
- # True for a condition that folds into a ternary's site: an
144
+ # True for a condition that folds into a ternary's decision: an
142
145
  # &&, ||, and or or not ignored.
143
146
  def foldable?(node)
144
147
  operator?(node) && !ignored?(node)
@@ -151,8 +154,8 @@ module PathCoverage
151
154
 
152
155
  # A ternary's or an if's predicate as its operand: a &. chain
153
156
  # nested as a Condition, its value its last leaf; anything
154
- # else a leaf, an && or || among them, as a site of its own,
155
- # as leaf_sites has it.
157
+ # else a leaf, an && or || among them, as a decision of its own,
158
+ # as leaf_decisions has it.
156
159
  def predicate_of(node)
157
160
  predicate = grouped(node.predicate)
158
161
  return leaf(predicate) if ignored?(predicate)
@@ -0,0 +1,97 @@
1
+ module PathCoverage
2
+ # The lines of a source not analysed: those between a
3
+ # # path: disable comment and the next # path: enable, the
4
+ # line straight after each disable saying why on a # reason:
5
+ # line. Only a comment that is its line's whole text is a
6
+ # marker, so a string or heredoc holding the text is not.
7
+ module ManifestDisabled
8
+ DISABLE = '# path: disable'.freeze
9
+ ENABLE = '# path: enable'.freeze
10
+ REASON = '# reason:'.freeze
11
+
12
+ # The line numbers not analysed in source, at path, parsed as
13
+ # parsed; ArgumentError naming a disable with no reason line
14
+ # straight after it, or with no enable after it, or a
15
+ # statement starting on such a line and ending after it.
16
+ def self.lines(source, parsed, path)
17
+ texts = source.lines
18
+ found = markers(parsed.comments, texts)
19
+ require_reasons(found, texts, path)
20
+ disabled = between(found, path)
21
+ refuse_straddling(parsed.value, disabled, path)
22
+ disabled
23
+ end
24
+
25
+ # [line number, DISABLE or ENABLE] of each comment, of those,
26
+ # that is one of them and its line's whole text, in order.
27
+ def self.markers(comments, texts)
28
+ comments.filter_map do |comment|
29
+ number = comment.location.start_line
30
+ text = texts[number - 1].strip
31
+ [number, text] if [DISABLE, ENABLE].include?(text)
32
+ end
33
+ end
34
+
35
+ # Refuses each DISABLE among found whose next line, of texts,
36
+ # is no REASON line.
37
+ def self.require_reasons(found, texts, path)
38
+ found.each do |number, text|
39
+ next unless text == DISABLE
40
+ # texts[number] is the next line, nil after the last.
41
+ next if texts[number].to_s.strip.start_with?(REASON)
42
+
43
+ raise ArgumentError, "#{path}:#{number} #{DISABLE} needs " \
44
+ "a #{REASON} line straight after it"
45
+ end
46
+ end
47
+
48
+ # The line numbers between each DISABLE among found and the
49
+ # next marker; refuses a DISABLE with no marker after it.
50
+ def self.between(found, path)
51
+ disabled = Set.new
52
+ opened = nil
53
+ found.each do |number, text|
54
+ disabled.merge((opened + 1)...number) if opened
55
+ opened = text == DISABLE ? number : nil
56
+ end
57
+ return disabled unless opened
58
+
59
+ raise ArgumentError,
60
+ "#{path}:#{opened} #{DISABLE} has no #{ENABLE} after it"
61
+ end
62
+
63
+ # Refuses the first statement under tree that starts on a
64
+ # disabled line and ends on an analysed one, as a statement
65
+ # is analysed whole or not at all.
66
+ def self.refuse_straddling(tree, disabled, path)
67
+ found = straddler(tree, disabled)
68
+ return unless found
69
+
70
+ raise ArgumentError, "#{path}:#{found.location.start_line} " \
71
+ 'the statement starting here ends ' \
72
+ "after its #{ENABLE}"
73
+ end
74
+
75
+ # The first statement under node that starts on one of the
76
+ # disabled lines and ends on an analysed one, else nil.
77
+ def self.straddler(node, disabled)
78
+ statements = node.is_a?(Prism::StatementsNode) ? node.body : []
79
+ statements.each do |statement|
80
+ return statement if straddles?(statement, disabled)
81
+ end
82
+ node.compact_child_nodes.each do |child|
83
+ found = straddler(child, disabled)
84
+ return found if found
85
+ end
86
+ nil
87
+ end
88
+
89
+ # True for a statement starting on a disabled line and
90
+ # ending on an analysed one.
91
+ def self.straddles?(statement, disabled)
92
+ location = statement.location
93
+ disabled.include?(location.start_line) &&
94
+ !disabled.include?(location.end_line)
95
+ end
96
+ end
97
+ end
@@ -1,23 +1,24 @@
1
1
  require_relative 'condition'
2
- require_relative 'site'
3
- require_relative 'site_paths'
2
+ require_relative 'decision'
3
+ require_relative 'decision_paths'
4
4
 
5
5
  module PathCoverage
6
- # The part of the manifest's visitor that folds every site in one
7
- # expression into one site. While a leaf is visited, each site
8
- # found in it, the leaf itself included, is collected as a nested
9
- # Condition of that leaf, rather than noted as a site of its own.
10
- # A new scope, eg a block's body or an if's arm, stops the
11
- # collecting, so a site in it is a site of its own. It relies on
12
- # its includer's condition_of, chain_condition, safe_chain?,
13
- # block_site? and extent_of.
6
+ # The part of the manifest's visitor that folds every decision
7
+ # in one expression into one decision. While a leaf is
8
+ # visited, each decision found in it, the leaf itself
9
+ # included, is collected as a nested Condition of that leaf,
10
+ # rather than noted as a decision of its own. A new scope, eg
11
+ # a block's body or an if's arm, stops the collecting, so a
12
+ # decision in it is a decision of its own. It relies on its
13
+ # includer's condition_of, chain_condition, safe_chain?,
14
+ # block_decision? and extent_of.
14
15
  module ManifestFolding
15
- # The sites that fold into the leaf operand, as collected
16
- # finds them; none for a leaf that is wholly a site of its own,
17
- # as own_site? has it, visited as one, as the leaf's outcome is
18
- # its value.
19
- def leaf_sites(operand)
20
- unless own_site?(operand)
16
+ # The decisions that fold into the leaf operand, as collected
17
+ # finds them; none for a leaf that is wholly a decision of
18
+ # its own, as own_decision? has it, visited as one, as the
19
+ # leaf's outcome is its value.
20
+ def leaf_decisions(operand)
21
+ unless own_decision?(operand)
21
22
  return collected { operand.accept(self) }
22
23
  end
23
24
 
@@ -25,35 +26,36 @@ module PathCoverage
25
26
  []
26
27
  end
27
28
 
28
- # True for a leaf that is wholly a site of its own: a block
29
+ # True for a leaf that is wholly a decision of its own: a block
29
30
  # method's call whose value follows from its path, or an && or
30
31
  # ||, eg a predicate, not ignored.
31
- def own_site?(node)
32
+ def own_decision?(node)
32
33
  valued?(node) || (operator?(node) && !ignored?(node))
33
34
  end
34
35
 
35
- # True for a block method's call that is a site, not ignored,
36
+ # True for a block method's call that is a decision, not ignored,
36
37
  # whose value follows from its path, eg any?, but not find.
37
38
  def valued?(node)
38
- node.type == :call_node && block_site?(node) &&
39
+ node.type == :call_node && block_decision?(node) &&
39
40
  VALUED.include?(node.name.to_s) && !ignored?(node)
40
41
  end
41
42
 
42
- # The one outcome each of a site's values gives a leaf.
43
+ # The one outcome each of a decision's values gives a leaf.
43
44
  GIVEN = { [true] => :truthy, [false] => :falsy }.freeze
44
45
 
45
- # The one outcome the leaf node can have, as the site it wholly
46
- # is gives it on every one of its paths, eg :truthy for a
47
- # select, whose array is truthy; nil when its paths give both,
48
- # or node is no such site.
46
+ # The one outcome the leaf node can have, as the decision it
47
+ # wholly is gives it on every one of its paths, eg :truthy for
48
+ # a select, whose array is truthy; nil when its paths give
49
+ # both, or node is no such decision.
49
50
  def given_outcome(node)
50
- return nil unless own_site?(node)
51
+ return nil unless own_decision?(node)
51
52
 
52
- site = @sites.fetch(Site.at(@path, site_loc(node)))
53
- GIVEN[SitePaths.values(site).uniq]
53
+ name = Decision.at(@path, decision_loc(node))
54
+ decision = @decisions.fetch(name)
55
+ GIVEN[DecisionPaths.values(decision).uniq]
54
56
  end
55
57
 
56
- # node's Condition as a site nested in a leaf: a &. chain's
58
+ # node's Condition as a decision nested in a leaf: a &. chain's
57
59
  # with its value as its last leaf, as its leaf's outcome
58
60
  # follows from it.
59
61
  def nested_condition_of(node)
@@ -62,8 +64,8 @@ module PathCoverage
62
64
  condition_of(node)
63
65
  end
64
66
 
65
- # The Conditions of the sites found while yielding, each one
66
- # collected rather than noted as a site of its own.
67
+ # The Conditions of the decisions found while yielding, each one
68
+ # collected rather than noted as a decision of its own.
67
69
  def collected
68
70
  outer = @inner
69
71
  @inner = []
@@ -73,8 +75,8 @@ module PathCoverage
73
75
  @inner = outer
74
76
  end
75
77
 
76
- # Yields with no collecting, so a site found is one of its own:
77
- # for a new scope, eg a block's body or an if's arm.
78
+ # Yields with no collecting, so a decision found is one of its
79
+ # own: for a new scope, eg a block's body or an if's arm.
78
80
  def scoped
79
81
  outer = @inner
80
82
  @inner = nil
@@ -83,11 +85,12 @@ module PathCoverage
83
85
  @inner = outer
84
86
  end
85
87
 
86
- # range as a leaf, or, with inner sites found in it, a Condition
87
- # named contains: those sites, then range, the leaf's outcome,
88
- # fixed as :nonempty when nonempty. A leaf that is wholly one
89
- # block method's call whose value follows from its path never
90
- # comes here: it is a site of its own, as leaf_sites has it.
88
+ # range as a leaf, or, with inner decisions found in it, a
89
+ # Condition named contains: those decisions, then range, the
90
+ # leaf's outcome, fixed as :nonempty when nonempty. A leaf
91
+ # that is wholly one block method's call whose value follows
92
+ # from its path never comes here: it is a decision of its
93
+ # own, as leaf_decisions has it.
91
94
  def contained(inner, range, nonempty: false)
92
95
  return range if inner.empty?
93
96
 
@@ -98,8 +101,8 @@ module PathCoverage
98
101
 
99
102
  # True for a call, with no arguments or block, to a method
100
103
  # treated as nonempty, eg any?, whose receiver, parenthesised
101
- # or not, is one of inner, the sites found in it: its outcome
102
- # then follows from that site's path. It relies on its
104
+ # or not, is one of inner, the decisions found in it: its outcome
105
+ # then follows from that decision's path. It relies on its
103
106
  # includer's grouped.
104
107
  def nonempty_call?(node, inner)
105
108
  return false unless node.type == :call_node
@@ -1,12 +1,12 @@
1
1
  module PathCoverage
2
- # The part of the manifest's visitor that leaves out the sites
2
+ # The part of the manifest's visitor that leaves out the decisions
3
3
  # of ignored operators, eg ignore '&&='. An ignored node is no
4
- # site, though a site inside it may be; nested in a site, it
5
- # is a leaf. It relies on its includer's @ignored, ternary?
6
- # and safe_chain?.
4
+ # decision, though a decision inside it may be; nested in a
5
+ # decision, it is a leaf. It relies on its includer's
6
+ # @ignored, ternary? and safe_chain?.
7
7
  module ManifestIgnoring
8
8
  # The operator of each node type that always names one kind
9
- # of site.
9
+ # of decision.
10
10
  NAMED = { unless_node: 'unless', case_node: 'case' }.freeze
11
11
 
12
12
  # True for a node whose operator is ignored.
@@ -14,7 +14,7 @@ module PathCoverage
14
14
  @ignored.include?(operator_of(node))
15
15
  end
16
16
 
17
- # The operator naming node's kind of site, eg ?: for a
17
+ # The operator naming node's kind of decision, eg ?: for a
18
18
  # ternary or any? for a block method's call; nil for a
19
19
  # node with none.
20
20
  def operator_of(node)
@@ -1,9 +1,9 @@
1
1
  require_relative 'condition'
2
2
 
3
3
  module PathCoverage
4
- # The part of the manifest's visitor that builds the sites of
4
+ # The part of the manifest's visitor that builds the decisions of
5
5
  # ||= and &&= writes, eg @clock ||= Clock.new. It relies on
6
- # its includer's add_site, bare_less? and extent_of.
6
+ # its includer's add_decision and extent_of.
7
7
  module ManifestWrites
8
8
  # Every node type of a ||= or &&= write, by its target: a
9
9
  # variable of each kind, a constant, a constant path, an
@@ -15,15 +15,15 @@ module PathCoverage
15
15
  %W[#{target}_or_write_node #{target}_and_write_node]
16
16
  end.map(&:to_sym).freeze
17
17
 
18
- # Notes each kind of write as a site, eg
18
+ # Notes each kind of write as a decision, eg
19
19
  # visit_index_or_write_node for store[key] ||= 0.
20
20
  WRITE_TYPES.each do |type|
21
21
  define_method(:"visit_#{type}") do |node|
22
- write?(node) ? add_site(node) : visit_child_nodes(node)
22
+ write?(node) ? add_decision(node) : visit_child_nodes(node)
23
23
  end
24
24
  end
25
25
 
26
- # True for a ||= or &&= write that is a site: any but one
26
+ # True for a ||= or &&= write that is a decision: any but one
27
27
  # through &., eg box&.size ||= 3, which a nil box skips whole,
28
28
  # its target never looked at, so neither of its paths taken.
29
29
  def write?(node)
@@ -40,15 +40,16 @@ module PathCoverage
40
40
  # target is false for ||=, true for &&=. The target is a
41
41
  # leaf the rewriter never reads again, as reading it could
42
42
  # call a method twice; its outcome follows from whether the
43
- # arm ran. Any site inside the write, eg in an index or on
44
- # the right side, is a site of its own. A right side that is
43
+ # arm ran. Any decision inside the write, eg in an index or on
44
+ # the right side, is a decision of its own. A right side that is
45
45
  # no bare argument, eg a command call, is noted among the
46
- # site's commands, to be parenthesised.
46
+ # decision's commands, to be parenthesised.
47
47
  def write_condition(node)
48
48
  visit_child_nodes(node)
49
49
  value = extent_of(node.value)
50
- @notes[:commands] << value if bare_less?(node.value)
51
- arm = Arm.new(kind: :then, extent: value, body: nil)
50
+ @notes[:commands] << value if Manifest.bare_less?(node.value)
51
+ arm = Arm.new(kind: :then, extent: value, body: nil,
52
+ leaves: nil)
52
53
  Condition.new(
53
54
  operator: node.operator, operands: [target_of(node), arm],
54
55
  extent: extent_of(node)
@@ -0,0 +1,20 @@
1
+ require 'prism'
2
+ require_relative 'version'
3
+
4
+ module PathCoverage
5
+ # The tools that parse and measure a run, each with its version:
6
+ # Ruby, Prism and path_coverage itself. A change to any of them
7
+ # can list a file's decisions or paths differently, so a report
8
+ # names them as it is written, and reports merge only when they
9
+ # name the same.
10
+ module MeasuredBy
11
+ # { tool name => its version } of this process, eg
12
+ # { 'ruby' => '4.0.5', 'prism' => '1.8.1', ... }.
13
+ def self.versions
14
+ {
15
+ 'ruby' => RUBY_VERSION, 'prism' => Prism::VERSION,
16
+ 'path_coverage' => VERSION
17
+ }
18
+ end
19
+ end
20
+ end
@@ -5,21 +5,21 @@ module PathCoverage
5
5
  # counts are the sums of every run's.
6
6
  def self.operands(runs)
7
7
  runs.reduce do |total, run|
8
- total.merge(run) do |_site, mine, theirs|
8
+ total.merge(run) do |_decision, mine, theirs|
9
9
  mine.zip(theirs).map { |a, b| sum(a, b) }
10
10
  end
11
11
  end
12
12
  end
13
13
 
14
- # One site paths hash, as Result#paths gives them, each
14
+ # One decision paths hash, as Result#paths gives them, each
15
15
  # path's count the sum of every run's. Runs that list a
16
- # site's paths differently raise, as adding their counts by
16
+ # decision's paths differently raise, as adding their counts by
17
17
  # position would credit one path's count to another.
18
18
  def self.paths(runs)
19
19
  runs.reduce do |total, run|
20
- total.merge(run) do |site, mine, theirs|
20
+ total.merge(run) do |name, mine, theirs|
21
21
  same = mine.map { _1[:path] } == theirs.map { _1[:path] }
22
- raise ArgumentError, "runs differ at #{site}" unless same
22
+ raise ArgumentError, "runs differ at #{name}" unless same
23
23
 
24
24
  mine.zip(theirs).map do |a, b|
25
25
  { path: a[:path], count: a[:count] + b[:count] }
@@ -28,13 +28,13 @@ module PathCoverage
28
28
  end
29
29
  end
30
30
 
31
- # One listed hash, { site => { path => count } }, eg the
31
+ # One listed hash, { decision => { path => count } }, eg the
32
32
  # paths a treatment rules out, each path's count the sum of
33
33
  # every run's, eg [true, false] taken once in each of two
34
34
  # runs is taken twice.
35
35
  def self.listed(runs)
36
36
  runs.reduce do |total, run|
37
- total.merge(run) do |_site, mine, theirs|
37
+ total.merge(run) do |_decision, mine, theirs|
38
38
  mine.merge(theirs) { |_path, a, b| a + b }
39
39
  end
40
40
  end