path_coverage 0.3.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 (103) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +316 -177
  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 +199 -0
  11. data/lib/path_coverage/card_way_lists.rb +72 -0
  12. data/lib/path_coverage/card_ways.rb +196 -0
  13. data/lib/path_coverage/{html_syntax.rb → code_tokens.rb} +38 -25
  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} +18 -8
  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/fold_rows.rb +140 -0
  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 +31 -16
  30. data/lib/path_coverage/kernel.rb +56 -57
  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 -17
  34. data/lib/path_coverage/kinds/chain.rb +40 -11
  35. data/lib/path_coverage/kinds/choice.rb +7 -10
  36. data/lib/path_coverage/kinds/contains.rb +43 -33
  37. data/lib/path_coverage/kinds/safe.rb +44 -46
  38. data/lib/path_coverage/kinds/write.rb +6 -12
  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 +94 -59
  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 +52 -29
  48. data/lib/path_coverage/manifest_disabled.rb +97 -0
  49. data/lib/path_coverage/manifest_folding.rb +66 -26
  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 +147 -139
  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 +61 -27
  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 +184 -44
  80. metadata +36 -29
  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 -470
  86. data/lib/path_coverage/html/sort.js +0 -34
  87. data/lib/path_coverage/html/style.css +0 -470
  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 -111
  92. data/lib/path_coverage/html_cells.rb +0 -66
  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 -23
  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 -166
  101. data/lib/path_coverage/html_tabs.rb +0 -26
  102. data/lib/path_coverage/html_template.rb +0 -26
  103. data/lib/path_coverage/html_tree.rb +0 -131
@@ -1,3 +1,4 @@
1
+ require_relative 'call_trace'
1
2
  require_relative 'condition'
2
3
  require_relative 'recorder_blocks'
3
4
  require_relative 'recorder_cases'
@@ -12,78 +13,98 @@ module PathCoverage
12
13
  include RecorderChains
13
14
  include RecorderWrites
14
15
 
15
- # One evaluation's way through its site: the outcome of
16
+ # One evaluation's way through its decision: the outcome of
16
17
  # each leaf, nil for one not yet, or never, reached.
17
- Trail = Struct.new(:site, :outcomes)
18
+ Trail = Struct.new(:decision, :outcomes)
18
19
 
19
- # Starts with no outcomes, site paths or reaches counted.
20
+ # Starts with no outcomes, decision paths or reaches counted.
20
21
  def initialize
21
22
  @counts = Hash.new do |counts, key|
22
23
  counts[key] = { truthy: 0, falsy: 0 }
23
24
  end
24
- @site_paths = Hash.new do |site_paths, site|
25
- site_paths[site] = Hash.new(0)
25
+ @decision_paths = Hash.new do |decision_paths, decision|
26
+ decision_paths[decision] = Hash.new(0)
26
27
  end
27
28
  @reached = Hash.new(0)
28
29
  @trails_key = :"path_coverage_trails_#{object_id}"
30
+ @trace = CallTrace.new
29
31
  end
30
32
 
31
33
  # { name => runs } of each statement reached so far, by its
32
34
  # name, eg { "k.rb:2:2" => 2 }; none never reached.
33
35
  attr_reader :reached
34
36
 
35
- # Counts a run of the statement named name.
37
+ # The ways each call of a covered method has taken so far.
38
+ attr_reader :trace
39
+
40
+ # Counts a run of the statement named name, a step of its
41
+ # call's way.
36
42
  def reach(name)
37
43
  @reached[name] += 1
44
+ @trace.reach(name)
45
+ nil
46
+ end
47
+
48
+ # Notes a pass of the loop named name, a block called with
49
+ # one more item.
50
+ def pass(name)
51
+ @trace.pass(name)
38
52
  nil
39
53
  end
40
54
 
41
- # The stack of site's evaluations under way in the current
55
+ # The stack of decision's evaluations under way in the current
42
56
  # thread (fiber), innermost last, so another thread's never
43
57
  # mix with its.
44
- def trails(site)
58
+ def trails(decision)
45
59
  stacks = Thread.current[@trails_key] ||=
46
60
  Hash.new { |all, key| all[key] = [] }
47
- stacks[site]
61
+ stacks[decision]
48
62
  end
