path_coverage 0.7.2 → 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 +24 -6
- data/lib/path_coverage/current_test.rb +28 -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 +5 -3
- data/lib/path_coverage/manifest.rb +57 -33
- 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 +5 -4
- 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 +18 -5
- 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 +11 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 397df01f01a7932912565d351f5418a454c80788bc566e0749208c49e86894ef
|
|
4
|
+
data.tar.gz: f2104387941d43d1b7b8bb2a55357cc35875bd3c5169738c42eb74231fcd579f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 700ce1c5d9e49d12fbc7030c0212ab76fbe65163ffd2fde0cdf63847da5287338e4a819aeb71d1d38b211d161d60bf601eda20a57f3342fc78b5fea43245917a
|
|
7
|
+
data.tar.gz: 8e8ae6a4235efef6de0920a2928cf55cdf8abf3320f0c2f5d152cd07239731bb76f34f3d07bc39fe63fa66a5249086b2f6ba7ef9f0f0b709f3c585a0ad5ec8c9
|
data/README.md
CHANGED
|
@@ -67,8 +67,21 @@ PathCoverage.start do
|
|
|
67
67
|
loops # count each loop as a decision: 0 items
|
|
68
68
|
# or 1+ items (off by default)
|
|
69
69
|
end
|
|
70
|
+
require 'path_coverage/minitest' # tally each count by the Minitest test
|
|
71
|
+
# that made it
|
|
70
72
|
```
|
|
71
73
|
|
|
74
|
+
Every count in `path_coverage.json` is a tally by test, so it tells which
|
|
75
|
+
tests take which paths. `require 'path_coverage/minitest'` marks each
|
|
76
|
+
Minitest test under way, named by its class and name, eg
|
|
77
|
+
`KataTest#test_ok`. Another framework names its test with
|
|
78
|
+
`PathCoverage.testing(id)` as it starts, eg in an RSpec `around` hook, and
|
|
79
|
+
`PathCoverage.testing(PathCoverage::Tally::NO_TEST)` as it ends. Code run
|
|
80
|
+
under no test, eg a file's load, counts under `(no test)`. The test under
|
|
81
|
+
way is kept per thread, so tests run in parallel threads, eg with
|
|
82
|
+
`parallelize_me!`, count apart, and a thread a test starts counts under
|
|
83
|
+
that test.
|
|
84
|
+
|
|
72
85
|
## Ignoring and treating
|
|
73
86
|
|
|
74
87
|
`ignore '&&=', '||='` stops `&&=` and `||=` writes being measured.
|
|
@@ -247,7 +260,8 @@ As the process exits:
|
|
|
247
260
|
it alone: `PathCoverage::Render.from_json(config)`, where `config` is a
|
|
248
261
|
`PathCoverage::Configuration` built from the same settings block.
|
|
249
262
|
Given several runs' reports, `Render.from_json(config, paths)` adds
|
|
250
|
-
their
|
|
263
|
+
their tallies together first, test by test, so the report shows only
|
|
264
|
+
the gaps that
|
|
251
265
|
every run left. A report whose kinds, `ignored` or `treats` differ
|
|
252
266
|
from `config`'s is refused, as its decisions list their paths
|
|
253
267
|
differently.
|
|
@@ -272,7 +286,7 @@ order; a leaf that short-circuiting skipped is not on it. Each leaf is
|
|
|
272
286
|
quoted as a Markdown code span, on one line, its fence one backtick longer
|
|
273
287
|
than any run of backticks inside it. The gap lines are for people; a tool
|
|
274
288
|
should read the JSON, whose `paths` give each decision's leaves as
|
|
275
|
-
`line:column` spans, and each possible path with
|
|
289
|
+
`line:column` spans, and each possible path with the tests that took it.
|
|
276
290
|
|
|
277
291
|
A decision is an outermost condition. Its leaves are numbered left to right
|
|
278
292
|
across the whole of it, nested conditions included. A condition inside a
|
|
@@ -293,11 +307,13 @@ is false. It is named at its keyword, and its extent is its keyword to
|
|
|
293
307
|
the end of its predicate, so a decision inside an arm keeps its own button.
|
|
294
308
|
An `elsif` is a decision of its own.
|
|
295
309
|
|
|
296
|
-
A `case`
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
310
|
+
A `case` is a decision whose leaves are its `when` patterns, tried in
|
|
311
|
+
order until one matches: matched against its subject, or, with no
|
|
312
|
+
subject, tested for truth. A splat, eg `when *sizes`, is one leaf, which
|
|
313
|
+
matches when any of its items does. Ruby itself matches every pattern, in
|
|
314
|
+
the method's own frame, so a Regexp pattern sets `$~` and a private `===`
|
|
315
|
+
is called, as without coverage. The instrumentation notes only which
|
|
316
|
+
pattern each try reached and which arm the `case` took.
|
|
301
317
|
|
|
302
318
|
A call to `any?` `all?` `none?` `find` `detect` `find_index`
|
|
303
319
|
`take_while` `select` `filter` `reject` `partition` `count` or
|
|
@@ -366,7 +382,7 @@ with a row for each statement that shapes its paths: each decision, each
|
|
|
366
382
|
`x = 1`, runs exactly when what holds it does, so is no row. A decision's
|
|
367
383
|
row counts its paths; a `return` or `raise` row is one path, taken
|
|
368
384
|
when it is reached. A method's total adds up its rows. Its `calls`
|
|
369
|
-
|
|
385
|
+
tally the tests that called it, so a method never called is a gap,
|
|
370
386
|
even one with no rows. A file's code outside any method gets a flow
|
|
371
387
|
of its own.
|
|
372
388
|
|
|
@@ -467,13 +483,23 @@ decided there, so an arm that returns or raises still counts it.
|
|
|
467
483
|
Each statement that is no decision gets a reach call before it, counting
|
|
468
484
|
its run, for its flow's row.
|
|
469
485
|
|
|
470
|
-
A
|
|
471
|
-
|
|
472
|
-
whole `and` or `or` inside its leave
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
486
|
+
A leaf that is not valid as a bare argument, eg the command call `ok? id`,
|
|
487
|
+
`not ok`, or `x in [1, 2]`, gets parentheses of its own, Prism deciding
|
|
488
|
+
which leaves need them, and so does a whole `and` or `or` inside its leave
|
|
489
|
+
call. A flip-flop, eg `(i == 3)..(i == 5)`, is one only in a condition,
|
|
490
|
+
so its leaf is passed as a ternary's predicate, `((leaf) ? true : false)`,
|
|
491
|
+
and keeps its state. Nothing else gets parentheses: they make a statement,
|
|
492
|
+
and a statement on a continuation line gives that line a line-coverage
|
|
493
|
+
count of its own, which changes SimpleCov's line totals. So such a leaf
|
|
494
|
+
written over several lines can add to SimpleCov's relevant lines; nothing
|
|
495
|
+
else does.
|
|
496
|
+
|
|
497
|
+
Code that never runs is never instrumented: the operand of `defined?` is
|
|
498
|
+
no decision and gets no call, so `defined?(x ||= 1)` still answers
|
|
499
|
+
`"assignment"`. A covered file is read in its own source encoding, its
|
|
500
|
+
magic comment's or UTF-8, and its text reaches the reports as UTF-8. A
|
|
501
|
+
covered file that does not parse is left for Ruby to load, raising its own
|
|
502
|
+
`SyntaxError`.
|
|
477
503
|
|
|
478
504
|
`record` counts whether its value was truthy or falsy, and notes it on the
|
|
479
505
|
decision's current path; `enter` starts that path, and `leave` counts it.
|
|
@@ -490,8 +516,8 @@ the run never loaded are read and parsed then.
|
|
|
490
516
|
## Roadmap
|
|
491
517
|
|
|
492
518
|
Decisions covered now: `&&`, `||`, `and`, `or`, the ternary `?:`,
|
|
493
|
-
`if`/`elsif`/`else` and `unless` (modifiers included), `case`/`when
|
|
494
|
-
|
|
519
|
+
`if`/`elsif`/`else` and `unless` (modifiers included), `case`/`when`,
|
|
520
|
+
and the block methods `any?` `all?` `none?` `find`
|
|
495
521
|
`detect` `find_index` `take_while` `select` `filter` `reject`
|
|
496
522
|
`partition` `count` `filter_map`, the writes `||=` and `&&=`, and `&.`
|
|
497
523
|
safe-navigation chains. Method paths cover every decision in a method,
|
|
@@ -504,7 +530,7 @@ Next:
|
|
|
504
530
|
with blocks of more than one expression
|
|
505
531
|
- `fetch(k, default)`, `dig`, `Hash#[]` with a default: present vs default
|
|
506
532
|
- `x || default` in value context: nil vs not nil
|
|
507
|
-
- `case
|
|
533
|
+
- `case`/`in` patterns
|
|
508
534
|
- regex matches: nil vs MatchData
|
|
509
535
|
- `treat 'methods_of', as: :truthy`, so each call to it counts as a
|
|
510
536
|
leaf that is only truthy, as `Foo.new` is, and a run where it returns
|
|
@@ -566,7 +592,7 @@ test:
|
|
|
566
592
|
Paths alone: 65 / 84 (77.38%)
|
|
567
593
|
Paths combined: 3 / 3 (100.00%)
|
|
568
594
|
SimpleCov report: .../reports/index.html
|
|
569
|
-
PathCov report: .../reports/paths/
|
|
595
|
+
PathCov report: .../reports/paths/path_coverage.json
|
|
570
596
|
coverage: ALLOWED
|
|
571
597
|
```
|
|
572
598
|
|
|
@@ -16,7 +16,7 @@ module PathCoverage
|
|
|
16
16
|
@depths_key = :"path_coverage_depths_#{object_id}"
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
# { unit's name => { way =>
|
|
19
|
+
# { unit's name => { way => Tally } } of every way ended so
|
|
20
20
|
# far, as Walk counts them.
|
|
21
21
|
attr_reader :ways
|
|
22
22
|
|
data/lib/path_coverage/calls.rb
CHANGED
|
@@ -21,16 +21,43 @@ module PathCoverage
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
# The call rewritten code makes around a case's pattern, the
|
|
24
|
-
# index-th of
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
# index-th leaf of decision, noting it reached; returns pattern
|
|
25
|
+
# unchanged, for the case to match or test as written.
|
|
26
|
+
def self.tried(decision, index, pattern)
|
|
27
|
+
@recorder.tried(decision, index, pattern)
|
|
27
28
|
end
|
|
28
29
|
|
|
29
|
-
# The call rewritten code makes
|
|
30
|
-
#
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
# The call rewritten code makes first in a when arm of a case
|
|
31
|
+
# that is decision, noting its pattern matched and deciding it.
|
|
32
|
+
def self.took(decision)
|
|
33
|
+
@recorder.took(decision)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# The call rewritten code splats after the last pattern of a case
|
|
37
|
+
# that is decision, noting no pattern matched and deciding it;
|
|
38
|
+
# returns no patterns.
|
|
39
|
+
def self.missed(decision)
|
|
40
|
+
@recorder.missed(decision)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# The call rewritten code makes first in a when arm of a case in
|
|
44
|
+
# decision's leaf, noting its pattern matched.
|
|
45
|
+
def self.took_within(decision)
|
|
46
|
+
@recorder.took_within(decision)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# The call rewritten code splats after the last pattern of a case
|
|
50
|
+
# in decision's leaf, noting no pattern matched; returns no
|
|
51
|
+
# patterns.
|
|
52
|
+
def self.missed_within(decision)
|
|
53
|
+
@recorder.missed_within(decision)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# The call rewritten code makes around a case in decision, noting
|
|
57
|
+
# a when arm with no statements matched; returns value, the
|
|
58
|
+
# case's, unchanged.
|
|
59
|
+
def self.settled(decision, value)
|
|
60
|
+
@recorder.settled(decision, value)
|
|
34
61
|
end
|
|
35
62
|
|
|
36
63
|
# The call rewritten code makes around the right side of a
|
|
@@ -2,6 +2,12 @@ module PathCoverage
|
|
|
2
2
|
# The operators whose predicate picks an arm.
|
|
3
3
|
CHOICES = %w[?: if unless].freeze
|
|
4
4
|
|
|
5
|
+
# The operator of a when in a case with no subject: its patterns
|
|
6
|
+
# are tested for truth, as an ||'s operands are, where a when's
|
|
7
|
+
# in a case with a subject are matched against it. Its label is
|
|
8
|
+
# when, as it is written.
|
|
9
|
+
TRUTHY_WHEN = 'when truthy'.freeze
|
|
10
|
+
|
|
5
11
|
# The operator of a safe-navigation chain, eg user&.account.
|
|
6
12
|
SAFE = '&.'.freeze
|
|
7
13
|
|
|
@@ -77,13 +83,17 @@ module PathCoverage
|
|
|
77
83
|
# The members a Condition need not be given: no command-call
|
|
78
84
|
# or fixed leaves, no extent and no site.
|
|
79
85
|
CONDITION_OPTIONAL = {
|
|
80
|
-
commands: [].freeze,
|
|
86
|
+
commands: [].freeze, flip_flops: [].freeze, fixed: {}.freeze,
|
|
87
|
+
extent: nil, site: nil
|
|
81
88
|
}.freeze
|
|
82
89
|
|
|
83
90
|
# One decision's condition as the manifest found it: its operator
|
|
84
91
|
# and its operands, each the byte range of a leaf or a nested
|
|
85
92
|
# Condition. A decision's commands are the byte ranges of its
|
|
86
|
-
# leaves that are command calls, eg `ok? id`; its
|
|
93
|
+
# leaves that are command calls, eg `ok? id`; its flip_flops are
|
|
94
|
+
# the byte ranges of its leaves that are flip-flops, eg
|
|
95
|
+
# (i == 3)..(i == 5), which only a condition makes one, each
|
|
96
|
+
# through any parentheses, ! or not around it; its fixed are
|
|
87
97
|
# { byte range => :truthy } for leaves that can have that one
|
|
88
98
|
# outcome only, eg `Clock.new`. Its extent is the byte range
|
|
89
99
|
# of the whole condition as written, eg a ternary's from its
|
|
@@ -92,14 +102,22 @@ module PathCoverage
|
|
|
92
102
|
# decision of, the same in every parse of the same source, so
|
|
93
103
|
# that node, and no other starting where it does, is known as
|
|
94
104
|
# the decision; nil for a Condition that is no decision of its
|
|
95
|
-
# own, eg one nested in another's leaf, which no node is.
|
|
105
|
+
# own, eg one nested in another's leaf, which no node is. Its
|
|
106
|
+
# whole is the byte range of its node from start to end: its
|
|
107
|
+
# extent, but for a case, whose extent ends at its subject while
|
|
108
|
+
# its arms run on to its end, so that what wraps the case as a
|
|
109
|
+
# whole can.
|
|
96
110
|
Condition = Data.define(
|
|
97
|
-
:operator, :operands, :commands, :fixed, :extent,
|
|
111
|
+
:operator, :operands, :commands, :flip_flops, :fixed, :extent,
|
|
112
|
+
:whole, :site
|
|
98
113
|
) do
|
|
99
114
|
# A condition of operator and operands, each member of
|
|
100
|
-
# CONDITION_OPTIONAL given, or else its default
|
|
115
|
+
# CONDITION_OPTIONAL given, or else its default; whole, when
|
|
116
|
+
# not given, its extent.
|
|
101
117
|
def initialize(operator:, operands:, **given)
|
|
102
|
-
|
|
118
|
+
members = CONDITION_OPTIONAL.merge(given)
|
|
119
|
+
whole = members.fetch(:whole) { members[:extent] }
|
|
120
|
+
super(operator:, operands:, **members.except(:whole), whole:)
|
|
103
121
|
end
|
|
104
122
|
|
|
105
123
|
# The byte range of every leaf operand, left to right, a
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require_relative 'tally'
|
|
2
|
+
|
|
3
|
+
module PathCoverage
|
|
4
|
+
# The test whose run is under way, under which every count is
|
|
5
|
+
# tallied. It is kept in Fiber storage, which each thread has its
|
|
6
|
+
# own of and which every thread or fiber it starts inherits: so
|
|
7
|
+
# tests run in parallel threads count apart, and work a test
|
|
8
|
+
# starts counts under that test. Code run under no test, eg a
|
|
9
|
+
# file's load, counts under Tally::NO_TEST.
|
|
10
|
+
module CurrentTest
|
|
11
|
+
# The Fiber storage key, named for this module, so a copy of
|
|
12
|
+
# the gem under another name keeps a test of its own.
|
|
13
|
+
KEY = :"#{name}"
|
|
14
|
+
|
|
15
|
+
# The id of the test under way in this thread, or
|
|
16
|
+
# Tally::NO_TEST when there is none.
|
|
17
|
+
def self.id
|
|
18
|
+
marked = Fiber[KEY]
|
|
19
|
+
marked.nil? ? Tally::NO_TEST : marked
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Makes test, a test's id, or Tally::NO_TEST as a test ends, the
|
|
23
|
+
# test under way in this thread and those it starts from now on.
|
|
24
|
+
def self.testing(test)
|
|
25
|
+
Fiber[KEY] = test
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -2,28 +2,18 @@ require_relative 'condition'
|
|
|
2
2
|
require_relative 'kinds'
|
|
3
3
|
|
|
4
4
|
module PathCoverage
|
|
5
|
-
#
|
|
6
|
-
#
|
|
5
|
+
# A decision's tree: a grid whose columns are paths, as its fold
|
|
6
|
+
# in the source report shows it.
|
|
7
7
|
module DecisionTree
|
|
8
|
-
# { operator:,
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
def self.of(source, condition, paths)
|
|
18
|
-
columns = paths.sort_by.with_index do |taken, i|
|
|
19
|
-
[taken[:count].zero? ? 0 : 1, i]
|
|
20
|
-
end
|
|
21
|
-
tree = built(source, condition, columns.map { _1[:path] })
|
|
22
|
-
tree.merge(counts: columns.map { |taken| taken[:count] })
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# The tree of condition with no counts, a column for each of
|
|
26
|
-
# outcomes, each path's outcomes, in the order given.
|
|
8
|
+
# { operator:, cells:, operands: } for condition, a column for
|
|
9
|
+
# each of outcomes, each path's outcomes, in the order given.
|
|
10
|
+
# Every node has cells, one per column: a leaf { text:, cells: }
|
|
11
|
+
# its outcome, nil where unreached; a condition { operator:,
|
|
12
|
+
# cells:, operands: } its value; an arm { arm:, text:, cells:,
|
|
13
|
+
# body: } whether the column took it, body being its
|
|
14
|
+
# condition's tree, nil for a plain arm. Texts are cut from
|
|
15
|
+
# source at the manifest's ranges. An elsif's tree is labelled
|
|
16
|
+
# elsif, as it is written.
|
|
27
17
|
def self.built(source, condition, outcomes)
|
|
28
18
|
tree = node(source, condition, outcomes, (0..).each)
|
|
29
19
|
return tree unless elsif?(source, condition)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module PathCoverage
|
|
2
|
+
# The code Ruby can run, as every walk of a covered file sees it.
|
|
3
|
+
# The operand of a defined? never runs: defined? only asks what
|
|
4
|
+
# it would be. So nothing in it is a decision, a row, a loop, a
|
|
5
|
+
# rescue or a method, and nothing is ever inserted in it, which
|
|
6
|
+
# would change what defined? answers.
|
|
7
|
+
module Evaluated
|
|
8
|
+
# The nodes whose children never run.
|
|
9
|
+
ASKING = %i[defined_node].freeze
|
|
10
|
+
|
|
11
|
+
# node's children that can run: none of a defined?'s.
|
|
12
|
+
def self.children(node)
|
|
13
|
+
ASKING.include?(node.type) ? [] : node.compact_child_nodes
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# The part of a Prism visitor that visits only code that can
|
|
17
|
+
# run, so it never descends into a defined?'s operand.
|
|
18
|
+
module Visitor
|
|
19
|
+
# Visits nothing in node, a defined?, whose operand never runs.
|
|
20
|
+
def visit_defined_node(_node) = nil
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -5,20 +5,19 @@ require_relative 'fold_cells'
|
|
|
5
5
|
require_relative 'kinds'
|
|
6
6
|
|
|
7
7
|
module PathCoverage
|
|
8
|
-
# The tree of a decision, from DecisionTree.
|
|
9
|
-
# fold in
|
|
10
|
-
# decision's paths,
|
|
11
|
-
#
|
|
8
|
+
# The tree of a decision, from DecisionTree.built, as its row's
|
|
9
|
+
# fold in the source report holds it: a grid whose columns are
|
|
10
|
+
# the decision's paths, each row a kind, a branch, a label, where
|
|
11
|
+
# its code is and a cell per path.
|
|
12
12
|
module FoldRows
|
|
13
13
|
# The rows of decision's fold, as page data holds them:
|
|
14
|
-
# decision's own row, naming its operator and
|
|
15
|
-
#
|
|
16
|
-
# the rows of its operands.
|
|
14
|
+
# decision's own row, naming its operator, and where its else
|
|
15
|
+
# keyword is, if it has one; then the rows of its operands.
|
|
17
16
|
def self.rows(decision)
|
|
18
17
|
text = decision.fetch(:label) { decision[:operator] }
|
|
19
18
|
label = CodeTokens.label_code(text)
|
|
20
19
|
own = { kind: 'decision', branch: '', label:, at: decision[:at],
|
|
21
|
-
else: decision[:else_at]
|
|
20
|
+
else: decision[:else_at] }
|
|
22
21
|
[own, *operand_rows(decision, '')]
|
|
23
22
|
end
|
|
24
23
|
|
data/lib/path_coverage/gaps.rb
CHANGED
|
@@ -59,7 +59,7 @@ module PathCoverage
|
|
|
59
59
|
# texts being each leaf's source text.
|
|
60
60
|
def self.path_gaps(decision, paths, texts)
|
|
61
61
|
paths.each_with_object([]) do |each, lines|
|
|
62
|
-
next unless each[:
|
|
62
|
+
next unless each[:tests].empty?
|
|
63
63
|
|
|
64
64
|
named = steps(each[:path], texts)
|
|
65
65
|
lines << "#{decision} path never taken: #{named}"
|
|
@@ -83,15 +83,15 @@ module PathCoverage
|
|
|
83
83
|
def self.operand_gap(counts)
|
|
84
84
|
return ['never evaluated'] if never_ran?(counts)
|
|
85
85
|
return [] if counts[:only]
|
|
86
|
-
return ['never true'] if counts[:truthy].
|
|
87
|
-
return ['never false'] if counts[:falsy].
|
|
86
|
+
return ['never true'] if counts[:truthy].empty?
|
|
87
|
+
return ['never false'] if counts[:falsy].empty?
|
|
88
88
|
|
|
89
89
|
[]
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
# True when the operand was never recorded either way.
|
|
93
93
|
def self.never_ran?(counts)
|
|
94
|
-
counts[:truthy].
|
|
94
|
+
counts[:truthy].empty? && counts[:falsy].empty?
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
97
|
end
|
|
@@ -2,16 +2,22 @@ require 'json'
|
|
|
2
2
|
require_relative 'kinds'
|
|
3
3
|
require_relative 'measured_by'
|
|
4
4
|
require_relative 'merge'
|
|
5
|
+
require_relative 'report_tallies'
|
|
5
6
|
require_relative 'ways_report'
|
|
6
7
|
|
|
7
8
|
module PathCoverage
|
|
8
9
|
# Reads back the JSON reports JsonWriter writes, merging the
|
|
9
|
-
#
|
|
10
|
+
# Tallies of several runs, and refusing any report whose
|
|
10
11
|
# decisions' paths are listed differently from a render's.
|
|
11
12
|
module JsonReader
|
|
12
13
|
# The keys of a JSON report's fingerprint.
|
|
13
14
|
FINGERPRINT = %w[ignored treats].freeze
|
|
14
15
|
|
|
16
|
+
# The JSON report at path, each tally in it a Tally.
|
|
17
|
+
def self.load(path)
|
|
18
|
+
ReportTallies.restored(JSON.parse(File.read(path)))
|
|
19
|
+
end
|
|
20
|
+
|
|
15
21
|
# The operands of the JSON reports at paths, merged; raises
|
|
16
22
|
# unless each measured the kinds a render does, with
|
|
17
23
|
# fingerprint, as Configuration#fingerprint gives it.
|
|
@@ -34,12 +40,12 @@ module PathCoverage
|
|
|
34
40
|
end
|
|
35
41
|
|
|
36
42
|
# The ways of the JSON reports at paths, as WaysReport.ways
|
|
37
|
-
# reads them, each unit's way's
|
|
43
|
+
# reads them, each unit's way's Tallies summed; nil when none
|
|
38
44
|
# lists any, eg reports the :post reporter sent, so a render
|
|
39
45
|
# cannot say which ways were taken.
|
|
40
46
|
def self.ways(paths)
|
|
41
47
|
runs = paths.map do |path|
|
|
42
|
-
report =
|
|
48
|
+
report = load(path)
|
|
43
49
|
listed_ways?(report) ? WaysReport.ways(report) : nil
|
|
44
50
|
end.compact
|
|
45
51
|
return nil if runs.empty?
|
|
@@ -58,13 +64,13 @@ module PathCoverage
|
|
|
58
64
|
report.key?('max_paths')
|
|
59
65
|
end
|
|
60
66
|
|
|
61
|
-
# Example: { "k.rb:2:2" => 2 } and { "k.rb:2:2"
|
|
62
|
-
# { "k.rb:2:2" => 3 }.
|
|
67
|
+
# Example: { "k.rb:2:2" => Tally(a test: 2) } and { "k.rb:2:2"
|
|
68
|
+
# => Tally(a test: 1) } give { "k.rb:2:2" => Tally(a test: 3) }.
|
|
63
69
|
# The reaches of the JSON reports at paths, each statement's
|
|
64
70
|
# summed; nil when none has any, eg reports the :post reporter
|
|
65
71
|
# sent, so a render cannot say what was reached.
|
|
66
72
|
def self.reached(paths)
|
|
67
|
-
reports = paths.map { |path|
|
|
73
|
+
reports = paths.map { |path| load(path) }
|
|
68
74
|
runs = reports.map { |report| report['reached'] }.compact
|
|
69
75
|
return nil if runs.empty?
|
|
70
76
|
|
|
@@ -88,28 +94,26 @@ module PathCoverage
|
|
|
88
94
|
end
|
|
89
95
|
|
|
90
96
|
# The key lists of the JSON reports at paths, as listed_of
|
|
91
|
-
# gives them, each path's
|
|
97
|
+
# gives them, each path's Tally the sum of every report's.
|
|
92
98
|
def self.merged(paths, key)
|
|
93
99
|
Merge.listed(paths.map { |path| listed_of(path, key) })
|
|
94
100
|
end
|
|
95
101
|
|
|
96
102
|
# The JSON report at path's list under key, eg its paths a
|
|
97
|
-
# treatment rules out, { decision => { path =>
|
|
103
|
+
# treatment rules out, { decision => { path => Tally } }; none
|
|
98
104
|
# for a report that has none, so the render claims none.
|
|
99
105
|
def self.listed_of(path, key)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
taken.to_h { |each| [each['path'], each['count']] }
|
|
106
|
+
load(path).fetch(key, {}).transform_values do |taken|
|
|
107
|
+
taken.to_h { |each| [each['path'], each['tests']] }
|
|
103
108
|
end
|
|
104
109
|
end
|
|
105
110
|
|
|
106
111
|
# The decision paths of the JSON report at path, as
|
|
107
112
|
# Result#paths gives them; none for a report that has none.
|
|
108
113
|
def self.paths_of(path)
|
|
109
|
-
|
|
110
|
-
json.fetch('paths', {}).transform_values do |decision|
|
|
114
|
+
load(path).fetch('paths', {}).transform_values do |decision|
|
|
111
115
|
decision['taken'].map do |each|
|
|
112
|
-
{ path: each['path'],
|
|
116
|
+
{ path: each['path'], tests: each['tests'] }
|
|
113
117
|
end
|
|
114
118
|
end
|
|
115
119
|
end
|
|
@@ -118,15 +122,16 @@ module PathCoverage
|
|
|
118
122
|
# unless it measured the kinds a render does, with
|
|
119
123
|
# fingerprint.
|
|
120
124
|
def self.read(path, fingerprint)
|
|
121
|
-
json =
|
|
125
|
+
json = load(path)
|
|
122
126
|
same_measuring(path, json, fingerprint)
|
|
123
127
|
json['decisions'].transform_values do |leaves|
|
|
124
128
|
leaves.map { |leaf| counts(leaf) }
|
|
125
129
|
end
|
|
126
130
|
end
|
|
127
131
|
|
|
128
|
-
# One operand's
|
|
129
|
-
# and any only: value, as the symbols Result#operands
|
|
132
|
+
# One operand's Tallies as the report holds them, with the
|
|
133
|
+
# keys, and any only: value, as the symbols Result#operands
|
|
134
|
+
# uses.
|
|
130
135
|
def self.counts(leaf)
|
|
131
136
|
counts = { truthy: leaf['truthy'], falsy: leaf['falsy'] }
|
|
132
137
|
only = leaf['only']
|
|
@@ -4,6 +4,7 @@ require_relative 'paths_gaps'
|
|
|
4
4
|
require_relative 'console_summary'
|
|
5
5
|
require_relative 'json_writer'
|
|
6
6
|
require_relative 'paths_report'
|
|
7
|
+
require_relative 'report_text'
|
|
7
8
|
require_relative 'source_report'
|
|
8
9
|
require_relative 'within_methods'
|
|
9
10
|
|
|
@@ -11,7 +12,7 @@ module PathCoverage
|
|
|
11
12
|
# The two JSON reports every run writes, and every render of
|
|
12
13
|
# runs merged, into coverage_dir: path_coverage.json, the
|
|
13
14
|
# counts, and path_coverage.source.json, what drawing each
|
|
14
|
-
# file's code needs
|
|
15
|
+
# file's code needs.
|
|
15
16
|
module JsonReports
|
|
16
17
|
# What WithinMethods reads of a run: operands, decision paths,
|
|
17
18
|
# and paths a treatment rules out, as Result gives them.
|
|
@@ -61,7 +62,8 @@ module PathCoverage
|
|
|
61
62
|
def self.write_ways(flows, files, config, tree)
|
|
62
63
|
texts = PathsReport.texts(files)
|
|
63
64
|
lines = PathsGaps.lines(flows, texts, parents_of(tree))
|
|
64
|
-
|
|
65
|
+
text = ReportText.utf8(lines).map { "#{_1}\n" }.join
|
|
66
|
+
File.write(ways_path(config), text)
|
|
65
67
|
end
|
|
66
68
|
|
|
67
69
|
# { row's decision => its parent's decision } of each row in
|
|
@@ -89,7 +91,7 @@ module PathCoverage
|
|
|
89
91
|
def self.write_source(files, config, decision_paths, flows)
|
|
90
92
|
source = SourceReport.of(files, config, decision_paths, flows)
|
|
91
93
|
path = config.json_path.sub(/\.json\z/, '.source.json')
|
|
92
|
-
File.write(path, JSON.generate(source))
|
|
94
|
+
File.write(path, JSON.generate(ReportText.utf8(source)))
|
|
93
95
|
end
|
|
94
96
|
|
|
95
97
|
# The JSON report's totals, each [taken, possible] paths:
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
require 'json'
|
|
2
2
|
require_relative 'kinds'
|
|
3
3
|
require_relative 'measured_by'
|
|
4
|
+
require_relative 'report_text'
|
|
5
|
+
require_relative 'tally'
|
|
4
6
|
|
|
5
7
|
module PathCoverage
|
|
6
8
|
# The base reporter: the result as raw JSON, which every
|
|
7
9
|
# other reporter can read back.
|
|
8
10
|
module JsonWriter
|
|
9
11
|
# The URL of the schema the JSON report follows.
|
|
10
|
-
SCHEMA = 'https://path-coverage.github.io/schemas/
|
|
12
|
+
SCHEMA = 'https://path-coverage.github.io/schemas/v3/' \
|
|
11
13
|
'path_coverage.schema.json'.freeze
|
|
12
14
|
|
|
13
15
|
# Writes operands, as Result gives them, paths, as
|
|
@@ -20,7 +22,7 @@ module PathCoverage
|
|
|
20
22
|
File.write(path, json(operands, paths, **parts))
|
|
21
23
|
end
|
|
22
24
|
|
|
23
|
-
# The keys of parts listed as { decision => [{path:,
|
|
25
|
+
# The keys of parts listed as { decision => [{path:, tests:}] }:
|
|
24
26
|
# each path taken that a treatment rules out, as
|
|
25
27
|
# Result#outside gives them.
|
|
26
28
|
LISTED = %i[outside].freeze
|
|
@@ -34,7 +36,9 @@ module PathCoverage
|
|
|
34
36
|
# as Recorder#reached gives it, even empty, as a run that
|
|
35
37
|
# reached no statement says so; none when not given; parts'
|
|
36
38
|
# limits:, { "loops" =>, "max_paths" => } the flows were
|
|
37
|
-
# listed with; headed by its schema's URL.
|
|
39
|
+
# listed with; headed by its schema's URL. Every Tally in it is
|
|
40
|
+
# listed by its tests' keys, and its tests name each key's test,
|
|
41
|
+
# as Tally.jsonable lists them.
|
|
38
42
|
def self.json(operands, paths = {}, **parts)
|
|
39
43
|
fingerprint = parts.fetch(:fingerprint, {})
|
|
40
44
|
report = { '$schema' => SCHEMA, 'decisions' => operands,
|
|
@@ -43,7 +47,7 @@ module PathCoverage
|
|
|
43
47
|
report.merge!(lists(parts), counted(parts), kept(parts))
|
|
44
48
|
report['kinds'] = Kinds.names
|
|
45
49
|
report['measured_by'] = MeasuredBy.versions
|
|
46
|
-
JSON.pretty_generate(report)
|
|
50
|
+
JSON.pretty_generate(ReportText.utf8(Tally.jsonable(report)))
|
|
47
51
|
end
|
|
48
52
|
|
|
49
53
|
# { "reached" =>, "loops" =>, "max_paths" => } of parts'
|
|
@@ -74,11 +78,11 @@ module PathCoverage
|
|
|
74
78
|
end.to_h
|
|
75
79
|
end
|
|
76
80
|
|
|
77
|
-
# taken, { decision => { path =>
|
|
78
|
-
# eg { 'k.rb:2:2' => [{ path: [true, false],
|
|
81
|
+
# taken, { decision => { path => Tally } }, as JSON lists it,
|
|
82
|
+
# eg { 'k.rb:2:2' => [{ path: [true, false], tests: Tally }] }.
|
|
79
83
|
def self.listed(taken)
|
|
80
|
-
taken.transform_values do |
|
|
81
|
-
|
|
84
|
+
taken.transform_values do |tallies|
|
|
85
|
+
tallies.map { |path, tests| { path:, tests: } }
|
|
82
86
|
end
|
|
83
87
|
end
|
|
84
88
|
end
|