path_coverage 0.6.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/README.md +26 -19
- data/lib/path_coverage/condition.rb +10 -19
- data/lib/path_coverage/fold_cells.rb +0 -1
- data/lib/path_coverage/kinds/block.rb +37 -45
- data/lib/path_coverage/loop_forks.rb +11 -25
- data/lib/path_coverage/method_loops.rb +1 -1
- data/lib/path_coverage/method_ways.rb +1 -1
- data/lib/path_coverage/paths_context.rb +47 -22
- data/lib/path_coverage/paths_tree.rb +1 -1
- data/lib/path_coverage/recorder.rb +7 -4
- data/lib/path_coverage/recorder_blocks.rb +21 -30
- 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
|
data/README.md
CHANGED
|
@@ -88,7 +88,7 @@ limit a treatment to the files that glob matches.
|
|
|
88
88
|
`filter_map`, `partition` or `take_while`, the path that call took
|
|
89
89
|
often decides whether it kept any items. Paths where `any?` disagrees
|
|
90
90
|
with that are not listed, eg `ids.select { |i| i.odd? }.any?` true
|
|
91
|
-
with
|
|
91
|
+
with every answer false.
|
|
92
92
|
|
|
93
93
|
A run where a treatment turns out to be wrong is reported:
|
|
94
94
|
|
|
@@ -302,9 +302,13 @@ among its patterns, is no decision.
|
|
|
302
302
|
A call to `any?` `all?` `none?` `find` `detect` `find_index`
|
|
303
303
|
`take_while` `select` `filter` `reject` `partition` `count` or
|
|
304
304
|
`filter_map`, with no arguments and a block of one expression, is a decision
|
|
305
|
-
named at its method. Its
|
|
306
|
-
|
|
307
|
-
that
|
|
305
|
+
named at its method. Its paths are its block's answers: the last one for a
|
|
306
|
+
method that can stop early, eg `any?` true or false, and all true, all
|
|
307
|
+
false or both for one that calls its block with every item, eg `select`.
|
|
308
|
+
A call whose block was never called witnesses no path. How many items the
|
|
309
|
+
block was called with is a loop's question, asked by `loops`, so the
|
|
310
|
+
receiver is never asked its size, which could consume a sequence that can
|
|
311
|
+
be read only once.
|
|
308
312
|
|
|
309
313
|
A `||=` or `&&=` write is a decision, whatever its target: a variable of any
|
|
310
314
|
kind, a constant, an attribute (`self.size ||= n`) or an index
|
|
@@ -356,8 +360,9 @@ cannot be closed is the lesser error than hiding one that can.
|
|
|
356
360
|
### Methods
|
|
357
361
|
|
|
358
362
|
Each method has a flow, named by the `path:line:column` of its `def`,
|
|
359
|
-
with a row for each statement that shapes its paths: each decision,
|
|
360
|
-
|
|
363
|
+
with a row for each statement that shapes its paths: each decision, each
|
|
364
|
+
`return` or `raise`, which ends a path, and each `next`, `break` or
|
|
365
|
+
`retry`, which ends a pass of its loop. Any other statement, eg
|
|
361
366
|
`x = 1`, runs exactly when what holds it does, so is no row. A decision's
|
|
362
367
|
row counts its paths; a `return` or `raise` row is one path, taken
|
|
363
368
|
when it is reached. A method's total adds up its rows. Its `calls`
|
|
@@ -365,6 +370,13 @@ count how many times it was called, so a method never called is a gap,
|
|
|
365
370
|
even one with no rows. A file's code outside any method gets a flow
|
|
366
371
|
of its own.
|
|
367
372
|
|
|
373
|
+
A `begin` or `def` with `rescue` clauses forks its flow: its body
|
|
374
|
+
completes, or one of its rescues runs. A rescue can run after any part
|
|
375
|
+
of its body, as a raise can come from any call, so which exception was
|
|
376
|
+
raised is not tracked. A `rescue` modifier, `x rescue y`, forks the
|
|
377
|
+
same way, with one rescue. With `loops`, each loop forks too, a block
|
|
378
|
+
method's block included: 0 items, or 1+ items, its body walked once.
|
|
379
|
+
|
|
368
380
|
The JSON report's `flows` hold each flow's rows, its `ways` and its
|
|
369
381
|
`calls`, and its `tree` says how those rows nest.
|
|
370
382
|
|
|
@@ -396,7 +408,9 @@ flip.rb:5:11 path taken that its method rules out: `member` true
|
|
|
396
408
|
|
|
397
409
|
- `:ways` prints, for each method with a path through it that no run
|
|
398
410
|
took, the choices a test must make to take each one, every leaf by its
|
|
399
|
-
source text; a loop is named by its line and how many items it ran
|
|
411
|
+
source text; a loop is named by its line and how many items it ran,
|
|
412
|
+
and a rescue by its line and whether its body completed or which
|
|
413
|
+
rescue ran:
|
|
400
414
|
|
|
401
415
|
```text
|
|
402
416
|
lib/orders.rb:2 total() has 1 untested path.
|
|
@@ -480,8 +494,8 @@ Decisions covered now: `&&`, `||`, `and`, `or`, the ternary `?:`,
|
|
|
480
494
|
with a subject, and the block methods `any?` `all?` `none?` `find`
|
|
481
495
|
`detect` `find_index` `take_while` `select` `filter` `reject`
|
|
482
496
|
`partition` `count` `filter_map`, the writes `||=` and `&&=`, and `&.`
|
|
483
|
-
safe-navigation chains. Method paths cover every decision
|
|
484
|
-
|
|
497
|
+
safe-navigation chains. Method paths cover every decision in a method,
|
|
498
|
+
nested ones included, and its `rescue` clauses and modifiers.
|
|
485
499
|
|
|
486
500
|
Next:
|
|
487
501
|
|
|
@@ -490,28 +504,21 @@ Next:
|
|
|
490
504
|
with blocks of more than one expression
|
|
491
505
|
- `fetch(k, default)`, `dig`, `Hash#[]` with a default: present vs default
|
|
492
506
|
- `x || default` in value context: nil vs not nil
|
|
493
|
-
- `x rescue y` modifier: raised vs not raised
|
|
494
507
|
- `case` with no subject, and `case`/`in` patterns
|
|
495
508
|
- regex matches: nil vs MatchData
|
|
496
509
|
- `treat 'methods_of', as: :truthy`, so each call to it counts as a
|
|
497
510
|
leaf that is only truthy, as `Foo.new` is, and a run where it returns
|
|
498
511
|
nil or false is reported. Later, treatments could come from the
|
|
499
512
|
project's RBS signatures (`sig/*.rbs`) too.
|
|
500
|
-
- exceptions the code itself names: a `begin` or `def` with `rescue`
|
|
501
|
-
clauses as a decision, like a `case`, whose paths are no raise and each
|
|
502
|
-
clause that rescued, eg `rescue IOError` never taken. Branch coverage
|
|
503
|
-
ignores `rescue`, and tests reach these paths with real input. A raise
|
|
504
|
-
that nothing names, from any call, stays out, as every leaf would gain
|
|
505
|
-
a third outcome that only fault injection could take.
|
|
506
513
|
- an evaluation that raised part way through a decision, eg
|
|
507
514
|
`ok?(id) && fetch(id)` where `fetch` raises, reported as a path that
|
|
508
515
|
raised rather than dropped as unfinished.
|
|
509
516
|
- complexity maximums, reported and gated, since the possible paths
|
|
510
517
|
count how much there is to test, not only how much was tested. A
|
|
511
518
|
file's total measures its size, so each is a maximum over smaller
|
|
512
|
-
parts
|
|
513
|
-
|
|
514
|
-
- paths
|
|
519
|
+
parts. `max_paths` already gates the paths through one method; still
|
|
520
|
+
to come:
|
|
521
|
+
- paths in one decision, eg 3 for a `select` block
|
|
515
522
|
- paths within each decision, summed over every decision in one
|
|
516
523
|
method, nested ones included, eg decisions of 2, 3 and 15 paths
|
|
517
524
|
sum to 20. Every method has one, and it grows as the method gains
|
|
@@ -34,18 +34,14 @@ module PathCoverage
|
|
|
34
34
|
any? all? none? find detect find_index take_while
|
|
35
35
|
].freeze
|
|
36
36
|
|
|
37
|
-
# How many
|
|
38
|
-
#
|
|
37
|
+
# How many passes a loop made in a call, as a step of its
|
|
38
|
+
# way: none, one, or two or more.
|
|
39
39
|
ITEMS = ['0 items', '1 item', '2+ items'].freeze
|
|
40
40
|
|
|
41
|
-
# Every path a stop-early block method's call can take:
|
|
42
|
-
# many items
|
|
43
|
-
#
|
|
44
|
-
STOP_EARLY_PATHS = [
|
|
45
|
-
[ITEMS[0], nil],
|
|
46
|
-
[ITEMS[1], true], [ITEMS[1], false],
|
|
47
|
-
[ITEMS[2], true], [ITEMS[2], false]
|
|
48
|
-
].freeze
|
|
41
|
+
# Every path a stop-early block method's call can take: its
|
|
42
|
+
# block's last answer. How many items the block was called
|
|
43
|
+
# with is a loop's question, so the receiver's leaf is nil.
|
|
44
|
+
STOP_EARLY_PATHS = [[nil, true], [nil, false]].freeze
|
|
49
45
|
|
|
50
46
|
# The methods that call their block with every item.
|
|
51
47
|
EVERY_ITEM = %w[
|
|
@@ -55,15 +51,10 @@ module PathCoverage
|
|
|
55
51
|
# A block's answers over every item it was called with.
|
|
56
52
|
ANSWERS = ['all true', 'all false', 'both'].freeze
|
|
57
53
|
|
|
58
|
-
# Every path an every-item block method's call can take:
|
|
59
|
-
# many items
|
|
60
|
-
#
|
|
61
|
-
EVERY_ITEM_PATHS = [
|
|
62
|
-
[ITEMS[0], nil],
|
|
63
|
-
[ITEMS[1], ANSWERS[0]], [ITEMS[1], ANSWERS[1]],
|
|
64
|
-
[ITEMS[2], ANSWERS[0]], [ITEMS[2], ANSWERS[1]],
|
|
65
|
-
[ITEMS[2], ANSWERS[2]]
|
|
66
|
-
].freeze
|
|
54
|
+
# Every path an every-item block method's call can take: its
|
|
55
|
+
# block's answers. How many items the block was called with
|
|
56
|
+
# is a loop's question, so the receiver's leaf is nil.
|
|
57
|
+
EVERY_ITEM_PATHS = ANSWERS.map { [nil, _1] }.freeze
|
|
67
58
|
|
|
68
59
|
# The block methods whose value follows from their path alone:
|
|
69
60
|
# all but find and detect, whose found item may itself be nil.
|
|
@@ -13,7 +13,6 @@ module PathCoverage
|
|
|
13
13
|
# hovering as not nil or nil.
|
|
14
14
|
OUTCOMES = {
|
|
15
15
|
true => ['T'], false => ['F'], nil => [''],
|
|
16
|
-
ITEMS[0] => ['0'], ITEMS[1] => ['1'], ITEMS[2] => ['*'],
|
|
17
16
|
ANSWERS[0] => ['T'], ANSWERS[1] => ['F'], ANSWERS[2] => ['TF'],
|
|
18
17
|
PRESENCE[0] => ['', 'present', PRESENCE[0]],
|
|
19
18
|
PRESENCE[1] => ['', 'absent', PRESENCE[1]]
|
|
@@ -3,9 +3,10 @@ require_relative 'base'
|
|
|
3
3
|
module PathCoverage
|
|
4
4
|
module Kinds
|
|
5
5
|
# A block method's call, eg ids.any? { |id| id.odd? }: its
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
6
|
+
# block's answers, its value following from them. Its
|
|
7
|
+
# receiver's leaf has no outcome, as how many items the block
|
|
8
|
+
# was called with is a loop's question. Nothing else is
|
|
9
|
+
# evaluated, eg ids.size.
|
|
9
10
|
module Block
|
|
10
11
|
extend Base
|
|
11
12
|
|
|
@@ -14,57 +15,48 @@ module PathCoverage
|
|
|
14
15
|
# A value that holds whatever the path, eg select's array.
|
|
15
16
|
ALWAYS = ->(*) { true }
|
|
16
17
|
|
|
17
|
-
# nil, nothing found, when its
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
FOUND = ->(
|
|
18
|
+
# nil, nothing found, when its last answer was false; else
|
|
19
|
+
# the item found, which may itself be nil, so nil, as no
|
|
20
|
+
# path can tell.
|
|
21
|
+
FOUND = ->(answer) { answer ? nil : false }
|
|
21
22
|
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
|
|
23
|
+
# Its last answer, as the value of any?, all? and
|
|
24
|
+
# find_index.
|
|
25
|
+
LAST = ->(answer) { answer }
|
|
26
|
+
|
|
27
|
+
# A block method's value from its block's last answer; nil
|
|
28
|
+
# when the path cannot tell.
|
|
25
29
|
VALUES = {
|
|
26
|
-
'any?' =>
|
|
27
|
-
'
|
|
28
|
-
'none?' => ->(none, answer) { none || !answer },
|
|
30
|
+
'any?' => LAST, 'all?' => LAST, 'find_index' => LAST,
|
|
31
|
+
'none?' => lambda(&:!),
|
|
29
32
|
'detect' => FOUND,
|
|
30
33
|
'find' => FOUND,
|
|
31
|
-
'find_index' => ->(none, answer) { !none && answer },
|
|
32
34
|
'take_while' => ALWAYS,
|
|
33
35
|
**EVERY_ITEM.to_h { |name| [name, ALWAYS] }
|
|
34
36
|
}.freeze
|
|
35
37
|
|
|
36
38
|
# Whether select's result has items: whether any answer
|
|
37
39
|
# was true.
|
|
38
|
-
KEPT =
|
|
39
|
-
items != ITEMS[0] && answers != ANSWERS[1]
|
|
40
|
-
end
|
|
40
|
+
KEPT = ->(answers) { answers != ANSWERS[1] }
|
|
41
41
|
|
|
42
|
-
# Whether a block method's result has items, from
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
# after 2+ items, which may or may not be its first.
|
|
42
|
+
# Whether a block method's result has items, from its
|
|
43
|
+
# block's answers, eg select keeps an item when any answer
|
|
44
|
+
# was true; nil when its path cannot tell, eg take_while's
|
|
45
|
+
# last answer false, which may or may not be its first.
|
|
47
46
|
HAS_ITEMS = {
|
|
48
47
|
'select' => KEPT, 'filter' => KEPT, 'filter_map' => KEPT,
|
|
49
|
-
'reject' =>
|
|
50
|
-
items != ITEMS[0] && answers != ANSWERS[0]
|
|
51
|
-
end,
|
|
48
|
+
'reject' => ->(answers) { answers != ANSWERS[0] },
|
|
52
49
|
'partition' => ALWAYS,
|
|
53
|
-
'take_while' =>
|
|
54
|
-
next false if items == ITEMS[0]
|
|
55
|
-
next answer if answer
|
|
56
|
-
|
|
57
|
-
items == ITEMS[1] ? false : nil
|
|
58
|
-
end
|
|
50
|
+
'take_while' => ->(answer) { answer || nil }
|
|
59
51
|
}.freeze
|
|
60
52
|
|
|
61
53
|
# Whether decision's result has items on the path that took
|
|
62
54
|
# outcomes; nil when its kind cannot tell, eg for a decision
|
|
63
55
|
# that is no block method's call.
|
|
64
56
|
def self.items?(decision, outcomes)
|
|
65
|
-
|
|
57
|
+
_receiver, body = decision.operands
|
|
66
58
|
rule = HAS_ITEMS[decision.operator]
|
|
67
|
-
rule&.call(outcomes[
|
|
59
|
+
rule&.call(outcomes[body])
|
|
68
60
|
end
|
|
69
61
|
|
|
70
62
|
# The ways node can be evaluated, fixed by its shape, its
|
|
@@ -72,25 +64,25 @@ module PathCoverage
|
|
|
72
64
|
def self.ways(node, _fixed)
|
|
73
65
|
receiver, body = node.operands
|
|
74
66
|
BLOCK_PATHS[node.operator].map do |items, answer|
|
|
75
|
-
value = path_value(node.operator,
|
|
67
|
+
value = path_value(node.operator, answer)
|
|
76
68
|
[{ receiver => items, body => answer }, value]
|
|
77
69
|
end
|
|
78
70
|
end
|
|
79
71
|
|
|
80
|
-
# Its value on a path
|
|
81
|
-
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
def self.path_value(operator,
|
|
85
|
-
VALUES[operator].call(
|
|
72
|
+
# Its value on a path with its block's last answer, eg
|
|
73
|
+
# false for any? with false, and always truthy for select,
|
|
74
|
+
# which gives an array; nil for find with a last answer
|
|
75
|
+
# true, whose value no path can tell.
|
|
76
|
+
def self.path_value(operator, answer)
|
|
77
|
+
VALUES[operator].call(answer)
|
|
86
78
|
end
|
|
87
79
|
|
|
88
|
-
# Its value in each column, from its
|
|
89
|
-
#
|
|
80
|
+
# Its value in each column, from its block's answer there;
|
|
81
|
+
# nil where it was not reached.
|
|
90
82
|
def self.value(operator, operands)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
_receiver, body = operands
|
|
84
|
+
body[:cells].map do |answer|
|
|
85
|
+
answer.nil? ? nil : path_value(operator, answer)
|
|
94
86
|
end
|
|
95
87
|
end
|
|
96
88
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
require 'prism'
|
|
2
|
-
require_relative 'condition'
|
|
3
2
|
require_relative 'decision'
|
|
4
3
|
require_relative 'loop_nodes'
|
|
5
4
|
|
|
@@ -7,41 +6,28 @@ module PathCoverage
|
|
|
7
6
|
# The loops of each method that fork when loops are decisions:
|
|
8
7
|
# 0 items, or 1+ items, its body walked once. Each is one whose
|
|
9
8
|
# passes a pass call put first in its body can show, so a
|
|
10
|
-
# call's trace tells the two apart
|
|
11
|
-
#
|
|
12
|
-
# already.
|
|
9
|
+
# call's trace tells the two apart, a block method's block,
|
|
10
|
+
# eg any?'s, among them.
|
|
13
11
|
module LoopForks
|
|
14
12
|
# { def decision => { loop's name => [its bytes, its body's] } }
|
|
15
|
-
# of each def in source, at path
|
|
16
|
-
|
|
17
|
-
def self.of(source, path, decisions)
|
|
18
|
-
blocks = decision_blocks(decisions)
|
|
13
|
+
# of each def in source, at path.
|
|
14
|
+
def self.of(source, path)
|
|
19
15
|
LoopNodes.defs(Prism.parse(source).value).to_h do |node|
|
|
20
|
-
[Decision.of(path, node), in_def(node, path
|
|
16
|
+
[Decision.of(path, node), in_def(node, path)]
|
|
21
17
|
end
|
|
22
18
|
end
|
|
23
19
|
|
|
24
20
|
# { loop's name => [its bytes, its body's] } of each loop of
|
|
25
|
-
# node, a def, at path, that forks
|
|
26
|
-
|
|
27
|
-
def self.in_def(node, path, blocks)
|
|
21
|
+
# node, a def, at path, that forks.
|
|
22
|
+
def self.in_def(node, path)
|
|
28
23
|
loops = LoopNodes.loops_in(node.body)
|
|
29
|
-
loops.filter_map { fork(_1, path
|
|
24
|
+
loops.filter_map { fork(_1, path) }.to_h
|
|
30
25
|
end
|
|
31
26
|
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
def self.
|
|
35
|
-
by = decisions.values.group_by { BLOCK_PATHS.key?(_1.operator) }
|
|
36
|
-
by.fetch(true, []).to_set { _1.extent.end }
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# [name, [its bytes, its body's]] of loop, at path, when it is
|
|
40
|
-
# no block method's, its call not ending at one of blocks, and
|
|
41
|
-
# a pass call can go first in its body; else nil.
|
|
42
|
-
def self.fork(loop, path, blocks)
|
|
27
|
+
# [name, [its bytes, its body's]] of loop, at path, when a
|
|
28
|
+
# pass call can go first in its body; else nil.
|
|
29
|
+
def self.fork(loop, path)
|
|
43
30
|
body = LoopNodes.body_of(loop)
|
|
44
|
-
return if blocks.include?(loop.location.end_offset)
|
|
45
31
|
return if body.nil? || LoopNodes.modifier?(loop)
|
|
46
32
|
return unless LoopNodes.first_statement(body)
|
|
47
33
|
|
|
@@ -23,7 +23,7 @@ module PathCoverage
|
|
|
23
23
|
def self.of(source, path, decisions = nil)
|
|
24
24
|
decisions ||= Manifest.decisions(source, path)
|
|
25
25
|
spots = spots_in(source, path, decisions)
|
|
26
|
-
forks = LoopForks.of(source, path
|
|
26
|
+
forks = LoopForks.of(source, path)
|
|
27
27
|
starts = PathsTree.line_starts(source)
|
|
28
28
|
LoopNodes.defs(Prism.parse(source).value).to_h do |node|
|
|
29
29
|
decision = Decision.of(path, node)
|
|
@@ -28,7 +28,7 @@ module PathCoverage
|
|
|
28
28
|
def self.split(source, path, loops: false)
|
|
29
29
|
decisions = Manifest.decisions(source, path)
|
|
30
30
|
flows = MethodStatements.of(source, path, decisions)
|
|
31
|
-
forks = LoopForks.of(source, path
|
|
31
|
+
forks = LoopForks.of(source, path)
|
|
32
32
|
rescues = RescueForks.of(source, path)
|
|
33
33
|
flows.to_h do |key, rows|
|
|
34
34
|
scopes = [forks.fetch(key), rescues.fetch(key), loops]
|
|
@@ -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
|
|
@@ -151,7 +151,7 @@ module PathCoverage
|
|
|
151
151
|
skipped = possible.each_index.group_by do |i|
|
|
152
152
|
possible[i][index].nil?
|
|
153
153
|
end
|
|
154
|
-
on = skipped.fetch(false)
|
|
154
|
+
on = skipped.fetch(false, [])
|
|
155
155
|
Region.new(owner:, range:, arm: nil, on:, leaf: index,
|
|
156
156
|
leaves: nil)
|
|
157
157
|
end
|
|
@@ -14,8 +14,10 @@ module PathCoverage
|
|
|
14
14
|
include RecorderWrites
|
|
15
15
|
|
|
16
16
|
# One evaluation's way through its decision: the outcome of
|
|
17
|
-
# each leaf, nil for one not yet, or never, reached
|
|
18
|
-
|
|
17
|
+
# each leaf, nil for one not yet, or never, reached; and
|
|
18
|
+
# whether it witnesses no path, as when a block method's
|
|
19
|
+
# block was never called.
|
|
20
|
+
Trail = Struct.new(:decision, :outcomes, :unwitnessed)
|
|
19
21
|
|
|
20
22
|
# Starts with no outcomes, decision paths or reaches counted.
|
|
21
23
|
def initialize
|
|
@@ -92,12 +94,13 @@ module PathCoverage
|
|
|
92
94
|
# decision still entered above trail, as one that raised
|
|
93
95
|
# leaves, took trail's later outcomes, so trail's path is
|
|
94
96
|
# not counted; the stack is cleared down to trail either
|
|
95
|
-
# way.
|
|
97
|
+
# way. An unwitnessed trail's path is not counted either.
|
|
98
|
+
# A counted path is a step of its call's way.
|
|
96
99
|
def leave(trail, value)
|
|
97
100
|
stack = trails(trail.decision)
|
|
98
101
|
clean = stack.last.equal?(trail)
|
|
99
102
|
nil until stack.empty? || stack.pop.equal?(trail)
|
|
100
|
-
decided(trail) if clean
|
|
103
|
+
decided(trail) if clean && !trail.unwitnessed
|
|
101
104
|
value
|
|
102
105
|
end
|
|
103
106
|
|
|
@@ -2,28 +2,24 @@ require_relative 'condition'
|
|
|
2
2
|
|
|
3
3
|
module PathCoverage
|
|
4
4
|
# The part of the recorder that notes block method calls, eg
|
|
5
|
-
# ids.any? { |id| id.odd? }:
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
5
|
+
# ids.any? { |id| id.odd? }: its block's answers, as the leaf
|
|
6
|
+
# after the receiver's, at; at is 0 for a call that is a decision
|
|
7
|
+
# of its own. The receiver's leaf stays nil, as how many items
|
|
8
|
+
# the block was called with is a loop's question. It relies on
|
|
9
|
+
# its includer's counts, record and trails.
|
|
9
10
|
module RecorderBlocks
|
|
10
11
|
# Starts a block method's call in decision, its receiver the
|
|
11
|
-
# decision's at-th leaf
|
|
12
|
-
#
|
|
13
|
-
def begin_items(decision,
|
|
14
|
-
|
|
15
|
-
trail.outcomes[at] = ITEMS[0] if trail
|
|
16
|
-
trail
|
|
12
|
+
# decision's at-th leaf; returns the decision's current trail,
|
|
13
|
+
# nil for none.
|
|
14
|
+
def begin_items(decision, _at)
|
|
15
|
+
trails(decision).last
|
|
17
16
|
end
|
|
18
17
|
|
|
19
|
-
# Notes value, the block's answer, as its last,
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
# counted but noted on no path.
|
|
18
|
+
# Notes value, the block's answer, as its last, for a call
|
|
19
|
+
# whose receiver is decision's at-th leaf; returns value
|
|
20
|
+
# unchanged. A block called where its call was not entered,
|
|
21
|
+
# eg in another fiber, is counted but noted on no path.
|
|
24
22
|
def item_at(decision, at, value)
|
|
25
|
-
trail = trails(decision).last
|
|
26
|
-
one_more(trail, at) if trail
|
|
27
23
|
record(decision, at + 1, value)
|
|
28
24
|
end
|
|
29
25
|
|
|
@@ -39,28 +35,23 @@ module PathCoverage
|
|
|
39
35
|
value
|
|
40
36
|
end
|
|
41
37
|
|
|
42
|
-
# Notes on trail
|
|
43
|
-
#
|
|
38
|
+
# Notes on trail value among the answers so far of the block
|
|
39
|
+
# whose receiver is its at-th leaf.
|
|
44
40
|
def note_answer(trail, at, value)
|
|
45
|
-
one_more(trail, at)
|
|
46
41
|
now = value ? ANSWERS[0] : ANSWERS[1]
|
|
47
42
|
same = [nil, now].include?(trail.outcomes[at + 1])
|
|
48
43
|
trail.outcomes[at + 1] = same ? now : ANSWERS[2]
|
|
49
44
|
end
|
|
50
45
|
|
|
51
|
-
# Notes on trail one more item the block whose receiver is its
|
|
52
|
-
# at-th leaf was called with.
|
|
53
|
-
def one_more(trail, at)
|
|
54
|
-
called = ITEMS.index(trail.outcomes[at]) + 1
|
|
55
|
-
trail.outcomes[at] = ITEMS[[called, 2].min]
|
|
56
|
-
end
|
|
57
|
-
|
|
58
46
|
# Ends a block method's call whose receiver is decision's at-th
|
|
59
47
|
# leaf, counting the receiver truthy when its block was
|
|
60
|
-
# called, falsy when not; returns
|
|
61
|
-
#
|
|
48
|
+
# called, as its answer leaf shows, falsy when not; returns
|
|
49
|
+
# value unchanged. A call whose block was never called
|
|
50
|
+
# leaves trail unwitnessed. With no trail, as begin_items
|
|
51
|
+
# found none, it is counted as called.
|
|
62
52
|
def end_items(decision, at, trail, value)
|
|
63
|
-
called = trail.nil? || trail.outcomes[at
|
|
53
|
+
called = trail.nil? || !trail.outcomes[at + 1].nil?
|
|
54
|
+
trail.unwitnessed = true unless called
|
|
64
55
|
@counts[[decision, at]][called ? :truthy : :falsy] += 1
|
|
65
56
|
value
|
|
66
57
|
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
|
|