49
63
 
50
- # { site => { [outcome, ...] => evaluations } } for every
51
- # evaluation of a site entered and left so far.
52
- attr_reader :site_paths
64
+ # { decision => { [outcome, ...] => evaluations } } for every
65
+ # evaluation of a decision entered and left so far.
66
+ attr_reader :decision_paths
53
67
 
54
- # Starts an evaluation of site, which has size leaves, as
68
+ # Starts an evaluation of decision, which has size leaves, as
55
69
  # the trail its leaves' records fill in.
56
- def enter(site, size)
57
- trail = Trail.new(site, Array.new(size))
58
- trails(site).push(trail)
70
+ def enter(decision, size)
71
+ trail = Trail.new(decision, Array.new(size))
72
+ trails(decision).push(trail)
59
73
  trail
60
74
  end
61
75
 
62
76
  # Ends trail's evaluation, counting its path, and returns
63
- # value, the site's, unchanged. An evaluation of the same
64
- # site still entered above trail, as one that raised
77
+ # value, the decision's, unchanged. An evaluation of the same
78
+ # decision still entered above trail, as one that raised
65
79
  # leaves, took trail's later outcomes, so trail's path is
66
80
  # not counted; the stack is cleared down to trail either
67
- # way.
81
+ # way. A counted path is a step of its call's way.
68
82
  def leave(trail, value)
69
- stack = trails(trail.site)
83
+ stack = trails(trail.decision)
70
84
  clean = stack.last.equal?(trail)
71
85
  nil until stack.empty? || stack.pop.equal?(trail)
72
- @site_paths[trail.site][trail.outcomes] += 1 if clean
86
+ decided(trail) if clean
73
87
  value
74
88
  end
75
89
 
90
+ # Counts trail's path, its decision's, and steps its call's
91
+ # way with it.
92
+ def decided(trail)
93
+ @decision_paths[trail.decision][trail.outcomes] += 1
94
+ @trace.decided(trail.decision, trail.outcomes)
95
+ end
96
+
76
97
  # The truthy and falsy counts of every operand recorded so
77
- # far, keyed by [site, index]; an operand that never ran
98
+ # far, keyed by [decision, index]; an operand that never ran
78
99
  # has no entry.
79
100
  attr_reader :counts
80
101
 
81
102
  # Counts value's outcome and returns it unchanged, so the
82
103
  # condition around it behaves exactly as uninstrumented.
83
- def record(site, index, value)
104
+ def record(decision, index, value)
84
105
  outcome = value ? :truthy : :falsy
85
- @counts[[site, index]][outcome] += 1
86
- trail = trails(site).last
106
+ @counts[[decision, index]][outcome] += 1
107
+ trail = trails(decision).last
87
108
  trail.outcomes[index] = outcome == :truthy if trail
88
109
  value
89
110
  end
@@ -93,30 +114,30 @@ module PathCoverage
93
114
  # matches it against the pattern, once, as the case would
94
115
  # have.
95
116
  WhenMatch = Struct.new(
96
- :recorder, :site, :index, :total, :pattern
117
+ :recorder, :decision, :index, :total, :pattern
97
118
  ) do
98
119
  # Whether pattern matches subject, exactly as pattern says,
99
- # noted on the site's path.
120
+ # noted on the decision's path.
100
121
  def ===(subject)
101
- recorder.matched(site, index, total, pattern === subject)
122
+ recorder.matched(decision, index, total, pattern === subject)
102
123
  end
103
124
  end
104
125
 
105
126
  # The stand-in for pattern, the index-th of size in the case
106
- # at site.
107
- def when_match(site, index, size, pattern)
108
- WhenMatch.new(self, site, index, size, pattern)
127
+ # at decision.
128
+ def when_match(decision, index, size, pattern)
129
+ WhenMatch.new(self, decision, index, size, pattern)
109
130
  end
110
131
 
111
132
  # Notes whether the index-th of size patterns matched, the
112
- # first entering the case's site, and a match or the last
133
+ # first entering the case's decision, and a match or the last
113
134
  # leaving it, as no more patterns are then tried; returns
114
135
  # matched unchanged.
