path_coverage 0.7.0 → 0.7.1
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/lib/path_coverage/paths_context.rb +47 -22
- data/lib/path_coverage/version.rb +1 -1
- data/lib/path_coverage/within_methods.rb +22 -21
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3aba82007768b3ee01a089934083c833dcc35d9dffbde4998c04559e4d93e257
|
|
4
|
+
data.tar.gz: 13e4c34a101f2ef4143c1c39a2be3dfd3da871d483a7b675980d944fccac002d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c2098204eb8f2b5a75bead720fcc93a2518db3621c1a0223fedda9dbf8a57cc09cc4ceac226ec83d242901fe7b77e4104077a14584e0d9de07c1637d6863b77d
|
|
7
|
+
data.tar.gz: 407f0209d11862e23b65744ece44d197b17484a27c3293afac0eb617a4c81b3c39f5076e6a5df23d23c01c3502b111589b8d64908d943bc169dcf76c30364f30
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
require_relative 'loop_forks'
|
|
1
2
|
require_relative 'paths_tree'
|
|
2
3
|
require_relative 'paths_ways'
|
|
3
4
|
require_relative 'method_statements'
|
|
5
|
+
require_relative 'rescue_forks'
|
|
4
6
|
require_relative 'way_algebras'
|
|
5
7
|
|
|
6
8
|
module PathCoverage
|
|
@@ -9,22 +11,39 @@ module PathCoverage
|
|
|
9
11
|
# and any taken that it rules out, which are counted, never
|
|
10
12
|
# dropped, and reported. Paths combined count these, where paths
|
|
11
13
|
# alone count each decision's paths on its own.
|
|
12
|
-
#
|
|
13
|
-
# Recorder#reached does, nil when not known.
|
|
14
|
+
# recorded is [paths, reached]: paths as Result#paths gives it,
|
|
15
|
+
# and reached as Recorder#reached does, nil when not known.
|
|
16
|
+
# scopes is a def's [loop forks, rescue forks, forking], as
|
|
17
|
+
# scopes_of gives them, the scopes its flow is folded with.
|
|
14
18
|
module PathsContext
|
|
15
19
|
# Example: { "k.rb:1:0" => [2, 3] } for ship, its first row's
|
|
16
20
|
# 2 paths both taken, its second's 1 path, of 2, that its
|
|
17
21
|
# method can take, not taken.
|
|
18
|
-
# Each def's flow total in source, [taken, size], its
|
|
19
|
-
# taken as MethodStatements.taken gives them, a row not
|
|
20
|
-
# counting as not taken, and its size their paths as rows
|
|
21
|
-
# gives them.
|
|
22
|
-
def self.totals(source, path,
|
|
22
|
+
# Each def's flow total in source, at path, [taken, size], its
|
|
23
|
+
# rows' taken as MethodStatements.taken gives them, a row not
|
|
24
|
+
# known counting as not taken, and its size their paths as rows
|
|
25
|
+
# gives them. forking says whether loops fork.
|
|
26
|
+
def self.totals(source, path, recorded, decisions, forking)
|
|
27
|
+
scopes = scopes_of(source, path, forking)
|
|
23
28
|
flows = MethodStatements.of(source, path, decisions)
|
|
24
|
-
flows.
|
|
25
|
-
shown = rows(source, decisions, rows,
|
|
29
|
+
flows.to_h do |key, rows|
|
|
30
|
+
shown = rows(source, decisions, rows, recorded,
|
|
31
|
+
scopes.fetch(key))
|
|
26
32
|
seen = shown.filter_map(&:last).sum
|
|
27
|
-
|
|
33
|
+
size = MethodStatements.size(shown.map { _1.first.paths })
|
|
34
|
+
[key, [seen, size]]
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Example: { "k.rb:1:0" => [{}, { "k.rb:3:2" => [...] }, false] }
|
|
39
|
+
# for a def at line 1 with no loop and one rescue fork.
|
|
40
|
+
# { def decision => its scopes } for each def in source, at
|
|
41
|
+
# path: its loops, as LoopForks gives them, its rescue forks,
|
|
42
|
+
# as RescueForks gives them, and forking, whether loops fork.
|
|
43
|
+
def self.scopes_of(source, path, forking)
|
|
44
|
+
forks = LoopForks.of(source, path)
|
|
45
|
+
RescueForks.of(source, path).to_h do |key, rescues|
|
|
46
|
+
[key, [forks.fetch(key), rescues, forking]]
|
|
28
47
|
end
|
|
29
48
|
end
|
|
30
49
|
|
|
@@ -32,27 +51,30 @@ module PathCoverage
|
|
|
32
51
|
# as its paths how many of them its method can take or took,
|
|
33
52
|
# as of gives them, and taken as MethodStatements.taken gives
|
|
34
53
|
# it.
|
|
35
|
-
def self.rows(source, decisions, rows,
|
|
36
|
-
context = of(source, decisions, rows,
|
|
54
|
+
def self.rows(source, decisions, rows, recorded, scopes)
|
|
55
|
+
context = of(source, decisions, rows, recorded, scopes)
|
|
37
56
|
shown = rows.zip(context).map do |row, (can, took)|
|
|
38
57
|
row.with(paths: (can | took).size)
|
|
39
58
|
end
|
|
40
|
-
shown.zip(MethodStatements.taken(rows,
|
|
59
|
+
shown.zip(MethodStatements.taken(rows, *recorded))
|
|
41
60
|
end
|
|
42
61
|
|
|
43
62
|
# Example: [[[1], [1]], [[0, 1], [0]]] for return 0 if a, then
|
|
44
63
|
# a ?: of b, called once with a false and b true.
|
|
45
64
|
# [the indices of its paths its method can take, those taken]
|
|
46
65
|
# for each of rows, a flow's in source: those on some way
|
|
47
|
-
# through the flow, as WayAlgebras::Labelled
|
|
48
|
-
#
|
|
49
|
-
|
|
66
|
+
# through the flow folded with scopes, as WayAlgebras::Labelled
|
|
67
|
+
# folds them, so each rescue's rows are an alternative to the
|
|
68
|
+
# others'; and those taken, a return's or a raise's one path
|
|
69
|
+
# index 0.
|
|
70
|
+
def self.of(source, decisions, rows, recorded, scopes)
|
|
50
71
|
labelled = WayAlgebras::Labelled
|
|
51
|
-
labels = PathsWays.flow(source, decisions, rows, labelled
|
|
72
|
+
labels = PathsWays.flow(source, decisions, rows, labelled,
|
|
73
|
+
[true, *scopes])
|
|
52
74
|
by_key = labels.group_by(&:first)
|
|
53
75
|
rows.map do |row|
|
|
54
76
|
can = by_key.fetch(PathsTree.key_of(row), []).map(&:last)
|
|
55
|
-
[can, taken_paths(row,
|
|
77
|
+
[can, taken_paths(row, *recorded)]
|
|
56
78
|
end
|
|
57
79
|
end
|
|
58
80
|
|
|
@@ -77,9 +99,11 @@ module PathCoverage
|
|
|
77
99
|
files.flat_map do |full_path, parsed|
|
|
78
100
|
source, decisions = parsed.values_at(:source, :decisions)
|
|
79
101
|
path = config.relative(full_path)
|
|
102
|
+
scopes = scopes_of(source, path, config.loops?)
|
|
80
103
|
flows = MethodStatements.of(source, path, decisions)
|
|
81
|
-
flows.
|
|
82
|
-
ruled_in(source, decisions, rows, paths, reached
|
|
104
|
+
flows.flat_map do |key, rows|
|
|
105
|
+
ruled_in(source, decisions, rows, [paths, reached],
|
|
106
|
+
scopes.fetch(key))
|
|
83
107
|
end
|
|
84
108
|
end
|
|
85
109
|
end
|
|
@@ -87,8 +111,9 @@ module PathCoverage
|
|
|
87
111
|
# [name, path] for each path of rows, a flow's in source, taken
|
|
88
112
|
# though its method rules it out: a decision's name and the
|
|
89
113
|
# path, as paths has it; a return's or a raise's and nil.
|
|
90
|
-
def self.ruled_in(source, decisions, rows,
|
|
91
|
-
context = of(source, decisions, rows,
|
|
114
|
+
def self.ruled_in(source, decisions, rows, recorded, scopes)
|
|
115
|
+
context = of(source, decisions, rows, recorded, scopes)
|
|
116
|
+
paths = recorded.first
|
|
92
117
|
rows.zip(context).flat_map do |row, (can, took)|
|
|
93
118
|
(took - can).map { [row.name, path_at(row, _1, paths)] }
|
|
94
119
|
end
|
|
@@ -3,7 +3,6 @@ require_relative 'paths_scopes'
|
|
|
3
3
|
require_relative 'paths_tree'
|
|
4
4
|
require_relative 'paths_way_lists'
|
|
5
5
|
require_relative 'paths_ways'
|
|
6
|
-
require_relative 'loop_forks'
|
|
7
6
|
require_relative 'method_loops'
|
|
8
7
|
require_relative 'method_statements'
|
|
9
8
|
require_relative 'method_ways'
|
|
@@ -22,9 +21,11 @@ module PathCoverage
|
|
|
22
21
|
files.map do |full_path, parsed|
|
|
23
22
|
path = config.relative(full_path)
|
|
24
23
|
source, decisions = parsed.values_at(:source, :decisions)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
top = MethodStatements.top_level(source, path, paths,
|
|
25
|
+
decisions)
|
|
26
|
+
recorded = [paths, reached]
|
|
27
|
+
PathsContext.totals(source, path, recorded, decisions,
|
|
28
|
+
config.loops?)
|
|
28
29
|
.merge("#{path}:0:0" => top)
|
|
29
30
|
end.reduce({}, :merge)
|
|
30
31
|
end
|
|
@@ -116,7 +117,7 @@ module PathCoverage
|
|
|
116
117
|
source, decisions = parsed.values_at(:source, :decisions)
|
|
117
118
|
titles = titles(source, path, decisions)
|
|
118
119
|
lister = WayLister.new(source, path, decisions, counted)
|
|
119
|
-
context = [source, decisions, paths, reached]
|
|
120
|
+
context = [source, decisions, [paths, reached], lister]
|
|
120
121
|
MethodStatements.of(source, path, decisions).to_h do |key, rows|
|
|
121
122
|
count = lister.count(key, rows)
|
|
122
123
|
named = [*titles[key], count, reached&.fetch(key, 0)]
|
|
@@ -126,12 +127,13 @@ module PathCoverage
|
|
|
126
127
|
end
|
|
127
128
|
|
|
128
129
|
# The flow of the def at key, its rows, named as flow takes
|
|
129
|
-
# named; context is [source, decisions,
|
|
130
|
-
# listed_in has them
|
|
130
|
+
# named; context is [source, decisions, recorded, lister], as
|
|
131
|
+
# listed_in has them, recorded as PathsContext takes it, and
|
|
132
|
+
# lister the WayLister giving the def's scopes.
|
|
131
133
|
def self.method_flow(key, rows, named, context)
|
|
132
|
-
source, decisions,
|
|
133
|
-
shown = PathsContext.rows(source, decisions, rows,
|
|
134
|
-
|
|
134
|
+
source, decisions, recorded, lister = context
|
|
135
|
+
shown = PathsContext.rows(source, decisions, rows, recorded,
|
|
136
|
+
lister.scopes(key))
|
|
135
137
|
flow(key, named, shown)
|
|
136
138
|
end
|
|
137
139
|
|
|
@@ -156,9 +158,7 @@ module PathCoverage
|
|
|
156
158
|
@ways = ways
|
|
157
159
|
@limit = limit
|
|
158
160
|
@loops = MethodLoops.of(source, path, decisions)
|
|
159
|
-
@
|
|
160
|
-
@rescues = RescueForks.of(source, path)
|
|
161
|
-
@forking = loops
|
|
161
|
+
@scopes = PathsContext.scopes_of(source, path, loops)
|
|
162
162
|
end
|
|
163
163
|
|
|
164
164
|
# How many ways go through the flow of the def at key, its
|
|
@@ -185,26 +185,27 @@ module PathCoverage
|
|
|
185
185
|
walked.merge(PathsWayLists.checked(key, @ways, checked))
|
|
186
186
|
end
|
|
187
187
|
|
|
188
|
-
private
|
|
189
|
-
|
|
190
188
|
# [forks, rescues, forking] of the def at key, as
|
|
191
|
-
# MethodWays.split_flow
|
|
192
|
-
#
|
|
193
|
-
# forks. forking says whether its loops fork.
|
|
189
|
+
# MethodWays.split_flow and PathsContext take them, as
|
|
190
|
+
# PathsContext.scopes_of gives them.
|
|
194
191
|
def scopes(key)
|
|
195
|
-
|
|
192
|
+
@scopes.fetch(key)
|
|
196
193
|
end
|
|
197
194
|
|
|
195
|
+
private
|
|
196
|
+
|
|
198
197
|
# The names of the loops of the def at key: those holding a
|
|
199
198
|
# row, and those that fork.
|
|
200
199
|
def loops(key)
|
|
201
|
-
|
|
200
|
+
forks = scopes(key).first
|
|
201
|
+
(@loops[key].values.flatten + forks.keys).uniq
|
|
202
202
|
end
|
|
203
203
|
|
|
204
204
|
# The loops of the def at key that fork, as
|
|
205
205
|
# LoopForks gives them; none unless loops are forks.
|
|
206
206
|
def forked(key)
|
|
207
|
-
|
|
207
|
+
forks, _, forking = scopes(key)
|
|
208
|
+
forking ? forks : {}
|
|
208
209
|
end
|
|
209
210
|
end
|
|
210
211
|
|