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
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
require 'prism'
|
|
2
|
+
require_relative 'card_tree'
|
|
3
|
+
require_relative 'card_ways'
|
|
4
|
+
require_relative 'decision_paths'
|
|
5
|
+
require_relative 'manifest'
|
|
6
|
+
require_relative 'loop_forks'
|
|
7
|
+
require_relative 'method_statements'
|
|
8
|
+
require_relative 'way_algebras'
|
|
9
|
+
|
|
10
|
+
module PathCoverage
|
|
11
|
+
# The ways one call can take through each method, each listed as
|
|
12
|
+
# its steps, as a call's trace records them: a decision's
|
|
13
|
+
# [name, path], or any other row's [name], eg a return's.
|
|
14
|
+
module MethodWays
|
|
15
|
+
# { def decision => [way, ...] } for each def in source, at
|
|
16
|
+
# path, its decisions those of no settings: the ways some call
|
|
17
|
+
# can take, each loop a fork when loops.
|
|
18
|
+
def self.of(source, path, loops: false)
|
|
19
|
+
split(source, path, loops:).transform_values(&:first)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# { def decision => [possible, impossible] } for each def in
|
|
23
|
+
# source, at path, its decisions those of no settings: the
|
|
24
|
+
# ways some call can take, and those none can, as giving a
|
|
25
|
+
# leaf StableLeaves finds both outcomes; each loop a fork when
|
|
26
|
+
# loops, as LoopForks finds them.
|
|
27
|
+
def self.split(source, path, loops: false)
|
|
28
|
+
decisions = Manifest.decisions(source, path)
|
|
29
|
+
cards = MethodStatements.of(source, path, decisions)
|
|
30
|
+
forks = LoopForks.of(source, path, decisions)
|
|
31
|
+
cards.to_h do |key, rows|
|
|
32
|
+
forked = loops ? forks.fetch(key) : {}
|
|
33
|
+
[key, split_card(source, decisions, rows, forked)]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# [possible, impossible] of the card of rows in source, as
|
|
38
|
+
# split gives them, each loop of forks a fork; a way giving no
|
|
39
|
+
# items to a loop declared never empty is impossible.
|
|
40
|
+
def self.split_card(source, decisions, rows, forks = {})
|
|
41
|
+
possible, all = [true, false].map do |stable|
|
|
42
|
+
listed(source, decisions, rows, [stable, forks])
|
|
43
|
+
end
|
|
44
|
+
lines = never_empty(source)
|
|
45
|
+
by = possible.group_by { empties?(_1, lines) }
|
|
46
|
+
possible = by.fetch(false, [])
|
|
47
|
+
[possible, all - possible]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# The comment on a loop's line declaring it is never given no
|
|
51
|
+
# items.
|
|
52
|
+
NEVER_EMPTY = '# path: impossible 0 items'.freeze
|
|
53
|
+
|
|
54
|
+
# The numbers of the lines of source with a comment holding
|
|
55
|
+
# NEVER_EMPTY.
|
|
56
|
+
def self.never_empty(source)
|
|
57
|
+
Prism.parse(source).comments.filter_map do |comment|
|
|
58
|
+
location = comment.location
|
|
59
|
+
location.start_line if location.slice.include?(NEVER_EMPTY)
|
|
60
|
+
end.to_set
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# True for a way giving no items to a loop on one of lines.
|
|
64
|
+
def self.empties?(way, lines)
|
|
65
|
+
way.any? do |name, path|
|
|
66
|
+
line = Integer(name.split(':')[-2])
|
|
67
|
+
path == [FORKS[0]] && lines.include?(line)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# The steps of a loop's fork, by its path: no pass, or some.
|
|
72
|
+
FORKS = ['0 items', '1+ items'].freeze
|
|
73
|
+
|
|
74
|
+
# The ways through the card of rows, as steps, those no call
|
|
75
|
+
# can take too unless stable, each loop of forks a fork.
|
|
76
|
+
def self.listed(source, decisions, rows, (stable, forks))
|
|
77
|
+
ways = CardWays.card(source, decisions, rows,
|
|
78
|
+
WayAlgebras::Listed, [stable, forks])
|
|
79
|
+
steps = rows.to_h { [CardTree.key_of(_1), _1] }
|
|
80
|
+
loops = forks.keys.to_h { [CardTree.key_at(_1), _1] }
|
|
81
|
+
ways.map do |way|
|
|
82
|
+
way.map do |key, index|
|
|
83
|
+
next [loops[key], [FORKS[index]]] if loops.key?(key)
|
|
84
|
+
|
|
85
|
+
step(steps, decisions, key, index)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# The ways, as of lists them, that way, a call's, as its trace
|
|
91
|
+
# records it, witnesses: each pass of a loop inlined, one way
|
|
92
|
+
# for each distinct way its passes took, a loop with no pass
|
|
93
|
+
# adding nothing; each way's steps in the order their rows are
|
|
94
|
+
# written, as ordered gives them. A loop of forked, the names
|
|
95
|
+
# of loops that fork, that made a pass steps 1+ items first.
|
|
96
|
+
def self.witnessed(way, forked = [])
|
|
97
|
+
found = way.reduce([[]]) do |ways, step|
|
|
98
|
+
next ways.map { _1 + [step] } if step.size < 3
|
|
99
|
+
|
|
100
|
+
ways.product(passes(step, forked)).map { _1.sum([]) }
|
|
101
|
+
end
|
|
102
|
+
found.to_set { ordered(_1) }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# The ways a loop's step, [name, items, pass ways], inlines:
|
|
106
|
+
# each way its passes witness, after a step of 1+ items when
|
|
107
|
+
# the loop is among forked; or the one way of no steps when it
|
|
108
|
+
# made no pass.
|
|
109
|
+
def self.passes(step, forked)
|
|
110
|
+
taken = step[2].flat_map { witnessed(_1, forked).to_a }
|
|
111
|
+
return [[]] if taken.empty?
|
|
112
|
+
return taken unless forked.include?(step[0])
|
|
113
|
+
|
|
114
|
+
taken.map { [[step[0], [FORKS[1]]], *_1] }
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# way, a static way, as the way witnessed gives a call that
|
|
118
|
+
# took it: with no step of 0 items, as a loop that made no
|
|
119
|
+
# pass is no step of a call's trace, its steps ordered.
|
|
120
|
+
def self.matched(way)
|
|
121
|
+
by = way.group_by { _1[1] == [FORKS[0]] }
|
|
122
|
+
ordered(by.fetch(false, []))
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# way's steps in the order their rows are written, by line
|
|
126
|
+
# then column, so a way is compared by its steps alone.
|
|
127
|
+
def self.ordered(way)
|
|
128
|
+
way.sort_by { |step| step[0].split(':').last(2).map(&:to_i) }
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# The step of the path at index of the row keyed key, among
|
|
132
|
+
# rows, { key => row }: a decision's [name, path], decisions
|
|
133
|
+
# being { decision => Condition }; any other's [name].
|
|
134
|
+
def self.step(rows, decisions, key, index)
|
|
135
|
+
row = rows[key]
|
|
136
|
+
return [row.name] if row.decision.nil?
|
|
137
|
+
|
|
138
|
+
possible = DecisionPaths.possible(decisions[row.decision])
|
|
139
|
+
[row.decision, possible[index]]
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
module PathCoverage
|
|
2
|
-
# What the reports say about each
|
|
2
|
+
# What the reports say about each decision's paths beyond their
|
|
3
3
|
# counts, worked out from each covered file's source: where
|
|
4
4
|
# each leaf is, and what it says.
|
|
5
5
|
module PathsReport
|
|
6
|
-
# {
|
|
6
|
+
# { decision => { leaves:, taken: } }: taken is each path and
|
|
7
7
|
# its count, as Result#paths gives them, and leaves each
|
|
8
8
|
# leaf's ["line:column", "line:column"] span, so a tool can
|
|
9
9
|
# recover each leaf exactly. files is { full path =>
|
|
10
|
-
# {source:,
|
|
11
|
-
def self.of(
|
|
10
|
+
# {source:, decisions:} }.
|
|
11
|
+
def self.of(decision_paths, files)
|
|
12
12
|
spans = leaf_spans(files)
|
|
13
|
-
|
|
14
|
-
[
|
|
13
|
+
decision_paths.to_h do |decision, taken|
|
|
14
|
+
[decision, { leaves: spans.fetch(decision), taken: }]
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
# {
|
|
18
|
+
# { decision => [each leaf's source text] } for every decision in
|
|
19
19
|
# files.
|
|
20
20
|
def self.texts(files)
|
|
21
|
-
|
|
21
|
+
each_decision(files) do |source, condition|
|
|
22
22
|
condition.leaves.map { |range| source.byteslice(range) }
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
# {
|
|
26
|
+
# { decision => [each leaf's span] } for every decision in files.
|
|
27
27
|
def self.leaf_spans(files)
|
|
28
|
-
|
|
28
|
+
each_decision(files) do |source, condition|
|
|
29
29
|
condition.leaves.map do |range|
|
|
30
30
|
[at(source, range.begin), at(source, range.end)]
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
# {
|
|
36
|
-
# its condition } for every
|
|
37
|
-
def self.
|
|
35
|
+
# { decision => what the block makes of its file's source and
|
|
36
|
+
# its condition } for every decision in files.
|
|
37
|
+
def self.each_decision(files)
|
|
38
38
|
files.values.each_with_object({}) do |parsed, all|
|
|
39
|
-
parsed[:
|
|
40
|
-
all[
|
|
39
|
+
parsed[:decisions].each do |decision, condition|
|
|
40
|
+
all[decision] = yield(parsed[:source], condition)
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
# "line:column" of a byte offset in source, the line from
|
|
46
|
-
# 1 and the column, in characters, from 0, as
|
|
46
|
+
# 1 and the column, in characters, from 0, as decision names
|
|
47
47
|
# count them.
|
|
48
48
|
def self.at(source, offset)
|
|
49
49
|
before = source.byteslice(0, offset)
|
|
@@ -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
|
|
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(:
|
|
18
|
+
Trail = Struct.new(:decision, :outcomes)
|
|
18
19
|
|
|
19
|
-
# Starts with no outcomes,
|
|
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
|
-
@
|
|
25
|
-
|
|
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
|
-
#
|
|
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
|
|
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(
|
|
58
|
+
def trails(decision)
|
|
45
59
|
stacks = Thread.current[@trails_key] ||=
|
|
46
60
|
Hash.new { |all, key| all[key] = [] }
|
|
47
|
-
stacks[
|
|
61
|
+
stacks[decision]
|
|
48
62
|
end
|
|
49
63
|
|
|
50
|
-
# {
|
|
51
|
-
# evaluation of a
|
|
52
|
-
attr_reader :
|
|
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
|
|
68
|
+
# Starts an evaluation of decision, which has size leaves, as
|
|
55
69
|
# the trail its leaves' records fill in.
|
|
56
|
-
def enter(
|
|
57
|
-
trail = Trail.new(
|
|
58
|
-
trails(
|
|
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
|
|
64
|
-
#
|
|
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.
|
|
83
|
+
stack = trails(trail.decision)
|
|
70
84
|
clean = stack.last.equal?(trail)
|
|
71
85
|
nil until stack.empty? || stack.pop.equal?(trail)
|
|
72
|
-
|
|
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 [
|
|
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(
|
|
104
|
+
def record(decision, index, value)
|
|
84
105
|
outcome = value ? :truthy : :falsy
|
|
85
|
-
@counts[[
|
|
86
|
-
trail = trails(
|
|
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, :
|
|
117
|
+
:recorder, :decision, :index, :total, :pattern
|
|
97
118
|
) do
|
|
98
119
|
# Whether pattern matches subject, exactly as pattern says,
|
|
99
|
-
# noted on the
|
|
120
|
+
# noted on the decision's path.
|
|
100
121
|
def ===(subject)
|
|
101
|
-
recorder.matched(
|
|
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
|
|
107
|
-
def when_match(
|
|
108
|
-
WhenMatch.new(self,
|
|
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
|
|
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(
|
|
116
|
-
enter(
|
|
117
|
-
record(
|
|
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(
|
|
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
|
|
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
|
|
11
|
-
#
|
|
12
|
-
# returns the
|
|
13
|
-
def begin_items(
|
|
14
|
-
trail = trails(
|
|
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
|
-
#
|
|
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(
|
|
25
|
-
trail = trails(
|
|
24
|
+
def item_at(decision, at, value)
|
|
25
|
+
trail = trails(decision).last
|
|
26
26
|
one_more(trail, at) if trail
|
|
27
|
-
record(
|
|
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
|
|
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(
|
|
36
|
-
trail = trails(
|
|
35
|
+
def answer_at(decision, at, value)
|
|
36
|
+
trail = trails(decision).last
|
|
37
37
|
note_answer(trail, at, value) if trail
|
|
38
|
-
@counts[[
|
|
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
|
|
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(
|
|
62
|
+
def end_items(decision, at, trail, value)
|
|
63
63
|
called = trail.nil? || trail.outcomes[at] != ITEMS[0]
|
|
64
|
-
@counts[[
|
|
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
|
-
#
|
|
4
|
-
# enters and leaves, so its patterns only note
|
|
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
|
|
8
|
-
# match noted as the
|
|
9
|
-
NestedMatch = Struct.new(:recorder, :
|
|
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
|
|
12
|
+
# noted on the decision's path.
|
|
12
13
|
def ===(subject)
|
|
13
|
-
recorder.record(
|
|
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
|
|
18
|
+
# The stand-in for pattern, the index-th leaf of decision, in a
|
|
18
19
|
# case nested in it.
|
|
19
|
-
def pattern(
|
|
20
|
-
NestedMatch.new(self,
|
|
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
|
|
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(
|
|
13
|
-
return value unless reached?(
|
|
12
|
+
def present(decision, index, first, value)
|
|
13
|
+
return value unless reached?(decision, first, index)
|
|
14
14
|
|
|
15
|
-
@counts[[
|
|
16
|
-
trail = trails(
|
|
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
|
-
#
|
|
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(
|
|
26
|
-
return value unless reached?(
|
|
25
|
+
def chained(decision, index, first, value)
|
|
26
|
+
return value unless reached?(decision, first, index)
|
|
27
27
|
|
|
28
|
-
record(
|
|
28
|
+
record(decision, index, value)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
# True when
|
|
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?(
|
|
36
|
-
trail = trails(
|
|
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
|
|
4
|
-
# for a write that is a
|
|
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,
|
|
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(
|
|
12
|
-
record(
|
|
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,
|
|
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(
|
|
20
|
-
trail = trails(
|
|
19
|
+
def settle(decision, at, skipped, value)
|
|
20
|
+
trail = trails(decision).last
|
|
21
21
|
unnoted = trail.nil? || trail.outcomes[at].nil?
|
|
22
|
-
record(
|
|
22
|
+
record(decision, at, skipped) if unnoted
|
|
23
23
|
value
|
|
24
24
|
end
|
|
25
25
|
end
|