115
- def matched(site, index, size, matched)
116
- enter(site, size) if index.zero?
117
- record(site, index, matched)
136
+ def matched(decision, index, size, matched)
137
+ enter(decision, size) if index.zero?
138
+ record(decision, index, matched)
118
139
  last = matched || index == size - 1
119
- leave(trails(site).last, matched) if last
140
+ leave(trails(decision).last, matched) if last
120
141
  matched
121
142
  end
122
143
  end
@@ -4,38 +4,38 @@ module PathCoverage
4
4
  # The part of the recorder that notes block method calls, eg
5
5
  # ids.any? { |id| id.odd? }: how many items the block was called
6
6
  # with, as the receiver's leaf, at, and its answers, as the next
7
- # leaf; at is 0 for a call that is a site of its own. It relies
7
+ # leaf; at is 0 for a call that is a decision of its own. It relies
8
8
  # on its includer's counts, record and trails.
9
9
  module RecorderBlocks
10
- # Starts a block method's call in site, its receiver the
11
- # site's at-th leaf, its block not yet called with any item;
12
- # returns the site's current trail, nil for none.
13
- def begin_items(site, at)
14
- trail = trails(site).last
10
+ # Starts a block method's call in decision, its receiver the
11
+ # decision's at-th leaf, its block not yet called with any item;
12
+ # returns the decision's current trail, nil for none.
13
+ def begin_items(decision, at)
14
+ trail = trails(decision).last
15
15
  trail.outcomes[at] = ITEMS[0] if trail
16
16
  trail
17
17
  end
18
18
 
19
19
  # Notes value, the block's answer, as its last, and one more
20
20
  # item it was called with, for a call whose receiver is
21
- # site's at-th leaf; returns value unchanged. A block called
21
+ # decision's at-th leaf; returns value unchanged. A block called
22
22
  # where its call was not entered, eg in another fiber, is
23
23
  # counted but noted on no path.
24
- def item_at(site, at, value)
25
- trail = trails(site).last
24
+ def item_at(decision, at, value)
25
+ trail = trails(decision).last
26
26
  one_more(trail, at) if trail
27
- record(site, at + 1, value)
27
+ record(decision, at + 1, value)
28
28
  end
29
29
 
30
30
  # Notes value, the block's answer for one more item, among
31
31
  # all its answers so far: all true, all false, or both, for a
32
- # call whose receiver is site's at-th leaf; returns value
32
+ # call whose receiver is decision's at-th leaf; returns value
33
33
  # unchanged. A block called where its call was not entered
34
34
  # is counted but noted on no path.
35
- def answer_at(site, at, value)
36
- trail = trails(site).last
35
+ def answer_at(decision, at, value)
36
+ trail = trails(decision).last
37
37
  note_answer(trail, at, value) if trail
38
- @counts[[site, at + 1]][value ? :truthy : :falsy] += 1
38
+ @counts[[decision, at + 1]][value ? :truthy : :falsy] += 1
39
39
  value
40
40
  end
41
41
 
@@ -55,13 +55,13 @@ module PathCoverage
55
55
  trail.outcomes[at] = ITEMS[[called, 2].min]
56
56
  end
57
57
 
58
- # Ends a block method's call whose receiver is site's at-th
58
+ # Ends a block method's call whose receiver is decision's at-th
59
59
  # leaf, counting the receiver truthy when its block was
60
60
  # called, falsy when not; returns value unchanged. With no
61
61
  # trail, as begin_items found none, it is counted as called.
62
- def end_items(site, at, trail, value)
62
+ def end_items(decision, at, trail, value)
63
63
  called = trail.nil? || trail.outcomes[at] != ITEMS[0]
64
- @counts[[site, at]][called ? :truthy : :falsy] += 1
64
+ @counts[[decision, at]][called ? :truthy : :falsy] += 1
65
65
  value
66
66
  end
67
67
  end
@@ -1,23 +1,24 @@
1
1
  module PathCoverage
2
2
  # The part of the recorder that notes a case nested in another
3
- # site, eg (case a when 1 then b end) && c: the site around it
4
- # enters and leaves, so its patterns only note whether they
5
- # matched. It relies on its includer's record.
3
+ # decision, eg (case a when 1 then b end) && c: the decision
4
+ # around it enters and leaves, so its patterns only note
5
+ # whether they matched. It relies on its includer's record.
6
6
  module RecorderCases
