path_coverage 0.5.0 → 0.7.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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -153
  3. data/lib/path_coverage/call_trace.rb +26 -5
  4. data/lib/path_coverage/calls.rb +24 -0
  5. data/lib/path_coverage/condition.rb +10 -19
  6. data/lib/path_coverage/configuration_limits.rb +1 -1
  7. data/lib/path_coverage/console_summary.rb +13 -13
  8. data/lib/path_coverage/fold_cells.rb +0 -1
  9. data/lib/path_coverage/fold_rows.rb +2 -2
  10. data/lib/path_coverage/gaps.rb +1 -1
  11. data/lib/path_coverage/json_reader.rb +3 -3
  12. data/lib/path_coverage/json_reports.rb +28 -21
  13. data/lib/path_coverage/json_writer.rb +4 -4
  14. data/lib/path_coverage/kernel.rb +41 -20
  15. data/lib/path_coverage/kinds/block.rb +37 -45
  16. data/lib/path_coverage/leaving.rb +14 -6
  17. data/lib/path_coverage/loop_forks.rb +12 -26
  18. data/lib/path_coverage/loop_nodes.rb +41 -5
  19. data/lib/path_coverage/method_loops.rb +57 -13
  20. data/lib/path_coverage/method_statements.rb +25 -12
  21. data/lib/path_coverage/method_ways.rb +49 -21
  22. data/lib/path_coverage/{card_context.rb → paths_context.rb} +16 -16
  23. data/lib/path_coverage/paths_fitting.rb +31 -0
  24. data/lib/path_coverage/paths_forks.rb +72 -0
  25. data/lib/path_coverage/{card_gaps.rb → paths_gaps.rb} +38 -26
  26. data/lib/path_coverage/paths_leaving.rb +40 -0
  27. data/lib/path_coverage/paths_rescues.rb +146 -0
  28. data/lib/path_coverage/{card_scopes.rb → paths_scopes.rb} +6 -6
  29. data/lib/path_coverage/{card_tree.rb → paths_tree.rb} +20 -16
  30. data/lib/path_coverage/{card_way_lists.rb → paths_way_lists.rb} +3 -3
  31. data/lib/path_coverage/paths_ways.rb +193 -0
  32. data/lib/path_coverage/recorder.rb +21 -4
  33. data/lib/path_coverage/recorder_blocks.rb +21 -30
  34. data/lib/path_coverage/render.rb +6 -6
  35. data/lib/path_coverage/rescue_forks.rb +174 -0
  36. data/lib/path_coverage/rewriter.rb +83 -14
  37. data/lib/path_coverage/source_report.rb +4 -4
  38. data/lib/path_coverage/stable_leaves.rb +3 -3
  39. data/lib/path_coverage/statement_arms.rb +23 -9
  40. data/lib/path_coverage/totals.rb +5 -5
  41. data/lib/path_coverage/version.rb +1 -1
  42. data/lib/path_coverage/way_algebras.rb +2 -2
  43. data/lib/path_coverage/ways_report.rb +8 -8
  44. data/lib/path_coverage/ways_totals.rb +7 -7
  45. data/lib/path_coverage/within_methods.rb +62 -62
  46. metadata +12 -8
  47. data/lib/path_coverage/card_forks.rb +0 -44
  48. data/lib/path_coverage/card_ways.rb +0 -196
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: path_coverage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jagger
@@ -39,13 +39,6 @@ files:
39
39
  - lib/path_coverage/auto.rb
40
40
  - lib/path_coverage/call_trace.rb
41
41
  - lib/path_coverage/calls.rb
42
- - lib/path_coverage/card_context.rb
43
- - lib/path_coverage/card_forks.rb
44
- - lib/path_coverage/card_gaps.rb
45
- - lib/path_coverage/card_scopes.rb
46
- - lib/path_coverage/card_tree.rb
47
- - lib/path_coverage/card_way_lists.rb
48
- - lib/path_coverage/card_ways.rb
49
42
  - lib/path_coverage/code_tokens.rb
