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
|
@@ -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
|
data/lib/path_coverage/render.rb
CHANGED
|
@@ -1,88 +1,95 @@
|
|
|
1
|
+
require_relative 'card_context'
|
|
1
2
|
require_relative 'console_summary'
|
|
2
3
|
require_relative 'gaps'
|
|
3
|
-
require_relative 'html_report'
|
|
4
4
|
require_relative 'json_reader'
|
|
5
|
+
require_relative 'json_reports'
|
|
5
6
|
require_relative 'manifest'
|
|
6
7
|
require_relative 'paths_report'
|
|
7
8
|
require_relative 'post'
|
|
8
|
-
require_relative '
|
|
9
|
+
require_relative 'decision_paths'
|
|
9
10
|
require_relative 'within_methods'
|
|
10
11
|
|
|
11
12
|
module PathCoverage
|
|
12
|
-
# The reporters, run from operands alone:
|
|
13
|
-
# run recorded beyond them, they can run in
|
|
13
|
+
# The JSON reports and the reporters, run from operands alone:
|
|
14
|
+
# needing nothing the run recorded beyond them, they can run in
|
|
15
|
+
# another process.
|
|
14
16
|
module Render
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
# reached: as Recorder#reached
|
|
18
|
-
# { full path => {source:,
|
|
17
|
+
# Writes the JSON reports, then runs each reporter chosen in
|
|
18
|
+
# config. operands, and taken's decision_paths: and outside:, are
|
|
19
|
+
# as Result gives them, and its reached: as Recorder#reached
|
|
20
|
+
# gives it; files is { full path => {source:, decisions:} } for
|
|
21
|
+
# each covered file.
|
|
19
22
|
def self.run(operands, files, config, **taken)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
recorded = taken.merge(
|
|
24
|
+
decision_paths: every_decision(
|
|
25
|
+
taken.fetch(:decision_paths, {}), files
|
|
26
|
+
),
|
|
27
|
+
outside: taken.fetch(:outside, {})
|
|
28
|
+
)
|
|
29
|
+
JsonReports.write(operands, files, config, **recorded)
|
|
30
|
+
reporters(operands, files, config, recorded)
|
|
31
|
+
end
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
# Runs each reporter chosen in config, from operands, files,
|
|
34
|
+
# and recorded, as run has them.
|
|
35
|
+
def self.reporters(operands, files, config, recorded)
|
|
36
|
+
paths, reached = recorded.values_at(:decision_paths, :reached)
|
|
37
|
+
runs = {
|
|
38
|
+
gaps: -> { gaps(operands, files, config, recorded) },
|
|
39
|
+
summary: -> { summary(files, config, paths, reached) },
|
|
40
|
+
ways: -> { print File.read(JsonReports.ways_path(config)) },
|
|
41
|
+
post: -> { post(operands, files, config, paths) }
|
|
42
|
+
}
|
|
43
|
+
runs.slice(*config.reporters).each_value(&:call)
|
|
30
44
|
end
|
|
31
45
|
|
|
32
46
|
# Runs the :post reporter: operands, and the paths report of
|
|
33
|
-
#
|
|
34
|
-
def self.post(operands, files, config,
|
|
35
|
-
report = PathsReport.of(
|
|
47
|
+
# decision_paths in files, with config's fingerprint.
|
|
48
|
+
def self.post(operands, files, config, decision_paths)
|
|
49
|
+
report = PathsReport.of(decision_paths, files)
|
|
36
50
|
url = config.collector_url
|
|
37
51
|
fingerprint = config.fingerprint
|
|
38
52
|
Post.deliver(operands, url, report, fingerprint:)
|
|
39
53
|
end
|
|
40
54
|
|
|
41
|
-
# Runs the :html and :summary reporters, each when chosen.
|
|
42
|
-
def self.html_and_summary(operands, files, config, recorded)
|
|
43
|
-
site_paths, reached = recorded
|
|
44
|
-
reporters = config.reporters
|
|
45
|
-
if reporters.include?(:html)
|
|
46
|
-
HtmlReport.write(operands, files, config, recorded)
|
|
47
|
-
end
|
|
48
|
-
return unless reporters.include?(:summary)
|
|
49
|
-
|
|
50
|
-
cards = WithinMethods.cards(files, config, site_paths, reached)
|
|
51
|
-
summary(config, site_paths, cards)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
55
|
# Prints the summary lines: the paths taken of all possible
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
puts ConsoleSummary.lines(
|
|
56
|
+
# alone, and combined, each def's card of files as decision_paths
|
|
57
|
+
# and reached have it; then any operators ignored.
|
|
58
|
+
def self.summary(files, config, decision_paths, reached)
|
|
59
|
+
cards = WithinMethods.cards(files, config, decision_paths,
|
|
60
|
+
reached)
|
|
61
|
+
puts ConsoleSummary.lines(decision_paths, cards,
|
|
62
|
+
config.groups) +
|
|
61
63
|
ConsoleSummary.ignored_lines(config.ignored)
|
|
62
64
|
end
|
|
63
65
|
|
|
64
|
-
#
|
|
66
|
+
# decision_paths with every decision in files that it lacks, eg
|
|
65
67
|
# from a JSON report with no paths, given each possible
|
|
66
68
|
# path at a count of zero: unable to say which paths such
|
|
67
|
-
# a
|
|
68
|
-
def self.
|
|
69
|
+
# a decision took, the report claims none.
|
|
70
|
+
def self.every_decision(decision_paths, files)
|
|
69
71
|
none = files.values.each_with_object({}) do |parsed, all|
|
|
70
|
-
parsed[:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
end
|
|
72
|
+
parsed[:decisions].each do |decision, condition|
|
|
73
|
+
possible = DecisionPaths.possible(condition)
|
|
74
|
+
all[decision] = possible.map { |path| { path:, count: 0 } }
|
|
74
75
|
end
|
|
75
76
|
end
|
|
76
|
-
none.merge(
|
|
77
|
+
none.merge(decision_paths)
|
|
77
78
|
end
|
|
78
79
|
|
|
79
|
-
# Prints the gap lines: each path a
|
|
80
|
+
# Prints the gap lines: each path a decision never took, and each
|
|
80
81
|
# path taken that a treatment rules out, as outside lists
|
|
81
|
-
# them, each leaf named by its text in files
|
|
82
|
-
|
|
82
|
+
# them, each leaf named by its text in files; then each path
|
|
83
|
+
# taken, or return or raise reached, that its method rules
|
|
84
|
+
# out, as CardContext.ruled_out finds them in files under
|
|
85
|
+
# config. recorded is as run has it.
|
|
86
|
+
def self.gaps(operands, files, config, recorded)
|
|
83
87
|
texts = PathsReport.texts(files)
|
|
84
|
-
paths =
|
|
88
|
+
paths, outside, reached =
|
|
89
|
+
recorded.values_at(:decision_paths, :outside, :reached)
|
|
85
90
|
lines = Gaps.lines(operands, paths:, texts:, outside:)
|
|
91
|
+
ruled = CardContext.ruled_out(files, config, paths, reached)
|
|
92
|
+
lines += Gaps.ruled_by_method(ruled, texts)
|
|
86
93
|
lines.each { |line| puts line }
|
|
87
94
|
end
|
|
88
95
|
|
data/lib/path_coverage/result.rb
CHANGED
|
@@ -1,78 +1,79 @@
|
|
|
1
|
-
require_relative '
|
|
1
|
+
require_relative 'decision_paths'
|
|
2
2
|
|
|
3
3
|
module PathCoverage
|
|
4
|
-
# What a run found: every
|
|
4
|
+
# What a run found: every decision the manifest knows of, with
|
|
5
5
|
# the counts its operands were recorded with. Every
|
|
6
6
|
# reporter builds on this.
|
|
7
7
|
class Result
|
|
8
8
|
NEVER_RAN = { truthy: 0, falsy: 0 }.freeze
|
|
9
9
|
|
|
10
|
-
#
|
|
11
|
-
# counts is { [
|
|
12
|
-
# {
|
|
10
|
+
# decisions is { decision => Condition }, from the manifest;
|
|
11
|
+
# counts is { [decision, index] => counts } and decision_paths is
|
|
12
|
+
# { decision => { path => evaluations } }, both from the
|
|
13
13
|
# recorder.
|
|
14
|
-
def initialize(
|
|
15
|
-
@
|
|
14
|
+
def initialize(decisions, counts, decision_paths = {})
|
|
15
|
+
@decisions = decisions
|
|
16
16
|
@counts = counts
|
|
17
|
-
@
|
|
17
|
+
@decision_paths = decision_paths
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
# {
|
|
21
|
-
# of each
|
|
22
|
-
# evaluations that took it, zero for one never
|
|
20
|
+
# { decision => [{ path:, count: }, ...] }: every possible path
|
|
21
|
+
# of each decision, as DecisionPaths gives them, with the
|
|
22
|
+
# number of evaluations that took it, zero for one never
|
|
23
|
+
# taken.
|
|
23
24
|
def paths
|
|
24
|
-
@
|
|
25
|
-
taken = @
|
|
26
|
-
all =
|
|
25
|
+
@decisions.to_h do |decision, condition|
|
|
26
|
+
taken = @decision_paths.fetch(decision, {})
|
|
27
|
+
all = DecisionPaths.possible(condition).map do |path|
|
|
27
28
|
{ path:, count: taken.fetch(path, 0) }
|
|
28
29
|
end
|
|
29
|
-
[
|
|
30
|
+
[decision, all]
|
|
30
31
|
end
|
|
31
32
|
end
|
|
32
33
|
|
|
33
|
-
# {
|
|
34
|
-
# that is none of its
|
|
35
|
-
# nil though treated as present; only
|
|
34
|
+
# { decision => { path => evaluations } } of each path taken
|
|
35
|
+
# that is none of its decision's possible paths, eg a &. receiver
|
|
36
|
+
# nil though treated as present; only decisions with one. Such a
|
|
36
37
|
# path shows a treatment to be wrong, so it is reported, never
|
|
37
38
|
# dropped.
|
|
38
39
|
def outside
|
|
39
|
-
all = @
|
|
40
|
-
taken = @
|
|
41
|
-
[
|
|
40
|
+
all = @decisions.to_h do |decision, condition|
|
|
41
|
+
taken = @decision_paths.fetch(decision, {})
|
|
42
|
+
[decision, taken.except(*DecisionPaths.possible(condition))]
|
|
42
43
|
end
|
|
43
44
|
all.reject { |_, paths| paths.empty? }
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
# The paths taken, as Render.run takes them:
|
|
47
|
+
# The paths taken, as Render.run takes them: decision_paths:,
|
|
47
48
|
# as paths gives them, and outside:.
|
|
48
49
|
def taken
|
|
49
|
-
{
|
|
50
|
+
{ decision_paths: paths, outside: }
|
|
50
51
|
end
|
|
51
52
|
|
|
52
|
-
# {
|
|
53
|
+
# { decision => [counts of operand 0, counts of operand 1, ...] },
|
|
53
54
|
# with zero counts for an operand that never ran, and
|
|
54
55
|
# only: naming the one outcome a fixed leaf can have.
|
|
55
56
|
def operands
|
|
56
|
-
@
|
|
57
|
+
@decisions.to_h do |decision, condition|
|
|
57
58
|
leaves = condition.leaves.each_with_index.map do |range, i|
|
|
58
|
-
leaf(
|
|
59
|
+
leaf(decision, condition, range, i)
|
|
59
60
|
end
|
|
60
|
-
[
|
|
61
|
+
[decision, leaves]
|
|
61
62
|
end
|
|
62
63
|
end
|
|
63
64
|
|
|
64
65
|
private
|
|
65
66
|
|
|
66
67
|
# The counts of one leaf, with only: when it is fixed.
|
|
67
|
-
def leaf(
|
|
68
|
-
counts = counts_of(
|
|
68
|
+
def leaf(decision, condition, range, index)
|
|
69
|
+
counts = counts_of(decision, index)
|
|
69
70
|
only = condition.fixed[range]
|
|
70
71
|
only ? counts.merge(only:) : counts
|
|
71
72
|
end
|
|
72
73
|
|
|
73
74
|
# The recorded counts of one operand, or zeros.
|
|
74
|
-
def counts_of(
|
|
75
|
-
@counts.fetch([
|
|
75
|
+
def counts_of(decision, index)
|
|
76
|
+
@counts.fetch([decision, index], NEVER_RAN)
|
|
76
77
|
end
|
|
77
78
|
end
|
|
78
79
|
end
|