7
- # A stand-in for the pattern of a case nested in site, its
8
- # match noted as the site's index-th leaf.
9
- NestedMatch = Struct.new(:recorder, :site, :index, :pattern) do
7
+ # A stand-in for the pattern of a case nested in decision, its
8
+ # match noted as the decision's index-th leaf.
9
+ NestedMatch = Struct.new(:recorder, :decision, :index,
10
+ :pattern) do
10
11
  # Whether pattern matches subject, exactly as pattern says,
11
- # noted on the site's path.
12
+ # noted on the decision's path.
12
13
  def ===(subject)
13
- recorder.record(site, index, pattern === subject)
14
+ recorder.record(decision, index, pattern === subject)
14
15
  end
15
16
  end
16
17
 
17
- # The stand-in for pattern, the index-th leaf of site, in a
18
+ # The stand-in for pattern, the index-th leaf of decision, in a
18
19
  # case nested in it.
19
- def pattern(site, index, pattern)
20
- NestedMatch.new(self, site, index, pattern)
20
+ def pattern(decision, index, pattern)
21
+ NestedMatch.new(self, decision, index, pattern)
21
22
  end
22
23
  end
23
24
  end
@@ -4,36 +4,36 @@ module PathCoverage
4
4
  # The part of the recorder that notes &. chains. It relies on
5
5
  # its includer's counts, record and trails.
6
6
  module RecorderChains
7
- # Notes value, the index-th leaf of site, a &. receiver, as
7
+ # Notes value, the index-th leaf of decision, a &. receiver, as
8
8
  # not nil or nil, and returns it unchanged; it counts truthy
9
9
  # when not nil. A receiver after a nil one in its chain,
10
10
  # whose leaves start at first, was never reached, as Ruby
11
11
  # skips the rest of the chain, so is not noted.
12
- def present(site, index, first, value)
13
- return value unless reached?(site, first, index)
12
+ def present(decision, index, first, value)
13
+ return value unless reached?(decision, first, index)
14
14
 
15
- @counts[[site, index]][value.nil? ? :falsy : :truthy] += 1
16
- trail = trails(site).last
15
+ @counts[[decision, index]][value.nil? ? :falsy : :truthy] += 1
16
+ trail = trails(decision).last
17
17
  trail.outcomes[index] = PRESENCE[value.nil? ? 1 : 0] if trail
18
18
  value
19
19
  end
20
20
 
21
21
  # Notes value, a &. chain's value as the index-th leaf of
22
- # site, as record does, when every receiver of the chain,
22
+ # decision, as record does, when every receiver of the chain,
23
23
  # whose leaves start at first, was not nil; returns value
24
24
  # unchanged.
25
- def chained(site, index, first, value)
26
- return value unless reached?(site, first, index)
25
+ def chained(decision, index, first, value)
26
+ return value unless reached?(decision, first, index)
27
27
 
28
- record(site, index, value)
28
+ record(decision, index, value)
29
29
  end
30
30
 
31
- # True when site's current evaluation reached its index-th
31
+ # True when decision's current evaluation reached its index-th
32
32
  # leaf: every leaf of its chain before it, from first, was
33
33
  # not nil. An evaluation with no trail, eg in another fiber,
34
34
  # is taken to reach it.
35
- def reached?(site, first, index)
36
- trail = trails(site).last
35
+ def reached?(decision, first, index)
36
+ trail = trails(decision).last
37
37
  trail.nil? || trail.outcomes[first...index].all?(PRESENCE[0])
38
38
  end
39
39
  end
@@ -1,25 +1,25 @@
1
1
  module PathCoverage
2
2
  # The part of the recorder that notes ||= and &&= writes: the
3
- # target's outcome at its place among its site's leaves, at 0
4
- # for a write that is a site of its own. It relies on its
3
+ # target's outcome at its place among its decision's leaves, at 0
4
+ # for a write that is a decision of its own. It relies on its
5
5
  # includer's record and trails.
6
6
  module RecorderWrites
7
- # Notes outcome as the target's, site's at-th leaf, of the
7
+ # Notes outcome as the target's, decision's at-th leaf, of the
8
8
  # write whose right side ran, false for ||=, true for &&=,
