path_coverage 0.7.1 → 0.8.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 +45 -19
- data/lib/path_coverage/call_trace.rb +1 -1
- data/lib/path_coverage/calls.rb +35 -8
- data/lib/path_coverage/condition.rb +35 -9
- data/lib/path_coverage/current_test.rb +28 -0
- data/lib/path_coverage/decision.rb +7 -0
- data/lib/path_coverage/decision_sites.rb +40 -0
- data/lib/path_coverage/decision_tree.rb +11 -21
- data/lib/path_coverage/evaluated.rb +23 -0
- data/lib/path_coverage/fold_rows.rb +7 -8
- data/lib/path_coverage/gaps.rb +4 -4
- data/lib/path_coverage/json_reader.rb +22 -17
- data/lib/path_coverage/json_reports.rb +5 -3
- data/lib/path_coverage/json_writer.rb +12 -8
- data/lib/path_coverage/kernel.rb +11 -3
- data/lib/path_coverage/kinds/base.rb +9 -0
- data/lib/path_coverage/kinds/block.rb +7 -1
- data/lib/path_coverage/kinds/case.rb +63 -20
- data/lib/path_coverage/kinds/chain.rb +13 -3
- data/lib/path_coverage/kinds/choice.rb +5 -0
- data/lib/path_coverage/kinds/contains.rb +6 -0
- data/lib/path_coverage/kinds/safe.rb +3 -3
- data/lib/path_coverage/kinds/write.rb +3 -3
- data/lib/path_coverage/kinds.rb +14 -0
- data/lib/path_coverage/loop_nodes.rb +15 -10
- data/lib/path_coverage/manifest.rb +61 -35
- data/lib/path_coverage/manifest_case.rb +43 -26
- data/lib/path_coverage/manifest_folding.rb +20 -0
- data/lib/path_coverage/merge.rb +8 -8
- data/lib/path_coverage/method_statements.rb +41 -61
- data/lib/path_coverage/minitest.rb +7 -0
- data/lib/path_coverage/minitest_tests.rb +25 -0
- data/lib/path_coverage/paths_context.rb +2 -2
- data/lib/path_coverage/paths_forks.rb +6 -3
- data/lib/path_coverage/paths_leaving.rb +3 -1
- data/lib/path_coverage/paths_regions.rb +78 -0
- data/lib/path_coverage/paths_rescues.rb +5 -2
- data/lib/path_coverage/paths_scopes.rb +2 -1
- data/lib/path_coverage/paths_tree.rb +10 -68
- data/lib/path_coverage/paths_way_lists.rb +11 -10
- data/lib/path_coverage/recorder.rb +28 -47
- data/lib/path_coverage/recorder_blocks.rb +3 -3
- data/lib/path_coverage/recorder_cases.rb +70 -17
- data/lib/path_coverage/recorder_chains.rb +2 -2
- data/lib/path_coverage/render.rb +7 -3
- data/lib/path_coverage/report_tallies.rb +79 -0
- data/lib/path_coverage/report_text.rb +23 -0
- data/lib/path_coverage/rescue_forks.rb +3 -0
- data/lib/path_coverage/result.rb +17 -16
- data/lib/path_coverage/rewriter.rb +42 -114
- data/lib/path_coverage/rewriter_marks.rb +108 -0
- data/lib/path_coverage/source_report.rb +5 -6
- data/lib/path_coverage/stable_leaves.rb +6 -26
- data/lib/path_coverage/statement_arms.rb +23 -25
- data/lib/path_coverage/statement_tops.rb +53 -0
- data/lib/path_coverage/tally.rb +129 -0
- data/lib/path_coverage/testing.rb +13 -0
- data/lib/path_coverage/totals.rb +3 -3
- data/lib/path_coverage/version.rb +1 -1
- data/lib/path_coverage/walk.rb +4 -3
- data/lib/path_coverage/ways_report.rb +11 -10
- data/lib/path_coverage/within_methods.rb +12 -3
- metadata +13 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require_relative 'method_ways'
|
|
2
|
+
require_relative 'tally'
|
|
2
3
|
require_relative 'ways_report'
|
|
3
4
|
|
|
4
5
|
module PathCoverage
|
|
@@ -49,23 +50,23 @@ module PathCoverage
|
|
|
49
50
|
end
|
|
50
51
|
end
|
|
51
52
|
|
|
52
|
-
# { way =>
|
|
53
|
-
#
|
|
54
|
-
# gives them, each loop of forked a fork.
|
|
53
|
+
# { way => Tally of the calls that witnessed it } of walked,
|
|
54
|
+
# { way => Tally }, each way's steps ordered, as
|
|
55
|
+
# MethodWays.witnessed gives them, each loop of forked a fork.
|
|
55
56
|
def self.witnessed(walked, forked)
|
|
56
|
-
walked.each_with_object(
|
|
57
|
-
MethodWays.witnessed(way, forked).each {
|
|
57
|
+
walked.each_with_object(Tally.per_key) do |(way, tests), found|
|
|
58
|
+
MethodWays.witnessed(way, forked).each { found[_1] += tests }
|
|
58
59
|
end
|
|
59
60
|
end
|
|
60
61
|
|
|
61
|
-
# [{ "way", "
|
|
62
|
-
# seen
|
|
62
|
+
# [{ "way", "tests" }] of each of possible some call took, as
|
|
63
|
+
# seen tallies them.
|
|
63
64
|
def self.covered(possible, seen)
|
|
64
65
|
possible.filter_map do |way|
|
|
65
|
-
|
|
66
|
-
next
|
|
66
|
+
tests = seen.fetch(MethodWays.matched(way)) { Tally.new }
|
|
67
|
+
next if tests.empty?
|
|
67
68
|
|
|
68
|
-
{ 'way' => WaysReport.way(way), '
|
|
69
|
+
{ 'way' => WaysReport.way(way), 'tests' => tests }
|
|
69
70
|
end
|
|
70
71
|
end
|
|
71
72
|
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require_relative 'call_trace'
|
|
2
2
|
require_relative 'condition'
|
|
3
|
+
require_relative 'current_test'
|
|
3
4
|
require_relative 'recorder_blocks'
|
|
4
5
|
require_relative 'recorder_cases'
|
|
5
6
|
require_relative 'recorder_chains'
|
|
@@ -14,26 +15,28 @@ module PathCoverage
|
|
|
14
15
|
include RecorderWrites
|
|
15
16
|
|
|
16
17
|
# One evaluation's way through its decision: the outcome of
|
|
17
|
-
# each leaf, nil for one not yet, or never, reached;
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
|
|
18
|
+
# each leaf, nil for one not yet, or never, reached; whether it
|
|
19
|
+
# witnesses no path, as when a block method's block was never
|
|
20
|
+
# called; and the index of a case pattern reached whose
|
|
21
|
+
# outcome is not yet known, nil for none.
|
|
22
|
+
Trail = Struct.new(:decision, :outcomes, :unwitnessed, :pending)
|
|
21
23
|
|
|
22
24
|
# Starts with no outcomes, decision paths or reaches counted.
|
|
25
|
+
# Every count is a Tally, by the test under way as it happens.
|
|
23
26
|
def initialize
|
|
24
27
|
@counts = Hash.new do |counts, key|
|
|
25
|
-
counts[key] = { truthy:
|
|
28
|
+
counts[key] = { truthy: Tally.new, falsy: Tally.new }
|
|
26
29
|
end
|
|
27
30
|
@decision_paths = Hash.new do |decision_paths, decision|
|
|
28
|
-
decision_paths[decision] =
|
|
31
|
+
decision_paths[decision] = Tally.per_key
|
|
29
32
|
end
|
|
30
|
-
@reached =
|
|
33
|
+
@reached = Tally.per_key
|
|
31
34
|
@trails_key = :"path_coverage_trails_#{object_id}"
|
|
32
35
|
@trace = CallTrace.new
|
|
33
36
|
end
|
|
34
37
|
|
|
35
|
-
# { name =>
|
|
36
|
-
# name, eg
|
|
38
|
+
# { name => Tally } of the runs of each statement reached so
|
|
39
|
+
# far, by its name, eg "k.rb:2:2"; none never reached.
|
|
37
40
|
attr_reader :reached
|
|
38
41
|
|
|
39
42
|
# The ways each call of a covered method has taken so far.
|
|
@@ -42,7 +45,7 @@ module PathCoverage
|
|
|
42
45
|
# Counts a run of the statement named name, a step of its
|
|
43
46
|
# call's way.
|
|
44
47
|
def reach(name)
|
|
45
|
-
@reached[name]
|
|
48
|
+
@reached[name].add(CurrentTest.id)
|
|
46
49
|
@trace.reach(name)
|
|
47
50
|
nil
|
|
48
51
|
end
|
|
@@ -95,11 +98,14 @@ module PathCoverage
|
|
|
95
98
|
# leaves, took trail's later outcomes, so trail's path is
|
|
96
99
|
# not counted; the stack is cleared down to trail either
|
|
97
100
|
# way. An unwitnessed trail's path is not counted either.
|
|
98
|
-
# A counted path is a step of its call's way.
|
|
101
|
+
# A counted path is a step of its call's way. A trail already
|
|
102
|
+
# left, as a case is when its arm is taken, is left once only.
|
|
99
103
|
def leave(trail, value)
|
|
100
104
|
stack = trails(trail.decision)
|
|
105
|
+
return value unless stack.include?(trail)
|
|
106
|
+
|
|
101
107
|
clean = stack.last.equal?(trail)
|
|
102
|
-
nil until stack.
|
|
108
|
+
nil until stack.pop.equal?(trail)
|
|
103
109
|
decided(trail) if clean && !trail.unwitnessed
|
|
104
110
|
value
|
|
105
111
|
end
|
|
@@ -107,55 +113,30 @@ module PathCoverage
|
|
|
107
113
|
# Counts trail's path, its decision's, and steps its call's
|
|
108
114
|
# way with it.
|
|
109
115
|
def decided(trail)
|
|
110
|
-
@decision_paths[trail.decision][trail.outcomes]
|
|
116
|
+
@decision_paths[trail.decision][trail.outcomes]
|
|
117
|
+
.add(CurrentTest.id)
|
|
111
118
|
@trace.decided(trail.decision, trail.outcomes)
|
|
112
119
|
end
|
|
113
120
|
|
|
114
|
-
# The truthy and falsy
|
|
121
|
+
# The truthy and falsy Tallies of every operand recorded so
|
|
115
122
|
# far, keyed by [decision, index]; an operand that never ran
|
|
116
123
|
# has no entry.
|
|
117
124
|
attr_reader :counts
|
|
118
125
|
|
|
126
|
+
# Counts one more outcome, :truthy or :falsy, of the operand
|
|
127
|
+
# keyed key, [decision, index], under the test under way.
|
|
128
|
+
def count(key, outcome)
|
|
129
|
+
@counts[key][outcome].add(CurrentTest.id)
|
|
130
|
+
end
|
|
131
|
+
|
|
119
132
|
# Counts value's outcome and returns it unchanged, so the
|
|
120
133
|
# condition around it behaves exactly as uninstrumented.
|
|
121
134
|
def record(decision, index, value)
|
|
122
135
|
outcome = value ? :truthy : :falsy
|
|
123
|
-
|
|
136
|
+
count([decision, index], outcome)
|
|
124
137
|
trail = trails(decision).last
|
|
125
138
|
trail.outcomes[index] = outcome == :truthy if trail
|
|
126
139
|
value
|
|
127
140
|
end
|
|
128
|
-
|
|
129
|
-
# A stand-in for a case's index-th pattern of total: the
|
|
130
|
-
# case matches its subject against the stand-in, which
|
|
131
|
-
# matches it against the pattern, once, as the case would
|
|
132
|
-
# have.
|
|
133
|
-
WhenMatch = Struct.new(
|
|
134
|
-
:recorder, :decision, :index, :total, :pattern
|
|
135
|
-
) do
|
|
136
|
-
# Whether pattern matches subject, exactly as pattern says,
|
|
137
|
-
# noted on the decision's path.
|
|
138
|
-
def ===(subject)
|
|
139
|
-
recorder.matched(decision, index, total, pattern === subject)
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
# The stand-in for pattern, the index-th of size in the case
|
|
144
|
-
# at decision.
|
|
145
|
-
def when_match(decision, index, size, pattern)
|
|
146
|
-
WhenMatch.new(self, decision, index, size, pattern)
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
# Notes whether the index-th of size patterns matched, the
|
|
150
|
-
# first entering the case's decision, and a match or the last
|
|
151
|
-
# leaving it, as no more patterns are then tried; returns
|
|
152
|
-
# matched unchanged.
|
|
153
|
-
def matched(decision, index, size, matched)
|
|
154
|
-
enter(decision, size) if index.zero?
|
|
155
|
-
record(decision, index, matched)
|
|
156
|
-
last = matched || index == size - 1
|
|
157
|
-
leave(trails(decision).last, matched) if last
|
|
158
|
-
matched
|
|
159
|
-
end
|
|
160
141
|
end
|
|
161
142
|
end
|
|
@@ -6,7 +6,7 @@ module PathCoverage
|
|
|
6
6
|
# after the receiver's, at; at is 0 for a call that is a decision
|
|
7
7
|
# of its own. The receiver's leaf stays nil, as how many items
|
|
8
8
|
# the block was called with is a loop's question. It relies on
|
|
9
|
-
# its includer's
|
|
9
|
+
# its includer's count, record and trails.
|
|
10
10
|
module RecorderBlocks
|
|
11
11
|
# Starts a block method's call in decision, its receiver the
|
|
12
12
|
# decision's at-th leaf; returns the decision's current trail,
|
|
@@ -31,7 +31,7 @@ module PathCoverage
|
|
|
31
31
|
def answer_at(decision, at, value)
|
|
32
32
|
trail = trails(decision).last
|
|
33
33
|
note_answer(trail, at, value) if trail
|
|
34
|
-
|
|
34
|
+
count([decision, at + 1], value ? :truthy : :falsy)
|
|
35
35
|
value
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -52,7 +52,7 @@ module PathCoverage
|
|
|
52
52
|
def end_items(decision, at, trail, value)
|
|
53
53
|
called = trail.nil? || !trail.outcomes[at + 1].nil?
|
|
54
54
|
trail.unwitnessed = true unless called
|
|
55
|
-
|
|
55
|
+
count([decision, at], called ? :truthy : :falsy)
|
|
56
56
|
value
|
|
57
57
|
end
|
|
58
58
|
end
|
|
@@ -1,24 +1,77 @@
|
|
|
1
1
|
module PathCoverage
|
|
2
|
-
# The part of the recorder that notes a case
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
2
|
+
# The part of the recorder that notes a case's patterns. Ruby
|
|
3
|
+
# itself matches each pattern against the subject, or tests it
|
|
4
|
+
# for truth in a case with no subject, in the code's own frame;
|
|
5
|
+
# so no pattern's outcome is seen when it is matched. Instead
|
|
6
|
+
# tried notes each pattern reached, which tells the pattern
|
|
7
|
+
# reached before it did not match; took, first in a when arm,
|
|
8
|
+
# tells the pattern last reached matched; missed, after the last
|
|
9
|
+
# pattern, tells it did not; and settled, around the whole case,
|
|
10
|
+
# tells a pattern still pending matched, its when arm having no
|
|
11
|
+
# statements. A case that is a decision of its own is decided in
|
|
12
|
+
# took and missed, before an arm that may leave runs; one nested
|
|
13
|
+
# in another decision's leaf only notes, for that decision to
|
|
14
|
+
# decide. It relies on its includer's trails, record and leave.
|
|
6
15
|
module RecorderCases
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
# Notes the index-th leaf of decision reached, a pattern whose
|
|
17
|
+
# outcome is pending, the pattern pending before it not having
|
|
18
|
+
# matched; returns pattern unchanged. decision is always under
|
|
19
|
+
# way: a case is entered before its subject, and a case in a
|
|
20
|
+
# leaf runs inside its decision's evaluation.
|
|
21
|
+
def tried(decision, index, pattern)
|
|
22
|
+
trail = trails(decision).last
|
|
23
|
+
pending(trail, false)
|
|
24
|
+
trail.pending = index
|
|
25
|
+
pattern
|
|
16
26
|
end
|
|
17
27
|
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
def
|
|
21
|
-
|
|
28
|
+
# Notes that the pattern pending in decision, a case of its own,
|
|
29
|
+
# matched, and decides it, as its arm is about to run.
|
|
30
|
+
def took(decision)
|
|
31
|
+
trail = trails(decision).last
|
|
32
|
+
pending(trail, true)
|
|
33
|
+
leave(trail, nil)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Notes that the pattern pending in decision, a case of its own,
|
|
37
|
+
# did not match, and decides it; returns no patterns.
|
|
38
|
+
def missed(decision)
|
|
39
|
+
trail = trails(decision).last
|
|
40
|
+
pending(trail, false)
|
|
41
|
+
leave(trail, nil)
|
|
42
|
+
[]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Notes that the pattern pending in decision, around a case in
|
|
46
|
+
# its leaf, matched.
|
|
47
|
+
def took_within(decision)
|
|
48
|
+
pending(trails(decision).last, true)
|
|
49
|
+
nil
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Notes that the pattern pending in decision, around a case in
|
|
53
|
+
# its leaf, did not match; returns no patterns.
|
|
54
|
+
def missed_within(decision)
|
|
55
|
+
pending(trails(decision).last, false)
|
|
56
|
+
[]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Notes that a pattern still pending in decision when its case
|
|
60
|
+
# ends matched, as only a when arm with no statements leaves it
|
|
61
|
+
# so; returns value, the case's, unchanged.
|
|
62
|
+
def settled(decision, value)
|
|
63
|
+
pending(trails(decision).last, true)
|
|
64
|
+
value
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Notes outcome as that of the pattern pending on trail, if
|
|
68
|
+
# any, which is then pending no more.
|
|
69
|
+
def pending(trail, outcome)
|
|
70
|
+
index = trail&.pending
|
|
71
|
+
return if index.nil?
|
|
72
|
+
|
|
73
|
+
record(trail.decision, index, outcome)
|
|
74
|
+
trail.pending = nil
|
|
22
75
|
end
|
|
23
76
|
end
|
|
24
77
|
end
|
|
@@ -2,7 +2,7 @@ require_relative 'condition'
|
|
|
2
2
|
|
|
3
3
|
module PathCoverage
|
|
4
4
|
# The part of the recorder that notes &. chains. It relies on
|
|
5
|
-
# its includer's
|
|
5
|
+
# its includer's count, record and trails.
|
|
6
6
|
module RecorderChains
|
|
7
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
|
|
@@ -12,7 +12,7 @@ module PathCoverage
|
|
|
12
12
|
def present(decision, index, first, value)
|
|
13
13
|
return value unless reached?(decision, first, index)
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
count([decision, index], value.nil? ? :falsy : :truthy)
|
|
16
16
|
trail = trails(decision).last
|
|
17
17
|
trail.outcomes[index] = PRESENCE[value.nil? ? 1 : 0] if trail
|
|
18
18
|
value
|
data/lib/path_coverage/render.rb
CHANGED
|
@@ -6,6 +6,8 @@ require_relative 'json_reports'
|
|
|
6
6
|
require_relative 'manifest'
|
|
7
7
|
require_relative 'paths_report'
|
|
8
8
|
require_relative 'post'
|
|
9
|
+
require_relative 'report_text'
|
|
10
|
+
require_relative 'tally'
|
|
9
11
|
require_relative 'decision_paths'
|
|
10
12
|
require_relative 'within_methods'
|
|
11
13
|
|
|
@@ -65,13 +67,15 @@ module PathCoverage
|
|
|
65
67
|
|
|
66
68
|
# decision_paths with every decision in files that it lacks, eg
|
|
67
69
|
# from a JSON report with no paths, given each possible
|
|
68
|
-
# path
|
|
70
|
+
# path with an empty Tally: unable to say which paths such
|
|
69
71
|
# a decision took, the report claims none.
|
|
70
72
|
def self.every_decision(decision_paths, files)
|
|
71
73
|
none = files.values.each_with_object({}) do |parsed, all|
|
|
72
74
|
parsed[:decisions].each do |decision, condition|
|
|
73
75
|
possible = DecisionPaths.possible(condition)
|
|
74
|
-
all[decision] = possible.map
|
|
76
|
+
all[decision] = possible.map do |path|
|
|
77
|
+
{ path:, tests: Tally.new }
|
|
78
|
+
end
|
|
75
79
|
end
|
|
76
80
|
end
|
|
77
81
|
none.merge(decision_paths)
|
|
@@ -90,7 +94,7 @@ module PathCoverage
|
|
|
90
94
|
lines = Gaps.lines(operands, paths:, texts:, outside:)
|
|
91
95
|
ruled = PathsContext.ruled_out(files, config, paths, reached)
|
|
92
96
|
lines += Gaps.ruled_by_method(ruled, texts)
|
|
93
|
-
lines.each { |line| puts line }
|
|
97
|
+
ReportText.utf8(lines).each { |line| puts line }
|
|
94
98
|
end
|
|
95
99
|
|
|
96
100
|
# Runs the reporters chosen in config from the JSON reports
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require_relative 'tally'
|
|
2
|
+
|
|
3
|
+
module PathCoverage
|
|
4
|
+
# Reads back the tallies of a JSON report, the inverse of
|
|
5
|
+
# Tally.jsonable: each place the schema puts a tally, { key => n },
|
|
6
|
+
# is read as a Tally by the report's tests, { key => test id }.
|
|
7
|
+
# Each place is named, as an empty tally and an empty list both
|
|
8
|
+
# read {}; a place a report leaves out stays out.
|
|
9
|
+
module ReportTallies
|
|
10
|
+
# The top-level keys of a report that hold tallies.
|
|
11
|
+
PLACES = %w[decisions paths reached outside flows].freeze
|
|
12
|
+
|
|
13
|
+
# The keys of a flow whose lists' items each have tests.
|
|
14
|
+
TAKEN_LISTS = %w[taken covered].freeze
|
|
15
|
+
|
|
16
|
+
# json, a JSON report as parsed, with every tally in it a Tally.
|
|
17
|
+
def self.restored(json)
|
|
18
|
+
tests = json.fetch('tests')
|
|
19
|
+
read = ->(listed) { Tally.read(listed, tests) }
|
|
20
|
+
PLACES.each_with_object(json.dup) do |place, restored|
|
|
21
|
+
next unless json.key?(place)
|
|
22
|
+
|
|
23
|
+
restored[place] = send(:"#{place}_of", json[place], read)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# A report's decisions, each operand's truthy and falsy read.
|
|
28
|
+
def self.decisions_of(decisions, read)
|
|
29
|
+
decisions.transform_values do |leaves|
|
|
30
|
+
leaves.map do |leaf|
|
|
31
|
+
leaf.merge('truthy' => read.call(leaf['truthy']),
|
|
32
|
+
'falsy' => read.call(leaf['falsy']))
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# A report's paths, each decision's taken paths' tests read.
|
|
38
|
+
def self.paths_of(paths, read)
|
|
39
|
+
paths.transform_values do |decision|
|
|
40
|
+
decision.merge('taken' => taken(decision['taken'], read))
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# A report's reached, each statement's reaches read.
|
|
45
|
+
def self.reached_of(reached, read)
|
|
46
|
+
reached.transform_values { read.call(_1) }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# A report's outside, each decision's paths' tests read.
|
|
50
|
+
def self.outside_of(outside, read)
|
|
51
|
+
outside.transform_values { taken(_1, read) }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# A report's flows, each read as flow reads it.
|
|
55
|
+
def self.flows_of(flows, read)
|
|
56
|
+
flows.transform_values { flow(_1, read) }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# A flow with its calls read, null for a top flow; each item's
|
|
60
|
+
# tests read in its taken and covered ways; and in each loop's
|
|
61
|
+
# passes.
|
|
62
|
+
def self.flow(flow, read)
|
|
63
|
+
restored = flow.merge('calls' => flow['calls']&.then(&read))
|
|
64
|
+
TAKEN_LISTS.each do |key|
|
|
65
|
+
restored[key] = taken(flow[key], read) if flow.key?(key)
|
|
66
|
+
end
|
|
67
|
+
return restored unless flow.key?('passes')
|
|
68
|
+
|
|
69
|
+
passes = flow['passes'].transform_values { taken(_1, read) }
|
|
70
|
+
restored.merge('passes' => passes)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# list, each item with tests, a path or a way taken, its tests
|
|
74
|
+
# read.
|
|
75
|
+
def self.taken(list, read)
|
|
76
|
+
list.map { _1.merge('tests' => read.call(_1['tests'])) }
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module PathCoverage
|
|
2
|
+
# The text the reports write, in UTF-8 as JSON and the console
|
|
3
|
+
# take it. A covered file's text is read in its own source
|
|
4
|
+
# encoding, so every string cut from it is transcoded here, where
|
|
5
|
+
# it leaves the gem, and nowhere else.
|
|
6
|
+
module ReportText
|
|
7
|
+
# value with every String in it, at any depth of Hashes and
|
|
8
|
+
# Arrays, in UTF-8: each character as written, and each byte
|
|
9
|
+
# its encoding cannot read, or UTF-8 cannot hold, U+FFFD, so
|
|
10
|
+
# characters still count as they did.
|
|
11
|
+
def self.utf8(value)
|
|
12
|
+
case value
|
|
13
|
+
when String
|
|
14
|
+
value.encode(Encoding::UTF_8, invalid: :replace,
|
|
15
|
+
undef: :replace).scrub
|
|
16
|
+
when Array then value.map { utf8(_1) }
|
|
17
|
+
when Hash
|
|
18
|
+
value.to_h { |key, item| [utf8(key), utf8(item)] }
|
|
19
|
+
else value
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'prism'
|
|
2
2
|
require_relative 'decision'
|
|
3
|
+
require_relative 'evaluated'
|
|
3
4
|
require_relative 'leaving'
|
|
4
5
|
|
|
5
6
|
module PathCoverage
|
|
@@ -27,6 +28,8 @@ module PathCoverage
|
|
|
27
28
|
|
|
28
29
|
# Finds the rescue fork of each def it visits.
|
|
29
30
|
class Found < Prism::Visitor
|
|
31
|
+
include Evaluated::Visitor
|
|
32
|
+
|
|
30
33
|
# Starts with no def visited. Forks are named as at path.
|
|
31
34
|
def initialize(path)
|
|
32
35
|
@path = path
|
data/lib/path_coverage/result.rb
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
1
|
require_relative 'decision_paths'
|
|
2
|
+
require_relative 'tally'
|
|
2
3
|
|
|
3
4
|
module PathCoverage
|
|
4
5
|
# What a run found: every decision the manifest knows of, with
|
|
5
|
-
# the
|
|
6
|
+
# the Tallies its operands were recorded with. Every
|
|
6
7
|
# reporter builds on this.
|
|
7
8
|
class Result
|
|
8
|
-
NEVER_RAN = { truthy: 0, falsy: 0 }.freeze
|
|
9
|
-
|
|
10
9
|
# decisions is { decision => Condition }, from the manifest;
|
|
11
|
-
# counts is { [decision, index] =>
|
|
12
|
-
# { decision => { path =>
|
|
13
|
-
# recorder.
|
|
10
|
+
# counts is { [decision, index] => { truthy:, falsy: } } of
|
|
11
|
+
# Tallies and decision_paths is { decision => { path => Tally } },
|
|
12
|
+
# both from the recorder.
|
|
14
13
|
def initialize(decisions, counts, decision_paths = {})
|
|
15
14
|
@decisions = decisions
|
|
16
15
|
@counts = counts
|
|
17
16
|
@decision_paths = decision_paths
|
|
18
17
|
end
|
|
19
18
|
|
|
20
|
-
# { decision => [{ path:,
|
|
21
|
-
# of each decision, as DecisionPaths gives them, with the
|
|
22
|
-
#
|
|
23
|
-
# taken.
|
|
19
|
+
# { decision => [{ path:, tests: }, ...] }: every possible path
|
|
20
|
+
# of each decision, as DecisionPaths gives them, with the Tally
|
|
21
|
+
# of the evaluations that took it, empty for one never taken.
|
|
24
22
|
def paths
|
|
25
23
|
@decisions.to_h do |decision, condition|
|
|
26
24
|
taken = @decision_paths.fetch(decision, {})
|
|
27
25
|
all = DecisionPaths.possible(condition).map do |path|
|
|
28
|
-
{ path:,
|
|
26
|
+
{ path:, tests: taken.fetch(path) { Tally.new } }
|
|
29
27
|
end
|
|
30
28
|
[decision, all]
|
|
31
29
|
end
|
|
32
30
|
end
|
|
33
31
|
|
|
34
|
-
# { decision => { path =>
|
|
32
|
+
# { decision => { path => Tally } } of each path taken
|
|
35
33
|
# that is none of its decision's possible paths, eg a &. receiver
|
|
36
34
|
# nil though treated as present; only decisions with one. Such a
|
|
37
35
|
# path shows a treatment to be wrong, so it is reported, never
|
|
@@ -51,8 +49,9 @@ module PathCoverage
|
|
|
51
49
|
end
|
|
52
50
|
|
|
53
51
|
# { decision => [counts of operand 0, counts of operand 1, ...] },
|
|
54
|
-
#
|
|
55
|
-
# only: naming the one outcome a fixed leaf can
|
|
52
|
+
# each { truthy:, falsy: } of Tallies, empty for an operand that
|
|
53
|
+
# never ran, and only: naming the one outcome a fixed leaf can
|
|
54
|
+
# have.
|
|
56
55
|
def operands
|
|
57
56
|
@decisions.to_h do |decision, condition|
|
|
58
57
|
leaves = condition.leaves.each_with_index.map do |range, i|
|
|
@@ -71,9 +70,11 @@ module PathCoverage
|
|
|
71
70
|
only ? counts.merge(only:) : counts
|
|
72
71
|
end
|
|
73
72
|
|
|
74
|
-
# The recorded
|
|
73
|
+
# The recorded Tallies of one operand, or empty ones.
|
|
75
74
|
def counts_of(decision, index)
|
|
76
|
-
@counts.fetch([decision, index]
|
|
75
|
+
@counts.fetch([decision, index]) do
|
|
76
|
+
{ truthy: Tally.new, falsy: Tally.new }
|
|
77
|
+
end
|
|
77
78
|
end
|
|
78
79
|
end
|
|
79
80
|
end
|