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.
- checksums.yaml +4 -4
- data/README.md +286 -199
- 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 +79 -66
- data/lib/path_coverage/card_way_lists.rb +72 -0
- data/lib/path_coverage/card_ways.rb +123 -67
- data/lib/path_coverage/{html_syntax.rb → code_tokens.rb} +35 -33
- 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} +13 -11
- 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/{html_tree.rb → fold_rows.rb} +42 -71
- 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 +27 -12
- data/lib/path_coverage/kernel.rb +56 -58
- 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 -12
- data/lib/path_coverage/kinds/chain.rb +40 -11
- data/lib/path_coverage/kinds/choice.rb +4 -3
- data/lib/path_coverage/kinds/contains.rb +40 -32
- data/lib/path_coverage/kinds/safe.rb +38 -26
- data/lib/path_coverage/kinds/write.rb +6 -6
- 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 +92 -58
- 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 +23 -20
- data/lib/path_coverage/manifest_disabled.rb +97 -0
- data/lib/path_coverage/manifest_folding.rb +43 -40
- 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 +130 -127
- 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 +31 -30
- 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 +135 -80
- metadata +33 -28
- 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 -599
- data/lib/path_coverage/html/sort.js +0 -34
- data/lib/path_coverage/html/style.css +0 -484
- 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 -88
- data/lib/path_coverage/html_cells.rb +0 -71
- 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 -16
- 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 -186
- data/lib/path_coverage/html_tabs.rb +0 -26
- data/lib/path_coverage/html_template.rb +0 -26
|
@@ -1,98 +1,110 @@
|
|
|
1
|
+
require_relative 'card_forks'
|
|
1
2
|
require_relative 'manifest'
|
|
2
3
|
require_relative 'method_statements'
|
|
3
|
-
require_relative '
|
|
4
|
-
require_relative '
|
|
4
|
+
require_relative 'decision_paths'
|
|
5
|
+
require_relative 'decision_tree'
|
|
5
6
|
|
|
6
7
|
module PathCoverage
|
|
7
|
-
# How the rows of each card nest: for each row, the
|
|
8
|
-
# runs inside, the arm of that
|
|
9
|
-
# that
|
|
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
|
|
10
11
|
# reach a row, and count the paths through a card as a whole.
|
|
11
12
|
module CardTree
|
|
12
|
-
# Part of a
|
|
13
|
-
# statements, or a leaf; owner the key of the
|
|
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,
|
|
14
15
|
# range its bytes, arm its arm's name, nil for a leaf, on
|
|
15
|
-
# the indices of the
|
|
16
|
-
# leaf a leaf's index among the
|
|
17
|
-
|
|
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)
|
|
18
21
|
|
|
19
|
-
# The place of a row inside no other row's
|
|
20
|
-
TOP = {
|
|
21
|
-
|
|
22
|
-
'leaf' => nil, 'gives' => nil
|
|
23
|
-
}.freeze
|
|
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
|
|
24
25
|
|
|
25
26
|
# Example: def f(a); if a then 1 end; end gives the value
|
|
26
27
|
# row 1 its parent, the if, in its then arm, on its path 0.
|
|
27
|
-
# { def
|
|
28
|
+
# { def decision => { "line:column" => { 'parent' =>, 'in' =>,
|
|
28
29
|
# 'on' =>, 'leaf' =>, 'gives' => } } } for each def in
|
|
29
30
|
# source, a row keyed by where it is named. parent is the
|
|
30
|
-
# "line:column" of the
|
|
31
|
-
# of its arm, on the indices of that
|
|
32
|
-
# as
|
|
33
|
-
# the index of that
|
|
34
|
-
# row whose
|
|
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
|
|
35
36
|
# outcome on each of the row's own possible paths, nil where
|
|
36
37
|
# not known; each nil where it does not apply.
|
|
37
|
-
def self.of(source, path,
|
|
38
|
-
|
|
39
|
-
cards = MethodStatements.of(source, path,
|
|
40
|
-
cards.transform_values {
|
|
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) }
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
# { "line:column" => its place } for each of rows, a card's,
|
|
44
|
-
# each placed in the innermost region of another row's
|
|
45
|
-
# holding all of its own
|
|
46
|
-
# no
|
|
47
|
-
# does, eg an || whose first operand
|
|
48
|
-
# child, and is not held by it.
|
|
49
|
-
|
|
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))
|
|
50
62
|
starts = line_starts(source)
|
|
51
|
-
regions = card_regions(source, sites, rows)
|
|
52
63
|
rows.to_h do |row|
|
|
53
64
|
at = starts[row.line - 1] + row.column
|
|
54
|
-
|
|
55
|
-
span =
|
|
65
|
+
decision = row.decision ? decisions.fetch(row.decision) : nil
|
|
66
|
+
span = decision ? decision.extent : at...(at + 1)
|
|
56
67
|
key = key_of(row)
|
|
57
|
-
[key, placed(key, span, regions,
|
|
68
|
+
[key, placed(key, span, regions, decision)]
|
|
58
69
|
end
|
|
59
70
|
end
|
|
60
71
|
|
|
61
|
-
# The regions of the
|
|
62
|
-
# {
|
|
63
|
-
def self.card_regions(source,
|
|
64
|
-
rows.select(&:
|
|
65
|
-
regions_of(source, key_of(row),
|
|
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))
|
|
66
77
|
end
|
|
67
78
|
end
|
|
68
79
|
|
|
69
80
|
# The place of the row keyed key, its code the bytes span,
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
# span, as place gives it; TOP for a row in no such
|
|
73
|
-
|
|
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)
|
|
74
86
|
holding = holding(key, span, regions)
|
|
75
87
|
inner = smallest(holding)
|
|
76
88
|
return TOP if inner.nil?
|
|
77
89
|
|
|
78
90
|
owner = inner.owner
|
|
79
91
|
own = holding.group_by(&:owner).fetch(owner)
|
|
80
|
-
place(owner, own).merge(leaf_place(own,
|
|
92
|
+
place(owner, own).merge(leaf_place(own, decision))
|
|
81
93
|
end
|
|
82
94
|
|
|
83
95
|
# The leaf and gives of a row's place, own being the regions
|
|
84
|
-
# of its parent holding it,
|
|
85
|
-
# the innermost leaf holding it; and, when
|
|
86
|
-
# of that leaf,
|
|
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,
|
|
87
99
|
# as its kind gives them, the leaf's outcome there. Neither
|
|
88
|
-
# for a row that is no
|
|
100
|
+
# for a row that is no decision, a return or a raise, which gives
|
|
89
101
|
# its parent nothing.
|
|
90
|
-
def self.leaf_place(own,
|
|
91
|
-
return { 'leaf' => nil, 'gives' => nil } if
|
|
102
|
+
def self.leaf_place(own, decision)
|
|
103
|
+
return { 'leaf' => nil, 'gives' => nil } if decision.nil?
|
|
92
104
|
|
|
93
105
|
leaf = smallest(own.reject(&:arm))
|
|
94
|
-
whole = leaf &&
|
|
95
|
-
gives = whole ?
|
|
106
|
+
whole = leaf && decision.extent == leaf.range
|
|
107
|
+
gives = whole ? DecisionPaths.values(decision) : nil
|
|
96
108
|
{ 'leaf' => leaf&.leaf, 'gives' => gives }
|
|
97
109
|
end
|
|
98
110
|
|
|
@@ -105,8 +117,8 @@ module PathCoverage
|
|
|
105
117
|
held.fetch(true, [])
|
|
106
118
|
end
|
|
107
119
|
|
|
108
|
-
# A row's place in the
|
|
109
|
-
# the regions of that
|
|
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
|
|
110
122
|
# of them, nil for none, and the paths on which every one of
|
|
111
123
|
# them runs, as the row runs only where all of them do.
|
|
112
124
|
def self.place(owner, own)
|
|
@@ -116,15 +128,14 @@ module PathCoverage
|
|
|
116
128
|
end
|
|
117
129
|
|
|
118
130
|
# The region of regions with the fewest bytes; nil for none.
|
|
119
|
-
def self.smallest(regions)
|
|
120
|
-
regions.min_by { |region| region.range.size }
|
|
121
|
-
end
|
|
131
|
+
def self.smallest(regions) = regions.min_by { _1.range.size }
|
|
122
132
|
|
|
123
|
-
# The regions of condition, the
|
|
133
|
+
# The regions of condition, the decision of the row keyed owner:
|
|
124
134
|
# its arms', and its leaves'.
|
|
125
135
|
def self.regions_of(source, owner, condition)
|
|
126
|
-
possible =
|
|
127
|
-
node =
|
|
136
|
+
possible = DecisionPaths.possible(condition)
|
|
137
|
+
node = DecisionTree.node(source, condition, possible,
|
|
138
|
+
(0..).each)
|
|
128
139
|
arm_regions(owner, condition, node) +
|
|
129
140
|
leaf_regions(owner, condition, possible)
|
|
130
141
|
end
|
|
@@ -137,7 +148,8 @@ module PathCoverage
|
|
|
137
148
|
possible[i][index].nil?
|
|
138
149
|
end
|
|
139
150
|
on = skipped.fetch(false)
|
|
140
|
-
Region.new(owner:, range:, arm: nil, on:, leaf: index
|
|
151
|
+
Region.new(owner:, range:, arm: nil, on:, leaf: index,
|
|
152
|
+
leaves: nil)
|
|
141
153
|
end
|
|
142
154
|
end
|
|
143
155
|
|
|
@@ -166,14 +178,15 @@ module PathCoverage
|
|
|
166
178
|
cells = node[:cells]
|
|
167
179
|
on = cells.each_index.group_by { cells[_1] }.fetch(true, [])
|
|
168
180
|
own = Region.new(owner:, range: arm.extent, arm: arm.kind.to_s,
|
|
169
|
-
on:, leaf: nil)
|
|
181
|
+
on:, leaf: nil, leaves: arm.leaves)
|
|
170
182
|
[own, *body]
|
|
171
183
|
end
|
|
172
184
|
|
|
173
185
|
# The "line:column" key of row, from its name.
|
|
174
|
-
def self.key_of(row)
|
|
175
|
-
|
|
176
|
-
|
|
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(':')
|
|
177
190
|
|
|
178
191
|
# The byte offset where each line of source starts, first
|
|
179
192
|
# line first.
|
|
@@ -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
|
|
@@ -1,91 +1,152 @@
|
|
|
1
1
|
require_relative 'card_tree'
|
|
2
2
|
require_relative 'manifest'
|
|
3
3
|
require_relative 'method_statements'
|
|
4
|
-
require_relative '
|
|
4
|
+
require_relative 'decision_paths'
|
|
5
|
+
require_relative 'stable_leaves'
|
|
6
|
+
require_relative 'way_algebras'
|
|
5
7
|
|
|
6
8
|
module PathCoverage
|
|
7
|
-
# The
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
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
|
|
11
13
|
# arm that returns or raises, eg return 0 if a. Rows one after
|
|
12
14
|
# another multiply, but only the ways that go on reach the next
|
|
13
|
-
# row; a
|
|
14
|
-
# that path one after another; and a row that is the whole of
|
|
15
|
-
# leaf counts only those of its paths that give the leaf the
|
|
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
|
|
16
18
|
# outcome the path has, so no impossible way is counted where
|
|
17
|
-
# gives knows it. A block's body counts once
|
|
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.
|
|
18
28
|
class CardWays
|
|
29
|
+
include CardForks
|
|
30
|
+
|
|
19
31
|
# Example: { "k.rb:1:0" => 3 } for def f(a, b), return 0 if a,
|
|
20
32
|
# then a ?: of b: 1 way leaves, 2 go on.
|
|
21
|
-
# { def
|
|
22
|
-
# those of no settings.
|
|
23
|
-
def self.of(source, path)
|
|
24
|
-
|
|
25
|
-
cards = MethodStatements.of(source, path,
|
|
26
|
-
cards.transform_values
|
|
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
|
|
27
41
|
end
|
|
28
42
|
|
|
29
|
-
# The ways through a card of rows in source,
|
|
30
|
-
# {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
43
57
|
end
|
|
44
58
|
|
|
45
59
|
# The fold of rows, a card's in source, placed as places has
|
|
46
|
-
# them, each
|
|
47
|
-
|
|
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))
|
|
48
65
|
@source = source
|
|
49
66
|
@rows = rows.to_h { |row| [CardTree.key_of(row), row] }
|
|
50
67
|
@places = places
|
|
51
|
-
@
|
|
68
|
+
@decisions = decisions
|
|
69
|
+
@ways = WayAlgebras::Tallied.new(algebra)
|
|
52
70
|
@children = places.keys.group_by { places[_1]['parent'] }
|
|
71
|
+
@names = names
|
|
53
72
|
end
|
|
54
73
|
|
|
55
|
-
# The ways through the card: its top rows'
|
|
56
|
-
# another, those that go on and those that
|
|
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.
|
|
57
77
|
def total
|
|
58
78
|
tops = @children.fetch(nil, []).map { |key| pair_of(key) }
|
|
59
|
-
|
|
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
|
|
60
91
|
end
|
|
61
92
|
|
|
62
|
-
# The pair of the row keyed key: a
|
|
93
|
+
# The pair of the row keyed key: a decision's adds up its paths'
|
|
63
94
|
# pairs; any other row is a return or a raise, as no other is
|
|
64
|
-
# a row, so leaves.
|
|
95
|
+
# a row, so leaves, at its one path.
|
|
65
96
|
def pair_of(key)
|
|
97
|
+
return fork_pair(key) unless @rows.key?(key)
|
|
98
|
+
|
|
66
99
|
row = @rows[key]
|
|
67
|
-
|
|
100
|
+
leaves = [@ways.zero, @ways.unit([key, 0])]
|
|
101
|
+
return leaves if row.decision.nil?
|
|
68
102
|
|
|
69
|
-
pairs = possible(row.
|
|
103
|
+
pairs = possible(row.decision).each_index.map do |path|
|
|
70
104
|
pair_on(key, path)
|
|
71
105
|
end
|
|
72
106
|
added(pairs)
|
|
73
107
|
end
|
|
74
108
|
|
|
75
|
-
# The pair of the
|
|
76
|
-
# path: the rows it runs on that path,
|
|
77
|
-
# given that path's outcomes; every
|
|
78
|
-
# path takes an arm that leaves.
|
|
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.
|
|
79
113
|
def pair_on(key, path)
|
|
80
|
-
outcomes = possible(@rows[key].
|
|
114
|
+
outcomes = possible(@rows[key].decision)[path]
|
|
81
115
|
pairs = running(key, path).map do |child|
|
|
82
116
|
child_pair(child, outcomes)
|
|
83
117
|
end
|
|
84
|
-
|
|
85
|
-
|
|
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)]
|
|
86
123
|
end
|
|
87
124
|
|
|
88
|
-
# The
|
|
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
|
|
89
150
|
# at index path, in the order they are written.
|
|
90
151
|
def running(key, path)
|
|
91
152
|
runs = @children.fetch(key, []).group_by do |child|
|
|
@@ -103,38 +164,33 @@ module PathCoverage
|
|
|
103
164
|
gives = place['gives']
|
|
104
165
|
return pair_of(child) if gives.nil?
|
|
105
166
|
|
|
106
|
-
fits = [nil,
|
|
167
|
+
fits = [nil, outcomes[place['leaf']]]
|
|
168
|
+
none = [@ways.zero, @ways.zero]
|
|
107
169
|
pairs = gives.each_index.map do |path|
|
|
108
|
-
fits.include?(gives[path]) ? pair_on(child, path) :
|
|
170
|
+
fits.include?(gives[path]) ? pair_on(child, path) : none
|
|
109
171
|
end
|
|
110
172
|
added(pairs)
|
|
111
173
|
end
|
|
112
174
|
|
|
113
|
-
# The
|
|
114
|
-
# names.
|
|
115
|
-
def outcome_of(outcomes, place)
|
|
116
|
-
outcomes[place['leaf']]
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
# The indices of the paths of the site row keyed key that take
|
|
175
|
+
# The indices of the paths of the decision row keyed key that take
|
|
120
176
|
# an arm whose code returns or raises.
|
|
121
177
|
def leaving(key)
|
|
122
|
-
|
|
123
|
-
regions = CardTree.regions_of(@source, key,
|
|
124
|
-
|
|
125
|
-
region.arm && @source.byteslice(region.range).match?(LEAVES)
|
|
126
|
-
end
|
|
127
|
-
left.fetch(true, []).flat_map(&:on)
|
|
178
|
+
decision = @decisions.fetch(@rows[key].decision)
|
|
179
|
+
regions = CardTree.regions_of(@source, key, decision)
|
|
180
|
+
regions.select(&:leaves).flat_map(&:on)
|
|
128
181
|
end
|
|
129
182
|
|
|
130
|
-
# pairs added up, each part on its own.
|
|
183
|
+
# pairs added up, each part on its own; no ways for no pairs.
|
|
131
184
|
def added(pairs)
|
|
132
|
-
|
|
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
|
|
133
189
|
end
|
|
134
190
|
|
|
135
|
-
# The possible paths of the
|
|
136
|
-
def possible(
|
|
137
|
-
|
|
191
|
+
# The possible paths of the decision named decision.
|
|
192
|
+
def possible(decision)
|
|
193
|
+
DecisionPaths.possible(@decisions.fetch(decision))
|
|
138
194
|
end
|
|
139
195
|
end
|
|
140
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,52 +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
132
|
|
|
133
|
-
|
|
133
|
+
{ text:, tokens: of(text).fetch(1, []) }
|
|
134
134
|
end
|
|
135
135
|
|
|
136
|
-
# Example: if/else
|
|
137
|
-
#
|
|
138
|
-
#
|
|
139
|
-
#
|
|
140
|
-
#
|
|
141
|
-
def self.
|
|
142
|
-
return
|
|
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})
|
|
143
143
|
|
|
144
|
-
text.split('/').map {
|
|
144
|
+
words = text.split('/').map { code(_1) }
|
|
145
|
+
words.reduce { |one, other| joined_code(one, '/', other) }
|
|
145
146
|
end
|
|
146
147
|
|
|
147
|
-
#
|
|
148
|
-
#
|
|
149
|
-
|
|
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)
|
|
150
152
|
mark, code = label.split(' ', 2)
|
|
151
|
-
|
|
153
|
+
marked = { text: mark, tokens: [[0, mark.length, 'o']] }
|
|
154
|
+
joined_code(marked, ' ', code(code.to_s))
|
|
152
155
|
end
|
|
153
156
|
|
|
154
|
-
#
|
|
155
|
-
#
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
token = CGI.escapeHTML(text[from...to])
|
|
162
|
-
%(#{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]
|
|
163
164
|
end
|
|
164
|
-
|
|
165
|
+
{ text: one[:text] + between + other[:text],
|
|
166
|
+
tokens: one[:tokens] + moved }
|
|
165
167
|
end
|
|
166
168
|
end
|
|
167
169
|
end
|