9
9
  # and returns value, the right side's, unchanged. The target
10
10
  # is never read, as reading it could call a method twice.
11
- def written_at(site, at, outcome, value)
12
- record(site, at, outcome)
11
+ def written_at(decision, at, outcome, value)
12
+ record(decision, at, outcome)
13
13
  value
14
14
  end
15
15
 
16
- # Notes skipped as the outcome of the write's target, site's
16
+ # Notes skipped as the outcome of the write's target, decision's
17
17
  # at-th leaf, when its right side never ran, so noted none;
18
18
  # returns value, the write's, unchanged.
19
- def settle(site, at, skipped, value)
20
- trail = trails(site).last
19
+ def settle(decision, at, skipped, value)
20
+ trail = trails(decision).last
21
21
  unnoted = trail.nil? || trail.outcomes[at].nil?
22
- record(site, at, skipped) if unnoted
22
+ record(decision, at, skipped) if unnoted
23
23
  value
24
24
  end
25
25
  end
@@ -1,88 +1,95 @@
1
+ require_relative 'card_context'
1
2
  require_relative 'console_summary'
2
3
  require_relative 'gaps'
3
- require_relative 'html_report'
4
4
  require_relative 'json_reader'
5
+ require_relative 'json_reports'
5
6
  require_relative 'manifest'
6
7
  require_relative 'paths_report'
7
8
  require_relative 'post'
8
- require_relative 'site_paths'
9
+ require_relative 'decision_paths'
9
10
  require_relative 'within_methods'
10
11
 
11
12
  module PathCoverage
12
- # The reporters, run from operands alone: needing nothing the
13
- # run recorded beyond them, they can run in another process.
13
+ # The JSON reports and the reporters, run from operands alone:
14
+ # needing nothing the run recorded beyond them, they can run in
15
+ # another process.
14
16
  module Render
15
- # Runs each reporter chosen in config. operands, and taken's
16
- # site_paths: and outside:, are as Result gives them, and its
17
- # reached: as Recorder#reached gives it; files is
18
- # { full path => {source:, sites:} } for each covered file.
17
+ # Writes the JSON reports, then runs each reporter chosen in
18
+ # config. operands, and taken's decision_paths: and outside:, are
19
+ # as Result gives them, and its reached: as Recorder#reached
20
+ # gives it; files is { full path => {source:, decisions:} } for
21
+ # each covered file.
19
22
  def self.run(operands, files, config, **taken)
20
- site_paths = every_site(taken.fetch(:site_paths, {}), files)
21
- reporters = config.reporters
22
- if reporters.include?(:gaps)
23
- gaps(operands, files, site_paths, taken.fetch(:outside, {}))
24
- end
25
- html_and_summary(operands, files, config,
26
- [site_paths, taken[:reached]])
27
- return unless reporters.include?(:post)
23
+ recorded = taken.merge(
24
+ decision_paths: every_decision(
25
+ taken.fetch(:decision_paths, {}), files
26
+ ),
27
+ outside: taken.fetch(:outside, {})
28
+ )
29
+ JsonReports.write(operands, files, config, **recorded)
30
+ reporters(operands, files, config, recorded)
31
+ end
28
32
 
29
- post(operands, files, config, site_paths)
33
+ # Runs each reporter chosen in config, from operands, files,
34
+ # and recorded, as run has them.
35
+ def self.reporters(operands, files, config, recorded)
36
+ paths, reached = recorded.values_at(:decision_paths, :reached)
37
+ runs = {
38
+ gaps: -> { gaps(operands, files, config, recorded) },
39
+ summary: -> { summary(files, config, paths, reached) },
40
+ ways: -> { print File.read(JsonReports.ways_path(config)) },
41
+ post: -> { post(operands, files, config, paths) }
42
+ }
43
+ runs.slice(*config.reporters).each_value(&:call)
30
44
  end
31
45
 
32
46
  # Runs the :post reporter: operands, and the paths report of
33
- # site_paths in files, with config's fingerprint.
34
- def self.post(operands, files, config, site_paths)
35
- report = PathsReport.of(site_paths, files)
47
+ # decision_paths in files, with config's fingerprint.
48
+ def self.post(operands, files, config, decision_paths)
49
+ report = PathsReport.of(decision_paths, files)
36
50
  url = config.collector_url
