path_coverage 0.6.0 → 0.7.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 +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_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 +1 -1
- 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: 72f61105ee75c749617db00548e9d803bcae76919e51cac6b0a081b93eca54b4
|
|
4
|
+
data.tar.gz: deec7238a3260dceecdb937464246a5b0d7b502c73826a6bde0947a611713b22
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e7b265531ef2dc15e67e3554d0cae1292163dd3874333a10546822bdb62dd06ceea24ecb12bfd62dad4d32d16eb2c9b3329eddfd3d26d8d3b73e96077f81a912
|
|
7
|
+
data.tar.gz: d847e2497b63d34f392cd88d6b538fa3b5fc1ab92796a183e4cae55176c1edb43cf499310c31f1b4a0c8d5fbb75705c89f9153f938828c4ca7b2bd2619447357
|
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]
|
|
@@ -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
|
|
@@ -156,7 +156,7 @@ module PathCoverage
|
|
|
156
156
|
@ways = ways
|
|
157
157
|
@limit = limit
|
|
158
158
|
@loops = MethodLoops.of(source, path, decisions)
|
|
159
|
-
@forks = LoopForks.of(source, path
|
|
159
|
+
@forks = LoopForks.of(source, path)
|
|
160
160
|
@rescues = RescueForks.of(source, path)
|
|
161
161
|
@forking = loops
|
|
162
162
|
end
|