50
43
  - lib/path_coverage/collector.rb
51
44
  - lib/path_coverage/condition.rb
@@ -91,7 +84,17 @@ files:
91
84
  - lib/path_coverage/method_loops.rb
92
85
  - lib/path_coverage/method_statements.rb
93
86
  - lib/path_coverage/method_ways.rb
87
+ - lib/path_coverage/paths_context.rb
88
+ - lib/path_coverage/paths_fitting.rb
89
+ - lib/path_coverage/paths_forks.rb
90
+ - lib/path_coverage/paths_gaps.rb
91
+ - lib/path_coverage/paths_leaving.rb
94
92
  - lib/path_coverage/paths_report.rb
93
+ - lib/path_coverage/paths_rescues.rb
94
+ - lib/path_coverage/paths_scopes.rb
95
+ - lib/path_coverage/paths_tree.rb
96
+ - lib/path_coverage/paths_way_lists.rb
97
+ - lib/path_coverage/paths_ways.rb
95
98
  - lib/path_coverage/post.rb
96
99
  - lib/path_coverage/recorder.rb
97
100
  - lib/path_coverage/recorder_blocks.rb
@@ -99,6 +102,7 @@ files:
99
102
  - lib/path_coverage/recorder_chains.rb
100
103
  - lib/path_coverage/recorder_writes.rb
101
104
  - lib/path_coverage/render.rb
105
+ - lib/path_coverage/rescue_forks.rb
102
106
  - lib/path_coverage/result.rb
103
107
  - lib/path_coverage/rewriter.rb
104
108
  - lib/path_coverage/rewriter_nested.rb