37
51
  fingerprint = config.fingerprint
38
52
  Post.deliver(operands, url, report, fingerprint:)
39
53
  end
40
54
 
41
- # Runs the :html and :summary reporters, each when chosen.
42
- def self.html_and_summary(operands, files, config, recorded)
43
- site_paths, reached = recorded
44
- reporters = config.reporters
45
- if reporters.include?(:html)
46
- HtmlReport.write(operands, files, config, recorded)
47
- end
48
- return unless reporters.include?(:summary)
49
-
50
- cards = WithinMethods.cards(files, config, site_paths, reached)
51
- summary(config, site_paths, cards)
52
- end
53
-
54
55
  # Prints the summary lines: the paths taken of all possible
55
- # within decisions, and, when cards are given, as they are
56
- # when methods are measured, within methods; then any
57
- # operators ignored.
58
- def self.summary(config, site_paths, cards)
59
- groups = config.groups
60
- puts ConsoleSummary.lines(site_paths, cards, groups) +
56
+ # alone, and combined, each def's card of files as decision_paths
57
+ # and reached have it; then any operators ignored.
58
+ def self.summary(files, config, decision_paths, reached)
59
+ cards = WithinMethods.cards(files, config, decision_paths,
60
+ reached)
61
+ puts ConsoleSummary.lines(decision_paths, cards,
62
+ config.groups) +
61
63
  ConsoleSummary.ignored_lines(config.ignored)
62
64
  end
63
65
 
64
- # site_paths with every site in files that it lacks, eg
66
+ # decision_paths with every decision in files that it lacks, eg
65
67
  # from a JSON report with no paths, given each possible
66
68
  # path at a count of zero: unable to say which paths such
67
- # a site took, the report claims none.
68
- def self.every_site(site_paths, files)
69
+ # a decision took, the report claims none.
70
+ def self.every_decision(decision_paths, files)
69
71
  none = files.values.each_with_object({}) do |parsed, all|
70
- parsed[:sites].each do |site, condition|
71
- all[site] = SitePaths.possible(condition).map do |path|
72
- { path:, count: 0 }
73
- end
72
+ parsed[:decisions].each do |decision, condition|
73
+ possible = DecisionPaths.possible(condition)
74
+ all[decision] = possible.map { |path| { path:, count: 0 } }
74
75
  end
75
76
  end
76
- none.merge(site_paths)
77
+ none.merge(decision_paths)
77
78
  end
78
79
 
79
- # Prints the gap lines: each path a site never took, and each
80
+ # Prints the gap lines: each path a decision never took, and each
80
81
  # path taken that a treatment rules out, as outside lists
81
- # them, each leaf named by its text in files.
82
- def self.gaps(operands, files, site_paths, outside)
82
+ # them, each leaf named by its text in files; then each path
83
+ # taken, or return or raise reached, that its method rules
84
+ # out, as CardContext.ruled_out finds them in files under
85
+ # config. recorded is as run has it.
86
+ def self.gaps(operands, files, config, recorded)
83
87
  texts = PathsReport.texts(files)
84
- paths = site_paths
88
+ paths, outside, reached =
89
+ recorded.values_at(:decision_paths, :outside, :reached)
85
90
  lines = Gaps.lines(operands, paths:, texts:, outside:)
91
+ ruled = CardContext.ruled_out(files, config, paths, reached)
92
+ lines += Gaps.ruled_by_method(ruled, texts)
86
93
  lines.each { |line| puts line }
87
94
  end
88
95
 
@@ -1,78 +1,79 @@
1
- require_relative 'site_paths'
1
+ require_relative 'decision_paths'
2
2
 
3
3
  module PathCoverage
4
- # What a run found: every site the manifest knows of, with
4
+ # What a run found: every decision the manifest knows of, with
5
5
  # the counts its operands were recorded with. Every
6
6
  # reporter builds on this.
7
7
  class Result
8
8
  NEVER_RAN = { truthy: 0, falsy: 0 }.freeze
9
9
 
