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.
- checksums.yaml +4 -4
- data/README.md +316 -177
- data/exe/path_coverage_report +4 -0
- data/lib/path_coverage/call_trace.rb +88 -0
- data/lib/path_coverage/calls.rb +49 -43
- data/lib/path_coverage/card_context.rb +104 -0
- data/lib/path_coverage/card_forks.rb +44 -0
- data/lib/path_coverage/card_gaps.rb +125 -0
- data/lib/path_coverage/card_scopes.rb +37 -0
- data/lib/path_coverage/card_tree.rb +199 -0
- data/lib/path_coverage/card_way_lists.rb +72 -0
- data/lib/path_coverage/card_ways.rb +196 -0
- data/lib/path_coverage/{html_syntax.rb → code_tokens.rb} +38 -25
- data/lib/path_coverage/condition.rb +14 -14
- data/lib/path_coverage/configuration.rb +7 -4
- data/lib/path_coverage/configuration_limits.rb +52 -0
- data/lib/path_coverage/configuration_paths.rb +7 -7
- data/lib/path_coverage/console_summary.rb +24 -22
- data/lib/path_coverage/{site.rb → decision.rb} +2 -2
- data/lib/path_coverage/decision_locations.rb +76 -0
- data/lib/path_coverage/{site_paths.rb → decision_paths.rb} +18 -8
- data/lib/path_coverage/{site_tree.rb → decision_tree.rb} +25 -16
- data/lib/path_coverage/fold_branches.rb +18 -0
- data/lib/path_coverage/fold_cells.rb +42 -0
- data/lib/path_coverage/fold_rows.rb +140 -0
- data/lib/path_coverage/gaps.rb +33 -15
- data/lib/path_coverage/json_reader.rb +54 -19
- data/lib/path_coverage/json_reports.rb +102 -0
- data/lib/path_coverage/json_writer.rb +31 -16
- data/lib/path_coverage/kernel.rb +56 -57
- data/lib/path_coverage/kinds/base.rb +16 -16
- data/lib/path_coverage/kinds/block.rb +16 -15
- data/lib/path_coverage/kinds/case.rb +14 -17
- data/lib/path_coverage/kinds/chain.rb +40 -11
- data/lib/path_coverage/kinds/choice.rb +7 -10
- data/lib/path_coverage/kinds/contains.rb +43 -33
- data/lib/path_coverage/kinds/safe.rb +44 -46
- data/lib/path_coverage/kinds/write.rb +6 -12
- data/lib/path_coverage/kinds.rb +2 -2
- data/lib/path_coverage/leaving.rb +44 -0
- data/lib/path_coverage/loop_forks.rb +57 -0
- data/lib/path_coverage/loop_nodes.rb +55 -0
- data/lib/path_coverage/manifest.rb +94 -59
- data/lib/path_coverage/manifest_blocks.rb +5 -26
- data/lib/path_coverage/manifest_case.rb +2 -2
- data/lib/path_coverage/manifest_chains.rb +8 -8
- data/lib/path_coverage/manifest_choices.rb +52 -29
- data/lib/path_coverage/manifest_disabled.rb +97 -0
- data/lib/path_coverage/manifest_folding.rb +66 -26
- data/lib/path_coverage/manifest_ignoring.rb +6 -6
- data/lib/path_coverage/manifest_writes.rb +11 -10
- data/lib/path_coverage/measured_by.rb +20 -0
- data/lib/path_coverage/merge.rb +7 -7
- data/lib/path_coverage/method_loops.rb +128 -0
- data/lib/path_coverage/method_statements.rb +147 -139
- data/lib/path_coverage/method_ways.rb +142 -0
- data/lib/path_coverage/paths_report.rb +16 -16
- data/lib/path_coverage/recorder.rb +57 -36
- data/lib/path_coverage/recorder_blocks.rb +17 -17
- data/lib/path_coverage/recorder_cases.rb +12 -11
- data/lib/path_coverage/recorder_chains.rb +12 -12
- data/lib/path_coverage/recorder_writes.rb +9 -9
- data/lib/path_coverage/render.rb +58 -51
- data/lib/path_coverage/result.rb +32 -31
- data/lib/path_coverage/rewriter.rb +39 -27
- data/lib/path_coverage/rewriter_nested.rb +13 -13
- data/lib/path_coverage/runs_report.rb +84 -0
- data/lib/path_coverage/source_lines.rb +16 -16
- data/lib/path_coverage/source_report.rb +100 -0
- data/lib/path_coverage/stable_leaves.rb +162 -0
- data/lib/path_coverage/statement_arms.rb +61 -27
- data/lib/path_coverage/summary.rb +4 -62
- data/lib/path_coverage/totals.rb +10 -8
- data/lib/path_coverage/version.rb +1 -1
- data/lib/path_coverage/walk.rb +106 -0
- data/lib/path_coverage/way_algebras.rb +127 -0
- data/lib/path_coverage/ways_report.rb +91 -0
- data/lib/path_coverage/ways_totals.rb +46 -0
- data/lib/path_coverage/within_methods.rb +184 -44
- metadata +36 -29
- data/lib/path_coverage/card.rb +0 -14
- data/lib/path_coverage/html/file.html +0 -33
- data/lib/path_coverage/html/index.html +0 -29
- data/lib/path_coverage/html/settings.js +0 -50
- data/lib/path_coverage/html/side.js +0 -470
- data/lib/path_coverage/html/sort.js +0 -34
- data/lib/path_coverage/html/style.css +0 -470
- data/lib/path_coverage/html/tabs.js +0 -15
- data/lib/path_coverage/html/theme.js +0 -27
- data/lib/path_coverage/html_branch.rb +0 -30
- data/lib/path_coverage/html_cards.rb +0 -111
- data/lib/path_coverage/html_cells.rb +0 -66
- data/lib/path_coverage/html_file.rb +0 -123
- data/lib/path_coverage/html_index.rb +0 -128
- data/lib/path_coverage/html_index_head.rb +0 -29
- data/lib/path_coverage/html_labels.rb +0 -23
- data/lib/path_coverage/html_methods.rb +0 -66
- data/lib/path_coverage/html_nav.rb +0 -67
- data/lib/path_coverage/html_report.rb +0 -131
- data/lib/path_coverage/html_statements.rb +0 -166
- data/lib/path_coverage/html_tabs.rb +0 -26
- data/lib/path_coverage/html_template.rb +0 -26
- data/lib/path_coverage/html_tree.rb +0 -131
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
require_relative 'card_forks'
|
|
2
|
+
require_relative 'manifest'
|
|
3
|
+
require_relative 'method_statements'
|
|
4
|
+
require_relative 'decision_paths'
|
|
5
|
+
require_relative 'decision_tree'
|
|
6
|
+
|
|
7
|
+
module PathCoverage
|
|
8
|
+
# How the rows of each card nest: for each row, the decision it
|
|
9
|
+
# runs inside, the arm of that decision it is in, and the paths of
|
|
10
|
+
# that decision on which it runs, so a reader can tell which paths
|
|
11
|
+
# reach a row, and count the paths through a card as a whole.
|
|
12
|
+
module CardTree
|
|
13
|
+
# Part of a decision's code that a row can be inside: an arm of
|
|
14
|
+
# statements, or a leaf; owner the key of the decision's row,
|
|
15
|
+
# range its bytes, arm its arm's name, nil for a leaf, on
|
|
16
|
+
# the indices of the decision's possible paths that run it, and
|
|
17
|
+
# leaf a leaf's index among the decision's leaves, nil for an arm,
|
|
18
|
+
# and leaves its arm's Leaving word, nil for a leaf or an arm that
|
|
19
|
+
# does not leave the method.
|
|
20
|
+
Region = Data.define(:owner, :range, :arm, :on, :leaf, :leaves)
|
|
21
|
+
|
|
22
|
+
# The place of a row inside no other row's decision.
|
|
23
|
+
TOP = { 'parent' => nil, 'in' => nil, 'on' => nil,
|
|
24
|
+
'leaf' => nil, 'gives' => nil }.freeze
|
|
25
|
+
|
|
26
|
+
# Example: def f(a); if a then 1 end; end gives the value
|
|
27
|
+
# row 1 its parent, the if, in its then arm, on its path 0.
|
|
28
|
+
# { def decision => { "line:column" => { 'parent' =>, 'in' =>,
|
|
29
|
+
# 'on' =>, 'leaf' =>, 'gives' => } } } for each def in
|
|
30
|
+
# source, a row keyed by where it is named. parent is the
|
|
31
|
+
# "line:column" of the decision the row runs inside, in the name
|
|
32
|
+
# of its arm, on the indices of that decision's possible paths,
|
|
33
|
+
# as DecisionPaths.possible orders them, that run the row, leaf
|
|
34
|
+
# the index of that decision's leaf holding it, and gives, for a
|
|
35
|
+
# row whose decision is the whole of that leaf, the leaf's
|
|
36
|
+
# outcome on each of the row's own possible paths, nil where
|
|
37
|
+
# not known; each nil where it does not apply.
|
|
38
|
+
def self.of(source, path, decisions = nil)
|
|
39
|
+
decisions = Manifest.decisions(source, path) if decisions.nil?
|
|
40
|
+
cards = MethodStatements.of(source, path, decisions)
|
|
41
|
+
cards.transform_values { nested(source, decisions, _1) }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# { "line:column" => its place } for each of rows, a card's,
|
|
45
|
+
# each placed in the innermost region of another row's
|
|
46
|
+
# decision holding all of its own decision's code, or, for a
|
|
47
|
+
# row that is no decision, where it starts: a decision
|
|
48
|
+
# starting where its child does, eg an || whose first operand
|
|
49
|
+
# is an any?, holds that child, and is not held by it. Each of
|
|
50
|
+
# forks, { loop's name => [its bytes, its body's] }, as
|
|
51
|
+
# LoopForks gives them, is placed too, as CardForks places it.
|
|
52
|
+
def self.nested(source, decisions, rows, forks = {})
|
|
53
|
+
regions = card_regions(source, decisions, rows) +
|
|
54
|
+
CardForks.regions(forks)
|
|
55
|
+
places = rows_placed(source, rows, [decisions, regions])
|
|
56
|
+
CardForks.placed(places, forks, regions)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# { "line:column" => its place } for each of rows, a card's,
|
|
60
|
+
# among regions, as nested places them.
|
|
61
|
+
def self.rows_placed(source, rows, (decisions, regions))
|
|
62
|
+
starts = line_starts(source)
|
|
63
|
+
rows.to_h do |row|
|
|
64
|
+
at = starts[row.line - 1] + row.column
|
|
65
|
+
decision = row.decision ? decisions.fetch(row.decision) : nil
|
|
66
|
+
span = decision ? decision.extent : at...(at + 1)
|
|
67
|
+
key = key_of(row)
|
|
68
|
+
[key, placed(key, span, regions, decision)]
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# The regions of the decisions of rows, a card's, decisions being
|
|
73
|
+
# { decision => Condition }.
|
|
74
|
+
def self.card_regions(source, decisions, rows)
|
|
75
|
+
rows.select(&:decision).flat_map do |row|
|
|
76
|
+
regions_of(source, key_of(row), decisions.fetch(row.decision))
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# The place of the row keyed key, its code the bytes span,
|
|
81
|
+
# decision its Condition, nil for a row that is no decision:
|
|
82
|
+
# in the decision owning the smallest region of another row
|
|
83
|
+
# holding span, as place gives it; TOP for a row in no such
|
|
84
|
+
# region.
|
|
85
|
+
def self.placed(key, span, regions, decision)
|
|
86
|
+
holding = holding(key, span, regions)
|
|
87
|
+
inner = smallest(holding)
|
|
88
|
+
return TOP if inner.nil?
|
|
89
|
+
|
|
90
|
+
owner = inner.owner
|
|
91
|
+
own = holding.group_by(&:owner).fetch(owner)
|
|
92
|
+
place(owner, own).merge(leaf_place(own, decision))
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# The leaf and gives of a row's place, own being the regions
|
|
96
|
+
# of its parent holding it, decision its Condition: the index of
|
|
97
|
+
# the innermost leaf holding it; and, when decision is the whole
|
|
98
|
+
# of that leaf, decision's value on each of its possible paths,
|
|
99
|
+
# as its kind gives them, the leaf's outcome there. Neither
|
|
100
|
+
# for a row that is no decision, a return or a raise, which gives
|
|
101
|
+
# its parent nothing.
|
|
102
|
+
def self.leaf_place(own, decision)
|
|
103
|
+
return { 'leaf' => nil, 'gives' => nil } if decision.nil?
|
|
104
|
+
|
|
105
|
+
leaf = smallest(own.reject(&:arm))
|
|
106
|
+
whole = leaf && decision.extent == leaf.range
|
|
107
|
+
gives = whole ? DecisionPaths.values(decision) : nil
|
|
108
|
+
{ 'leaf' => leaf&.leaf, 'gives' => gives }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# The regions of regions holding all of the bytes span, but
|
|
112
|
+
# for those of the row keyed key itself.
|
|
113
|
+
def self.holding(key, span, regions)
|
|
114
|
+
held = regions.group_by do |region|
|
|
115
|
+
region.owner != key && region.range.cover?(span)
|
|
116
|
+
end
|
|
117
|
+
held.fetch(true, [])
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# A row's place in the decision of the row keyed owner, own being
|
|
121
|
+
# the regions of that decision holding the row: the innermost arm
|
|
122
|
+
# of them, nil for none, and the paths on which every one of
|
|
123
|
+
# them runs, as the row runs only where all of them do.
|
|
124
|
+
def self.place(owner, own)
|
|
125
|
+
arm = smallest(own.select(&:arm))
|
|
126
|
+
on = own.map(&:on).reduce(:&)
|
|
127
|
+
{ 'parent' => owner, 'in' => arm&.arm, 'on' => on }
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# The region of regions with the fewest bytes; nil for none.
|
|
131
|
+
def self.smallest(regions) = regions.min_by { _1.range.size }
|
|
132
|
+
|
|
133
|
+
# The regions of condition, the decision of the row keyed owner:
|
|
134
|
+
# its arms', and its leaves'.
|
|
135
|
+
def self.regions_of(source, owner, condition)
|
|
136
|
+
possible = DecisionPaths.possible(condition)
|
|
137
|
+
node = DecisionTree.node(source, condition, possible,
|
|
138
|
+
(0..).each)
|
|
139
|
+
arm_regions(owner, condition, node) +
|
|
140
|
+
leaf_regions(owner, condition, possible)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# The regions of condition's leaves, in no arm, each run on
|
|
144
|
+
# the paths of possible with an outcome at its index.
|
|
145
|
+
def self.leaf_regions(owner, condition, possible)
|
|
146
|
+
condition.leaves.each_with_index.map do |range, index|
|
|
147
|
+
skipped = possible.each_index.group_by do |i|
|
|
148
|
+
possible[i][index].nil?
|
|
149
|
+
end
|
|
150
|
+
on = skipped.fetch(false)
|
|
151
|
+
Region.new(owner:, range:, arm: nil, on:, leaf: index,
|
|
152
|
+
leaves: nil)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# The regions of the arms in condition, node its tree, each
|
|
157
|
+
# operand's node at its own index: of its own arms, and of
|
|
158
|
+
# those of each condition nested in it, in an operand or in
|
|
159
|
+
# an arm's body.
|
|
160
|
+
def self.arm_regions(owner, condition, node)
|
|
161
|
+
built = condition.operands.zip(node[:operands])
|
|
162
|
+
built.flat_map do |operand, operand_node|
|
|
163
|
+
case operand
|
|
164
|
+
when Condition then arm_regions(owner, operand, operand_node)
|
|
165
|
+
when Arm then arm_region(owner, operand, operand_node)
|
|
166
|
+
else []
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# The regions of arm, node its node: its own, named by its
|
|
172
|
+
# kind and run on the paths that take it, none for an arm
|
|
173
|
+
# with no statements, which holds no row; then its body's.
|
|
174
|
+
def self.arm_region(owner, arm, node)
|
|
175
|
+
body = arm.body ? arm_regions(owner, arm.body, node[:body]) : []
|
|
176
|
+
return body if arm.extent.nil?
|
|
177
|
+
|
|
178
|
+
cells = node[:cells]
|
|
179
|
+
on = cells.each_index.group_by { cells[_1] }.fetch(true, [])
|
|
180
|
+
own = Region.new(owner:, range: arm.extent, arm: arm.kind.to_s,
|
|
181
|
+
on:, leaf: nil, leaves: arm.leaves)
|
|
182
|
+
[own, *body]
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# The "line:column" key of row, from its name.
|
|
186
|
+
def self.key_of(row) = key_at(row.name)
|
|
187
|
+
|
|
188
|
+
# The "line:column" key of the row or loop named name.
|
|
189
|
+
def self.key_at(name) = name.split(':').last(2).join(':')
|
|
190
|
+
|
|
191
|
+
# The byte offset where each line of source starts, first
|
|
192
|
+
# line first.
|
|
193
|
+
def self.line_starts(source)
|
|
194
|
+
source.each_line.reduce([0]) do |starts, line|
|
|
195
|
+
starts << (starts.last + line.bytesize)
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require_relative 'method_ways'
|
|
2
|
+
require_relative 'ways_report'
|
|
3
|
+
|
|
4
|
+
module PathCoverage
|
|
5
|
+
# The ways a method's card lists for the JSON report: those its
|
|
6
|
+
# calls took, its loops' passes, and of the ways one call can take,
|
|
7
|
+
# those some call took, covered, and those none did, gaps.
|
|
8
|
+
module CardWayLists
|
|
9
|
+
# { "taken", "passes" } of the method whose entry is named
|
|
10
|
+
# entry: the ways its calls took, ways being { unit's name =>
|
|
11
|
+
# { way => count } }, as a CallTrace counts them; and the passes
|
|
12
|
+
# of each of loops, the names of the method's loops.
|
|
13
|
+
def self.walked(entry, ways, loops)
|
|
14
|
+
{ 'taken' => WaysReport.taken(ways.fetch(entry, {})),
|
|
15
|
+
'passes' => passes(ways, loops) }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# { "covered", "gaps", "impossible", "impossible_taken" } of
|
|
19
|
+
# the method whose entry is named entry, ways as walked has
|
|
20
|
+
# them; checked [split, forked]: split [possible, impossible],
|
|
21
|
+
# the ways one call can take, and those none can, as
|
|
22
|
+
# MethodWays.split_card lists them, forked the names of the
|
|
23
|
+
# loops that fork there.
|
|
24
|
+
def self.checked(entry, ways, ((possible, impossible), forked))
|
|
25
|
+
seen = witnessed(ways.fetch(entry, {}), forked)
|
|
26
|
+
{ 'covered' => covered(possible, seen),
|
|
27
|
+
'gaps' => listed(split(possible, seen).last),
|
|
28
|
+
'impossible' => listed(impossible),
|
|
29
|
+
'impossible_taken' => listed(split(impossible, seen).first) }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# [taken, untaken] of ways: those some call witnessed, as seen
|
|
33
|
+
# counts them, and those none did.
|
|
34
|
+
def self.split(ways, seen)
|
|
35
|
+
by = ways.group_by { seen.key?(MethodWays.matched(_1)) }
|
|
36
|
+
[by.fetch(true, []), by.fetch(false, [])]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Each of ways as the JSON report lists a way.
|
|
40
|
+
def self.listed(ways)
|
|
41
|
+
ways.map { WaysReport.way(_1) }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# { loop's at => its passes' ways, as WaysReport.taken lists
|
|
45
|
+
# them } of each of loops, ways as of has them.
|
|
46
|
+
def self.passes(ways, loops)
|
|
47
|
+
loops.to_h do |loop|
|
|
48
|
+
[WaysReport.at(loop), WaysReport.taken(ways.fetch(loop, {}))]
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# { way => how many calls witnessed it } of walked, { way =>
|
|
53
|
+
# count }, each way's steps ordered, as MethodWays.witnessed
|
|
54
|
+
# gives them, each loop of forked a fork.
|
|
55
|
+
def self.witnessed(walked, forked)
|
|
56
|
+
walked.each_with_object(Hash.new(0)) do |(way, count), seen|
|
|
57
|
+
MethodWays.witnessed(way, forked).each { seen[_1] += count }
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# [{ "way", "count" }] of each of possible some call took, as
|
|
62
|
+
# seen counts them.
|
|
63
|
+
def self.covered(possible, seen)
|
|
64
|
+
possible.filter_map do |way|
|
|
65
|
+
count = seen.fetch(MethodWays.matched(way), 0)
|
|
66
|
+
next unless count.positive?
|
|
67
|
+
|
|
68
|
+
{ 'way' => WaysReport.way(way), 'count' => count }
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,196 @@
|
|
|
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
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
require 'cgi/escape'
|
|
2
1
|
require 'prism'
|
|
3
2
|
|
|
4
3
|
module PathCoverage
|
|
5
4
|
# The colours of a file's code on its page: each token Prism
|
|
6
5
|
# lexes, as Ruby itself does, gets the class of its kind, eg k
|
|
7
6
|
# for a keyword, so the page's CSS colours it.
|
|
8
|
-
module
|
|
7
|
+
module CodeTokens
|
|
9
8
|
# The class of each coloured token type that is not a keyword
|
|
10
9
|
# or a number: c comment, s string, t constant, v instance
|
|
11
10
|
# variable, o an operator that decides a path.
|
|
@@ -116,41 +115,55 @@ module PathCoverage
|
|
|
116
115
|
end
|
|
117
116
|
end
|
|
118
117
|
|
|
119
|
-
# The names of the operators that decide a path, as a
|
|
118
|
+
# The names of the operators that decide a path, as a decision
|
|
120
119
|
# tree's labels write them. Alone, some lex as other tokens,
|
|
121
120
|
# eg ?: as a character and || as two pipes, so each is
|
|
122
121
|
# coloured as an operator by name.
|
|
123
122
|
DECIDING = %w[&& || &. ?: &&= ||=].freeze
|
|
124
123
|
|
|
125
|
-
#
|
|
126
|
-
#
|
|
127
|
-
#
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
# Example: x && y as { text: 'x && y', tokens: [[2, 4, 'o']] }.
|
|
125
|
+
# text, a fragment of code on one line, eg a decision tree's
|
|
126
|
+
# operator or operand, as page data holds it: its text and the
|
|
127
|
+
# [from, to, class] of each range coloured as the code it is
|
|
128
|
+
# part of; one of DECIDING wholly the operator it names.
|
|
129
|
+
def self.code(text)
|
|
130
|
+
return { text:, tokens: [[0, text.length, 'o']] } if
|
|
131
|
+
DECIDING.include?(text)
|
|
132
|
+
|
|
133
|
+
{ text:, tokens: of(text).fetch(1, []) }
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Example: if/else, each of if and else a keyword.
|
|
137
|
+
# The code of a row's or a fold's label, coloured as code
|
|
138
|
+
# colours it; but a label naming a choice and its else, eg
|
|
139
|
+
# if/else, each of its words, as code would read /else as a
|
|
140
|
+
# regexp's start.
|
|
141
|
+
def self.label_code(text)
|
|
142
|
+
return code(text) unless text.match?(%r{\A\w+/else\z})
|
|
132
143
|
|
|
133
|
-
|
|
144
|
+
words = text.split('/').map { code(_1) }
|
|
145
|
+
words.reduce { |one, other| joined_code(one, '/', other) }
|
|
134
146
|
end
|
|
135
147
|
|
|
136
|
-
#
|
|
137
|
-
#
|
|
138
|
-
|
|
148
|
+
# Example: ? total > 100, its ? coloured as an operator.
|
|
149
|
+
# The code of a ternary's arm's label: its ? or : coloured as
|
|
150
|
+
# an operator, the code after it as code.
|
|
151
|
+
def self.ternary_arm_code(label)
|
|
139
152
|
mark, code = label.split(' ', 2)
|
|
140
|
-
|
|
153
|
+
marked = { text: mark, tokens: [[0, mark.length, 'o']] }
|
|
154
|
+
joined_code(marked, ' ', code(code.to_s))
|
|
141
155
|
end
|
|
142
156
|
|
|
143
|
-
#
|
|
144
|
-
#
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
token = CGI.escapeHTML(text[from...to])
|
|
151
|
-
%(#{plain}<span class="#{css}">#{token}</span>)
|
|
157
|
+
# Example: if, / and else give if/else, its else's ranges moved
|
|
158
|
+
# on by 3.
|
|
159
|
+
# The code of one, then between, uncoloured, then other.
|
|
160
|
+
def self.joined_code(one, between, other)
|
|
161
|
+
shift = one[:text].length + between.length
|
|
162
|
+
moved = other[:tokens].map do |from, to, css|
|
|
163
|
+
[from + shift, to + shift, css]
|
|
152
164
|
end
|
|
153
|
-
|
|
165
|
+
{ text: one[:text] + between + other[:text],
|
|
166
|
+
tokens: one[:tokens] + moved }
|
|
154
167
|
end
|
|
155
168
|
end
|
|
156
169
|
end
|
|
@@ -2,16 +2,12 @@ module PathCoverage
|
|
|
2
2
|
# The operators whose predicate picks an arm.
|
|
3
3
|
CHOICES = %w[?: if unless].freeze
|
|
4
4
|
|
|
5
|
-
# The choices whose arms are statements, so whose path is
|
|
6
|
-
# decided by their predicate alone.
|
|
7
|
-
STATEMENT_CHOICES = %w[if unless].freeze
|
|
8
|
-
|
|
9
5
|
# The operator of a safe-navigation chain, eg user&.account.
|
|
10
6
|
SAFE = '&.'.freeze
|
|
11
7
|
|
|
12
|
-
# The operator of a leaf with
|
|
8
|
+
# The operator of a leaf with decisions inside it, eg
|
|
13
9
|
# ids.select { |i| i.odd? }.any? as an operand of an &&: its
|
|
14
|
-
# operands are those
|
|
10
|
+
# operands are those decisions' Conditions, then the leaf's own byte
|
|
15
11
|
# range, whose outcome is the leaf's value.
|
|
16
12
|
CONTAINS = 'contains'.freeze
|
|
17
13
|
|
|
@@ -25,9 +21,12 @@ module PathCoverage
|
|
|
25
21
|
WRITES = %w[||= &&=].freeze
|
|
26
22
|
|
|
27
23
|
# The predicate outcome on which each choice takes its then
|
|
28
|
-
# arm: an unless's is false, as is a ||= write's
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
# arm: an unless's is false, as is a ||= write's, and an || or
|
|
25
|
+
# or's, whose leaving right side, eg x or return t, runs when
|
|
26
|
+
# the operand before it is false.
|
|
27
|
+
THEN_ON = Hash.new(true).merge(
|
|
28
|
+
'unless' => false, '||=' => false, '||' => false, 'or' => false
|
|
29
|
+
).freeze
|
|
31
30
|
|
|
32
31
|
# The methods that call their block an item at a time until
|
|
33
32
|
# it decides, its last answer deciding the result.
|
|
@@ -70,7 +69,7 @@ module PathCoverage
|
|
|
70
69
|
# all but find and detect, whose found item may itself be nil.
|
|
71
70
|
VALUED = [*STOP_EARLY - %w[find detect], *EVERY_ITEM].freeze
|
|
72
71
|
|
|
73
|
-
# Every block method whose call is a
|
|
72
|
+
# Every block method whose call is a decision, by its paths.
|
|
74
73
|
BLOCK_PATHS = [
|
|
75
74
|
*STOP_EARLY.map { |name| [name, STOP_EARLY_PATHS] },
|
|
76
75
|
*EVERY_ITEM.map { |name| [name, EVERY_ITEM_PATHS] }
|
|
@@ -80,12 +79,13 @@ module PathCoverage
|
|
|
80
79
|
# :else, extent its byte range, nil for an arm with no
|
|
81
80
|
# statements, and body the Condition it is, when it is one,
|
|
82
81
|
# else nil for a plain value or statements, which decide
|
|
83
|
-
# nothing
|
|
84
|
-
|
|
82
|
+
# nothing; leaves is Leaving's word for its code, return or
|
|
83
|
+
# raise, nil for an arm that does not leave the method.
|
|
84
|
+
Arm = Data.define(:kind, :extent, :body, :leaves)
|
|
85
85
|
|
|
86
|
-
# One
|
|
86
|
+
# One decision's condition as the manifest found it: its operator
|
|
87
87
|
# and its operands, each the byte range of a leaf or a nested
|
|
88
|
-
# Condition. A
|
|
88
|
+
# Condition. A decision's commands are the byte ranges of its
|
|
89
89
|
# leaves that are command calls, eg `ok? id`; its fixed are
|
|
90
90
|
# { byte range => :truthy } for leaves that can have that one
|
|
91
91
|
# outcome only, eg `Clock.new`. Its extent is the byte range
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require_relative 'configuration_limits'
|
|
1
2
|
require_relative 'configuration_paths'
|
|
2
3
|
|
|
3
4
|
module PathCoverage
|
|
@@ -6,14 +7,15 @@ module PathCoverage
|
|
|
6
7
|
|
|
7
8
|
# The settings given in a PathCoverage.start block.
|
|
8
9
|
class Configuration
|
|
10
|
+
include ConfigurationLimits
|
|
9
11
|
include ConfigurationPaths
|
|
10
12
|
|
|
11
13
|
GLOB_FLAGS = File::FNM_PATHNAME | File::FNM_EXTGLOB
|
|
12
14
|
SETTINGS = %w[
|
|
13
|
-
collector cover coverage_dir group ignore
|
|
14
|
-
skip treat
|
|
15
|
+
collector cover coverage_dir group ignore loops max_paths
|
|
16
|
+
report root skip treat
|
|
15
17
|
].freeze
|
|
16
|
-
REPORTERS = %w[gaps
|
|
18
|
+
REPORTERS = %w[gaps post summary ways].freeze
|
|
17
19
|
|
|
18
20
|
# Evaluates the settings block against a new configuration.
|
|
19
21
|
def initialize(&)
|
|
@@ -23,6 +25,7 @@ module PathCoverage
|
|
|
23
25
|
@reporters = [:gaps]
|
|
24
26
|
@ignored = []
|
|
25
27
|
@treats = []
|
|
28
|
+
default_limits
|
|
26
29
|
instance_eval(&)
|
|
27
30
|
end
|
|
28
31
|
|
|
@@ -42,7 +45,7 @@ module PathCoverage
|
|
|
42
45
|
@collector_url = url
|
|
43
46
|
end
|
|
44
47
|
|
|
45
|
-
# Sets the dir that cover globs and
|
|
48
|
+
# Sets the dir that cover globs and decision names are
|
|
46
49
|
# relative to.
|
|
47
50
|
def root(dir)
|
|
48
51
|
@root = dir
|