@@ -1,44 +0,0 @@
1
- module PathCoverage
2
- # How the loops of a card fork when loops are decisions, each of
3
- # forks being { loop's name => [its bytes, its body's] }, as
4
- # LoopForks gives them: a loop is placed as a row that is no
5
- # decision is, by its bytes; its body is a region of it run on
6
- # its path 1, at least one item, so holds its rows; its path 0
7
- # is no item. Its module functions place it, for CardTree; its
8
- # instance method folds it, for CardWays, which includes it.
9
- module CardForks
10
- # The region of each loop of forks: its body, run on its path
11
- # 1.
12
- def self.regions(forks)
13
- forks.map do |name, (_, body)|
14
- CardTree::Region.new(owner: CardTree.key_at(name),
15
- range: body, arm: 'body', on: [1],
16
- leaf: nil, leaves: nil)
17
- end
18
- end
19
-
20
- # places, { key => its place }, a card's rows', with the place
21
- # of each loop of forks too, among regions, all in the order
22
- # they start; places alone with no loop.
23
- def self.placed(places, forks, regions)
24
- return places if forks.empty?
25
-
26
- loops = forks.to_h do |name, (span, _)|
27
- key = CardTree.key_at(name)
28
- [key, CardTree.placed(key, span, regions, nil)]
29
- end
30
- merged = places.merge(loops)
31
- merged.sort_by { _1[0].split(':').map(&:to_i) }.to_h
32
- end
33
-
34
- # The pair of the loop keyed key, placed but no row: no pass,
35
- # going on, or at least one, then the rows of its body one
36
- # after another, walked once.
37
- def fork_pair(key)
38
- pairs = running(key, 1).map { pair_of(_1) }
39
- own = @ways.unit([key, 1])
40
- some = sequence(pairs).map { @ways.times(own, _1) }
41
- added([[@ways.unit([key, 0]), @ways.zero], some])
42
- end
43
- end
44
- end
@@ -1,196 +0,0 @@
1
- require_relative 'card_tree'
2
- require_relative 'manifest'
3
- require_relative 'method_statements'
4
- require_relative 'decision_paths'
5
- require_relative 'stable_leaves'
6
- require_relative 'way_algebras'
7
-
8
- module PathCoverage
9
- # The ways one call can go through each card, folded over its
10
- # tree, as CardTree places its rows. Each row gives a pair,
11
- # [ways that go on, ways that leave the method]: a return or a
12
- # raise leaves, and so does each path of a decision taking an
13
- # arm that returns or raises, eg return 0 if a. Rows one after
14
- # another multiply, but only the ways that go on reach the next
15
- # row; a decision adds up its paths, each with the rows it runs
16
- # on that path one after another; and a row that is the whole of
17
- # a leaf counts only those of its paths that give the leaf the
18
- # outcome the path has, so no impossible way is counted where
19
- # gives knows it. A block's body counts once, unless the block
20
- # forks, as CardForks folds it.
21
- # Each way also notes the outcome it gives each leaf that
22
- # StableLeaves finds, by its local's name, and two ways joined
23
- # one after the other that give one name both outcomes are no
24
- # way, as no call can take them.
25
- # The fold is in one of WayAlgebras: Counted counts the ways,
26
- # by default; Labelled gives the paths taken on any of them, and
27
- # Listed lists them.
28
- class CardWays
29
- include CardForks
30
-
31
- # Example: { "k.rb:1:0" => 3 } for def f(a, b), return 0 if a,
32
- # then a ?: of b: 1 way leaves, 2 go on.
33
- # { def decision => its ways, in algebra } for each def in
34
- # source, its decisions those of no settings.
35
- def self.of(source, path, algebra = WayAlgebras::Counted)
36
- decisions = Manifest.decisions(source, path)
37
- cards = MethodStatements.of(source, path, decisions)
38
- cards.transform_values do |rows|
39
- card(source, decisions, rows, algebra)
40
- end
41
- end
42
-
43
- # The ways through a card of rows in source, in algebra,
44
- # decisions being { decision => Condition }, as
45
- # Manifest.decisions gives them; folding is [stable, forks]:
46
- # with stable false, those no call can take too, as no leaf is
47
- # then assigned; each loop of forks, as LoopForks gives them,
48
- # a fork, labelled [its key, 0] for 0 items, [its key, 1] for
49
- # 1+ items, then its body's rows, walked once.
50
- def self.card(source, decisions, rows,
51
- algebra = WayAlgebras::Counted,
52
- folding = [true, {}])
53
- stable, forks = folding
54
- places = CardTree.nested(source, decisions, rows, forks)
55
- names = stable ? StableLeaves.of(source, decisions, rows) : {}
56
- new(source, rows, places, decisions, [algebra, names]).total
57
- end
58
-
59
- # The fold of rows, a card's in source, placed as places has
60
- # them, each decision row's Condition among decisions; folding
61
- # is [algebra, names]: its ways in algebra, each step of it a
62
- # tally of them, as WayAlgebras::Tallied has them, assigning
63
- # the leaves names has, as StableLeaves finds them.
64
- def initialize(source, rows, places, decisions, (algebra, names))
65
- @source = source
66
- @rows = rows.to_h { |row| [CardTree.key_of(row), row] }
67
- @places = places
68
- @decisions = decisions
69
- @ways = WayAlgebras::Tallied.new(algebra)
70
- @children = places.keys.group_by { places[_1]['parent'] }
71
- @names = names
72
- end
73
-
74
- # The ways through the card, in its algebra: its top rows'
75
- # pairs, one after another, those that go on and those that
76
- # leave, whatever their assignments.
77
- def total
78
- tops = @children.fetch(nil, []).map { |key| pair_of(key) }
79
- @ways.total(@ways.plus(*sequence(tops)))
80
- end
81
-
82
- # The pair of rows one after another, from their pairs: the
83
- # ways that go on through them all, and those that leave at
84
- # one of them, having gone on through every one before it.
85
- def sequence(pairs)
86
- start = [@ways.one, @ways.zero]
87
- pairs.reduce(start) do |(on, left), (more, out)|
88
- through = @ways.times(on, out)
89
- [@ways.times(on, more), @ways.plus(left, through)]
90
- end
91
- end
92
-
93
- # The pair of the row keyed key: a decision's adds up its paths'
94
- # pairs; any other row is a return or a raise, as no other is
95
- # a row, so leaves, at its one path.
96
- def pair_of(key)
97
- return fork_pair(key) unless @rows.key?(key)
98
-
99
- row = @rows[key]
100
- leaves = [@ways.zero, @ways.unit([key, 0])]
101
- return leaves if row.decision.nil?
102
-
103
- pairs = possible(row.decision).each_index.map do |path|
104
- pair_on(key, path)
105
- end
106
- added(pairs)
107
- end
108
-
109
- # The pair of the decision row keyed key on its path at index
110
- # path: that path taken, then the rows it runs on that path,
111
- # one after another, each given that path's outcomes; every
112
- # way of it leaving when the path takes an arm that leaves.
113
- def pair_on(key, path)
114
- outcomes = possible(@rows[key].decision)[path]
115
- pairs = running(key, path).map do |child|
116
- child_pair(child, outcomes)
117
- end
118
- own = own(key, path, outcomes)
119
- on, left = sequence(pairs).map { @ways.times(own, _1) }
120
- return [on, left] unless leaving(key).include?(path)
121
-
122
- [@ways.zero, @ways.plus(on, left)]
123
- end
124
-
125
- # The tally of the one way that takes the decision row keyed
126
- # key's path at index path, with outcomes, giving each name
127
- # the outcome of its leaves on it; no way when it gives a name
128
- # both outcomes, as eg a && b || a && c does with a true then
129
- # false.
130
- def own(key, path, outcomes)
131
- named = named(key, outcomes)
132
- assignment = named.to_h
133
- return @ways.zero if assignment.size < named.size
134
-
135
- @ways.unit([key, path], assignment)
136
- end
137
-
138
- # The distinct [name, outcome] of each leaf, of the decision of
139
- # the row keyed key, that outcomes reaches and that has a name.
140
- def named(key, outcomes)
141
- leaves = @decisions.fetch(@rows[key].decision).leaves
142
- leaves.zip(outcomes).filter_map do |range, outcome|
143
- next if outcome.nil? || !@names.key?(range)
144
-
145
- [@names[range], outcome]
146
- end.uniq
147
- end
148
-
149
- # The keys of the rows the decision row keyed key runs on its path
150
- # at index path, in the order they are written.
151
- def running(key, path)
152
- runs = @children.fetch(key, []).group_by do |child|
153
- @places[child]['on'].include?(path)
154
- end
155
- runs.fetch(true, [])
156
- end
157
-
158
- # The pair of the row keyed child, its parent's path having
159
- # outcomes: all of its own, for a row that gives nothing; else
160
- # those of only its paths that give its leaf the outcome that
161
- # path has, or that give what is not known.
162
- def child_pair(child, outcomes)
163
- place = @places[child]
164
- gives = place['gives']
165
- return pair_of(child) if gives.nil?
166
-
167
- fits = [nil, outcomes[place['leaf']]]
168
- none = [@ways.zero, @ways.zero]
169
- pairs = gives.each_index.map do |path|
170
- fits.include?(gives[path]) ? pair_on(child, path) : none
171
- end
172
- added(pairs)
173
- end
174
-
175
- # The indices of the paths of the decision row keyed key that take
176
- # an arm whose code returns or raises.
177
- def leaving(key)
178
- decision = @decisions.fetch(@rows[key].decision)
179
- regions = CardTree.regions_of(@source, key, decision)
180
- regions.select(&:leaves).flat_map(&:on)
181
- end
182
-
183
- # pairs added up, each part on its own; no ways for no pairs.
184
- def added(pairs)
185
- none = [@ways.zero, @ways.zero]
186
- pairs.reduce(none) do |(on, left), (more, out)|
187
- [@ways.plus(on, more), @ways.plus(left, out)]
188
- end
189
- end
190
-
191
- # The possible paths of the decision named decision.
192
- def possible(decision)
193
- DecisionPaths.possible(@decisions.fetch(decision))
194
- end
195
- end
196
- end