10
- # sites is { site => Condition }, from the manifest;
11
- # counts is { [site, index] => counts } and site_paths is
12
- # { site => { path => evaluations } }, both from the
10
+ # decisions is { decision => Condition }, from the manifest;
11
+ # counts is { [decision, index] => counts } and decision_paths is
12
+ # { decision => { path => evaluations } }, both from the
13
13
  # recorder.
14
- def initialize(sites, counts, site_paths = {})
15
- @sites = sites
14
+ def initialize(decisions, counts, decision_paths = {})
15
+ @decisions = decisions
16
16
  @counts = counts
17
- @site_paths = site_paths
17
+ @decision_paths = decision_paths
18
18
  end
19
19
 
20
- # { site => [{ path:, count: }, ...] }: every possible path
21
- # of each site, as SitePaths gives them, with the number of
22
- # evaluations that took it, zero for one never taken.
20
+ # { decision => [{ path:, count: }, ...] }: every possible path
21
+ # of each decision, as DecisionPaths gives them, with the
22
+ # number of evaluations that took it, zero for one never
23
+ # taken.
23
24
  def paths
24
- @sites.to_h do |site, condition|
25
- taken = @site_paths.fetch(site, {})
26
- all = SitePaths.possible(condition).map do |path|
25
+ @decisions.to_h do |decision, condition|
26
+ taken = @decision_paths.fetch(decision, {})
27
+ all = DecisionPaths.possible(condition).map do |path|
27
28
  { path:, count: taken.fetch(path, 0) }
28
29
  end
29
- [site, all]
30
+ [decision, all]
30
31
  end
31
32
  end
32
33
 
33
- # { site => { path => evaluations } } of each path taken
34
- # that is none of its site's possible paths, eg a &. receiver
35
- # nil though treated as present; only sites with one. Such a
34
+ # { decision => { path => evaluations } } of each path taken
35
+ # that is none of its decision's possible paths, eg a &. receiver
36
+ # nil though treated as present; only decisions with one. Such a
36
37
  # path shows a treatment to be wrong, so it is reported, never
37
38
  # dropped.
38
39
  def outside
39
- all = @sites.to_h do |site, condition|
40
- taken = @site_paths.fetch(site, {})
41
- [site, taken.except(*SitePaths.possible(condition))]
40
+ all = @decisions.to_h do |decision, condition|
41
+ taken = @decision_paths.fetch(decision, {})
42
+ [decision, taken.except(*DecisionPaths.possible(condition))]
42
43
  end
43
44
  all.reject { |_, paths| paths.empty? }
44
45
  end
45
46
 
46
- # The paths taken, as Render.run takes them: site_paths:,
47
+ # The paths taken, as Render.run takes them: decision_paths:,
47
48
  # as paths gives them, and outside:.
48
49
  def taken
49
- { site_paths: paths, outside: }
50
+ { decision_paths: paths, outside: }
50
51
  end
51
52
 
52
- # { site => [counts of operand 0, counts of operand 1, ...] },
53
+ # { decision => [counts of operand 0, counts of operand 1, ...] },
53
54
  # with zero counts for an operand that never ran, and
54
55
  # only: naming the one outcome a fixed leaf can have.
55
56
  def operands
56
- @sites.to_h do |site, condition|
57
+ @decisions.to_h do |decision, condition|
57
58
  leaves = condition.leaves.each_with_index.map do |range, i|
58
- leaf(site, condition, range, i)
59
+ leaf(decision, condition, range, i)
59
60
  end
60
- [site, leaves]
61
+ [decision, leaves]
61
62
  end
62
63
  end
63
64
 
64
65
  private
65
66
 
66
67
  # The counts of one leaf, with only: when it is fixed.
67
- def leaf(site, condition, range, index)
68
- counts = counts_of(site, index)
68
+ def leaf(decision, condition, range, index)
69
+ counts = counts_of(decision, index)
69
70
  only = condition.fixed[range]
70
71
  only ? counts.merge(only:) : counts
71
72
  end
72
73
 
73
74
  # The recorded counts of one operand, or zeros.
74
- def counts_of(site, index)
75
- @counts.fetch([site, index], NEVER_RAN)
75
+ def counts_of(decision, index)
76
+ @counts.fetch([decision, index], NEVER_RAN)
76
77
  end
77
78
  end
78
79
  end