path_coverage 0.4.0 → 0.6.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 +260 -300
- data/exe/path_coverage_report +4 -0
- data/lib/path_coverage/call_trace.rb +109 -0
- data/lib/path_coverage/calls.rb +73 -43
- data/lib/path_coverage/{html_syntax.rb → code_tokens.rb} +35 -33
- data/lib/path_coverage/condition.rb +14 -14
- data/lib/path_coverage/configuration.rb +7 -4
- data/lib/path_coverage/configuration_limits.rb +52 -0
- data/lib/path_coverage/configuration_paths.rb +7 -7
- data/lib/path_coverage/console_summary.rb +28 -26
- data/lib/path_coverage/{site.rb → decision.rb} +2 -2
- data/lib/path_coverage/decision_locations.rb +76 -0
- data/lib/path_coverage/{site_paths.rb → decision_paths.rb} +13 -11
- data/lib/path_coverage/{site_tree.rb → decision_tree.rb} +25 -16
- data/lib/path_coverage/fold_branches.rb +18 -0
- data/lib/path_coverage/fold_cells.rb +42 -0
- data/lib/path_coverage/{html_tree.rb → fold_rows.rb} +43 -72
- data/lib/path_coverage/gaps.rb +33 -15
- data/lib/path_coverage/json_reader.rb +54 -19
- data/lib/path_coverage/json_reports.rb +109 -0
- data/lib/path_coverage/json_writer.rb +29 -14
- data/lib/path_coverage/kernel.rb +77 -58
- data/lib/path_coverage/kinds/base.rb +16 -16
- data/lib/path_coverage/kinds/block.rb +16 -15
- data/lib/path_coverage/kinds/case.rb +14 -12
- data/lib/path_coverage/kinds/chain.rb +40 -11
- data/lib/path_coverage/kinds/choice.rb +4 -3
- data/lib/path_coverage/kinds/contains.rb +40 -32
- data/lib/path_coverage/kinds/safe.rb +38 -26
- data/lib/path_coverage/kinds/write.rb +6 -6
- data/lib/path_coverage/kinds.rb +2 -2
- data/lib/path_coverage/leaving.rb +52 -0
- data/lib/path_coverage/loop_forks.rb +57 -0
- data/lib/path_coverage/loop_nodes.rb +91 -0
- data/lib/path_coverage/manifest.rb +92 -58
- data/lib/path_coverage/manifest_blocks.rb +5 -26
- data/lib/path_coverage/manifest_case.rb +2 -2
- data/lib/path_coverage/manifest_chains.rb +8 -8
- data/lib/path_coverage/manifest_choices.rb +23 -20
- data/lib/path_coverage/manifest_disabled.rb +97 -0
- data/lib/path_coverage/manifest_folding.rb +43 -40
- data/lib/path_coverage/manifest_ignoring.rb +6 -6
- data/lib/path_coverage/manifest_writes.rb +11 -10
- data/lib/path_coverage/measured_by.rb +20 -0
- data/lib/path_coverage/merge.rb +7 -7
- data/lib/path_coverage/method_loops.rb +172 -0
- data/lib/path_coverage/method_statements.rb +150 -134
- data/lib/path_coverage/method_ways.rb +170 -0
- data/lib/path_coverage/paths_context.rb +104 -0
- data/lib/path_coverage/paths_fitting.rb +31 -0
- data/lib/path_coverage/paths_forks.rb +72 -0
- data/lib/path_coverage/paths_gaps.rb +137 -0
- data/lib/path_coverage/paths_leaving.rb +40 -0
- data/lib/path_coverage/paths_report.rb +16 -16
- data/lib/path_coverage/paths_rescues.rb +146 -0
- data/lib/path_coverage/paths_scopes.rb +37 -0
- data/lib/path_coverage/paths_tree.rb +203 -0
- data/lib/path_coverage/paths_way_lists.rb +72 -0
- data/lib/path_coverage/paths_ways.rb +193 -0
- data/lib/path_coverage/recorder.rb +71 -36
- data/lib/path_coverage/recorder_blocks.rb +17 -17
- data/lib/path_coverage/recorder_cases.rb +12 -11
- data/lib/path_coverage/recorder_chains.rb +12 -12
- data/lib/path_coverage/recorder_writes.rb +9 -9
- data/lib/path_coverage/render.rb +58 -51
- data/lib/path_coverage/rescue_forks.rb +174 -0
- data/lib/path_coverage/result.rb +32 -31
- data/lib/path_coverage/rewriter.rb +116 -35
- data/lib/path_coverage/rewriter_nested.rb +13 -13
- data/lib/path_coverage/runs_report.rb +84 -0
- data/lib/path_coverage/source_lines.rb +16 -16
- data/lib/path_coverage/source_report.rb +100 -0
- data/lib/path_coverage/stable_leaves.rb +162 -0
- data/lib/path_coverage/statement_arms.rb +53 -38
- data/lib/path_coverage/summary.rb +4 -62
- data/lib/path_coverage/totals.rb +12 -10
- data/lib/path_coverage/version.rb +1 -1
- data/lib/path_coverage/walk.rb +106 -0
- data/lib/path_coverage/way_algebras.rb +127 -0
- data/lib/path_coverage/ways_report.rb +91 -0
- data/lib/path_coverage/ways_totals.rb +46 -0
- data/lib/path_coverage/within_methods.rb +152 -97
- metadata +39 -30
- data/lib/path_coverage/card.rb +0 -14
- data/lib/path_coverage/card_tree.rb +0 -186
- data/lib/path_coverage/card_ways.rb +0 -140
- data/lib/path_coverage/html/file.html +0 -33
- data/lib/path_coverage/html/index.html +0 -29
- data/lib/path_coverage/html/settings.js +0 -50
- data/lib/path_coverage/html/side.js +0 -599
- data/lib/path_coverage/html/sort.js +0 -34
- data/lib/path_coverage/html/style.css +0 -484
- data/lib/path_coverage/html/tabs.js +0 -15
- data/lib/path_coverage/html/theme.js +0 -27
- data/lib/path_coverage/html_branch.rb +0 -30
- data/lib/path_coverage/html_cards.rb +0 -88
- data/lib/path_coverage/html_cells.rb +0 -71
- data/lib/path_coverage/html_file.rb +0 -123
- data/lib/path_coverage/html_index.rb +0 -128
- data/lib/path_coverage/html_index_head.rb +0 -29
- data/lib/path_coverage/html_labels.rb +0 -16
- data/lib/path_coverage/html_methods.rb +0 -66
- data/lib/path_coverage/html_nav.rb +0 -67
- data/lib/path_coverage/html_report.rb +0 -131
- data/lib/path_coverage/html_statements.rb +0 -186
- data/lib/path_coverage/html_tabs.rb +0 -26
- data/lib/path_coverage/html_template.rb +0 -26
|
@@ -4,38 +4,38 @@ module PathCoverage
|
|
|
4
4
|
# The part of the recorder that notes block method calls, eg
|
|
5
5
|
# ids.any? { |id| id.odd? }: how many items the block was called
|
|
6
6
|
# with, as the receiver's leaf, at, and its answers, as the next
|
|
7
|
-
# leaf; at is 0 for a call that is a
|
|
7
|
+
# leaf; at is 0 for a call that is a decision of its own. It relies
|
|
8
8
|
# on its includer's counts, record and trails.
|
|
9
9
|
module RecorderBlocks
|
|
10
|
-
# Starts a block method's call in
|
|
11
|
-
#
|
|
12
|
-
# returns the
|
|
13
|
-
def begin_items(
|
|
14
|
-
trail = trails(
|
|
10
|
+
# Starts a block method's call in decision, its receiver the
|
|
11
|
+
# decision's at-th leaf, its block not yet called with any item;
|
|
12
|
+
# returns the decision's current trail, nil for none.
|
|
13
|
+
def begin_items(decision, at)
|
|
14
|
+
trail = trails(decision).last
|
|
15
15
|
trail.outcomes[at] = ITEMS[0] if trail
|
|
16
16
|
trail
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
# Notes value, the block's answer, as its last, and one more
|
|
20
20
|
# item it was called with, for a call whose receiver is
|
|
21
|
-
#
|
|
21
|
+
# decision's at-th leaf; returns value unchanged. A block called
|
|
22
22
|
# where its call was not entered, eg in another fiber, is
|
|
23
23
|
# counted but noted on no path.
|
|
24
|
-
def item_at(
|
|
25
|
-
trail = trails(
|
|
24
|
+
def item_at(decision, at, value)
|
|
25
|
+
trail = trails(decision).last
|
|
26
26
|
one_more(trail, at) if trail
|
|
27
|
-
record(
|
|
27
|
+
record(decision, at + 1, value)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
# Notes value, the block's answer for one more item, among
|
|
31
31
|
# all its answers so far: all true, all false, or both, for a
|
|
32
|
-
# call whose receiver is
|
|
32
|
+
# call whose receiver is decision's at-th leaf; returns value
|
|
33
33
|
# unchanged. A block called where its call was not entered
|
|
34
34
|
# is counted but noted on no path.
|
|
35
|
-
def answer_at(
|
|
36
|
-
trail = trails(
|
|
35
|
+
def answer_at(decision, at, value)
|
|
36
|
+
trail = trails(decision).last
|
|
37
37
|
note_answer(trail, at, value) if trail
|
|
38
|
-
@counts[[
|
|
38
|
+
@counts[[decision, at + 1]][value ? :truthy : :falsy] += 1
|
|
39
39
|
value
|
|
40
40
|
end
|
|
41
41
|
|
|
@@ -55,13 +55,13 @@ module PathCoverage
|
|
|
55
55
|
trail.outcomes[at] = ITEMS[[called, 2].min]
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
# Ends a block method's call whose receiver is
|
|
58
|
+
# Ends a block method's call whose receiver is decision's at-th
|
|
59
59
|
# leaf, counting the receiver truthy when its block was
|
|
60
60
|
# called, falsy when not; returns value unchanged. With no
|
|
61
61
|
# trail, as begin_items found none, it is counted as called.
|
|
62
|
-
def end_items(
|
|
62
|
+
def end_items(decision, at, trail, value)
|
|
63
63
|
called = trail.nil? || trail.outcomes[at] != ITEMS[0]
|
|
64
|
-
@counts[[
|
|
64
|
+
@counts[[decision, at]][called ? :truthy : :falsy] += 1
|
|
65
65
|
value
|
|
66
66
|
end
|
|
67
67
|
end
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
module PathCoverage
|
|
2
2
|
# The part of the recorder that notes a case nested in another
|
|
3
|
-
#
|
|
4
|
-
# enters and leaves, so its patterns only note
|
|
5
|
-
# matched. It relies on its includer's record.
|
|
3
|
+
# decision, eg (case a when 1 then b end) && c: the decision
|
|
4
|
+
# around it enters and leaves, so its patterns only note
|
|
5
|
+
# whether they matched. It relies on its includer's record.
|
|
6
6
|
module RecorderCases
|
|
7
|
-
# A stand-in for the pattern of a case nested in
|
|
8
|
-
# match noted as the
|
|
9
|
-
NestedMatch = Struct.new(:recorder, :
|
|
7
|
+
# A stand-in for the pattern of a case nested in decision, its
|
|
8
|
+
# match noted as the decision's index-th leaf.
|
|
9
|
+
NestedMatch = Struct.new(:recorder, :decision, :index,
|
|
10
|
+
:pattern) do
|
|
10
11
|
# Whether pattern matches subject, exactly as pattern says,
|
|
11
|
-
# noted on the
|
|
12
|
+
# noted on the decision's path.
|
|
12
13
|
def ===(subject)
|
|
13
|
-
recorder.record(
|
|
14
|
+
recorder.record(decision, index, pattern === subject)
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
|
|
17
|
-
# The stand-in for pattern, the index-th leaf of
|
|
18
|
+
# The stand-in for pattern, the index-th leaf of decision, in a
|
|
18
19
|
# case nested in it.
|
|
19
|
-
def pattern(
|
|
20
|
-
NestedMatch.new(self,
|
|
20
|
+
def pattern(decision, index, pattern)
|
|
21
|
+
NestedMatch.new(self, decision, index, pattern)
|
|
21
22
|
end
|
|
22
23
|
end
|
|
23
24
|
end
|
|
@@ -4,36 +4,36 @@ module PathCoverage
|
|
|
4
4
|
# The part of the recorder that notes &. chains. It relies on
|
|
5
5
|
# its includer's counts, record and trails.
|
|
6
6
|
module RecorderChains
|
|
7
|
-
# Notes value, the index-th leaf of
|
|
7
|
+
# Notes value, the index-th leaf of decision, a &. receiver, as
|
|
8
8
|
# not nil or nil, and returns it unchanged; it counts truthy
|
|
9
9
|
# when not nil. A receiver after a nil one in its chain,
|
|
10
10
|
# whose leaves start at first, was never reached, as Ruby
|
|
11
11
|
# skips the rest of the chain, so is not noted.
|
|
12
|
-
def present(
|
|
13
|
-
return value unless reached?(
|
|
12
|
+
def present(decision, index, first, value)
|
|
13
|
+
return value unless reached?(decision, first, index)
|
|
14
14
|
|
|
15
|
-
@counts[[
|
|
16
|
-
trail = trails(
|
|
15
|
+
@counts[[decision, index]][value.nil? ? :falsy : :truthy] += 1
|
|
16
|
+
trail = trails(decision).last
|
|
17
17
|
trail.outcomes[index] = PRESENCE[value.nil? ? 1 : 0] if trail
|
|
18
18
|
value
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
# Notes value, a &. chain's value as the index-th leaf of
|
|
22
|
-
#
|
|
22
|
+
# decision, as record does, when every receiver of the chain,
|
|
23
23
|
# whose leaves start at first, was not nil; returns value
|
|
24
24
|
# unchanged.
|
|
25
|
-
def chained(
|
|
26
|
-
return value unless reached?(
|
|
25
|
+
def chained(decision, index, first, value)
|
|
26
|
+
return value unless reached?(decision, first, index)
|
|
27
27
|
|
|
28
|
-
record(
|
|
28
|
+
record(decision, index, value)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
# True when
|
|
31
|
+
# True when decision's current evaluation reached its index-th
|
|
32
32
|
# leaf: every leaf of its chain before it, from first, was
|
|
33
33
|
# not nil. An evaluation with no trail, eg in another fiber,
|
|
34
34
|
# is taken to reach it.
|
|
35
|
-
def reached?(
|
|
36
|
-
trail = trails(
|
|
35
|
+
def reached?(decision, first, index)
|
|
36
|
+
trail = trails(decision).last
|
|
37
37
|
trail.nil? || trail.outcomes[first...index].all?(PRESENCE[0])
|
|
38
38
|
end
|
|
39
39
|
end
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
module PathCoverage
|
|
2
2
|
# The part of the recorder that notes ||= and &&= writes: the
|
|
3
|
-
# target's outcome at its place among its
|
|
4
|
-
# for a write that is a
|
|
3
|
+
# target's outcome at its place among its decision's leaves, at 0
|
|
4
|
+
# for a write that is a decision of its own. It relies on its
|
|
5
5
|
# includer's record and trails.
|
|
6
6
|
module RecorderWrites
|
|
7
|
-
# Notes outcome as the target's,
|
|
7
|
+
# Notes outcome as the target's, decision's at-th leaf, of the
|
|
8
8
|
# write whose right side ran, false for ||=, true for &&=,
|
|
9
9
|
# and returns value, the right side's, unchanged. The target
|
|
10
10
|
# is never read, as reading it could call a method twice.
|
|
11
|
-
def written_at(
|
|
12
|
-
record(
|
|
11
|
+
def written_at(decision, at, outcome, value)
|
|
12
|
+
record(decision, at, outcome)
|
|
13
13
|
value
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
# Notes skipped as the outcome of the write's target,
|
|
16
|
+
# Notes skipped as the outcome of the write's target, decision's
|
|
17
17
|
# at-th leaf, when its right side never ran, so noted none;
|
|
18
18
|
# returns value, the write's, unchanged.
|
|
19
|
-
def settle(
|
|
20
|
-
trail = trails(
|
|
19
|
+
def settle(decision, at, skipped, value)
|
|
20
|
+
trail = trails(decision).last
|
|
21
21
|
unnoted = trail.nil? || trail.outcomes[at].nil?
|
|
22
|
-
record(
|
|
22
|
+
record(decision, at, skipped) if unnoted
|
|
23
23
|
value
|
|
24
24
|
end
|
|
25
25
|
end
|
data/lib/path_coverage/render.rb
CHANGED
|
@@ -1,88 +1,95 @@
|
|
|
1
|
+
require_relative 'paths_context'
|
|
1
2
|
require_relative 'console_summary'
|
|
2
3
|
require_relative 'gaps'
|
|
3
|
-
require_relative 'html_report'
|
|
4
4
|
require_relative 'json_reader'
|
|
5
|
+
require_relative 'json_reports'
|
|
5
6
|
require_relative 'manifest'
|
|
6
7
|
require_relative 'paths_report'
|
|
7
8
|
require_relative 'post'
|
|
8
|
-
require_relative '
|
|
9
|
+
require_relative 'decision_paths'
|
|
9
10
|
require_relative 'within_methods'
|
|
10
11
|
|
|
11
12
|
module PathCoverage
|
|
12
|
-
# The reporters, run from operands alone:
|
|
13
|
-
# run recorded beyond them, they can run in
|
|
13
|
+
# The JSON reports and the reporters, run from operands alone:
|
|
14
|
+
# needing nothing the run recorded beyond them, they can run in
|
|
15
|
+
# another process.
|
|
14
16
|
module Render
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
# reached: as Recorder#reached
|
|
18
|
-
# { full path => {source:,
|
|
17
|
+
# Writes the JSON reports, then runs each reporter chosen in
|
|
18
|
+
# config. operands, and taken's decision_paths: and outside:, are
|
|
19
|
+
# as Result gives them, and its reached: as Recorder#reached
|
|
20
|
+
# gives it; files is { full path => {source:, decisions:} } for
|
|
21
|
+
# each covered file.
|
|
19
22
|
def self.run(operands, files, config, **taken)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
recorded = taken.merge(
|
|
24
|
+
decision_paths: every_decision(
|
|
25
|
+
taken.fetch(:decision_paths, {}), files
|
|
26
|
+
),
|
|
27
|
+
outside: taken.fetch(:outside, {})
|
|
28
|
+
)
|
|
29
|
+
JsonReports.write(operands, files, config, **recorded)
|
|
30
|
+
reporters(operands, files, config, recorded)
|
|
31
|
+
end
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
# Runs each reporter chosen in config, from operands, files,
|
|
34
|
+
# and recorded, as run has them.
|
|
35
|
+
def self.reporters(operands, files, config, recorded)
|
|
36
|
+
paths, reached = recorded.values_at(:decision_paths, :reached)
|
|
37
|
+
runs = {
|
|
38
|
+
gaps: -> { gaps(operands, files, config, recorded) },
|
|
39
|
+
summary: -> { summary(files, config, paths, reached) },
|
|
40
|
+
ways: -> { print File.read(JsonReports.ways_path(config)) },
|
|
41
|
+
post: -> { post(operands, files, config, paths) }
|
|
42
|
+
}
|
|
43
|
+
runs.slice(*config.reporters).each_value(&:call)
|
|
30
44
|
end
|
|
31
45
|
|
|
32
46
|
# Runs the :post reporter: operands, and the paths report of
|
|
33
|
-
#
|
|
34
|
-
def self.post(operands, files, config,
|
|
35
|
-
report = PathsReport.of(
|
|
47
|
+
# decision_paths in files, with config's fingerprint.
|
|
48
|
+
def self.post(operands, files, config, decision_paths)
|
|
49
|
+
report = PathsReport.of(decision_paths, files)
|
|
36
50
|
url = config.collector_url
|
|
37
51
|
fingerprint = config.fingerprint
|
|
38
52
|
Post.deliver(operands, url, report, fingerprint:)
|
|
39
53
|
end
|
|
40
54
|
|
|
41
|
-
# Runs the :html and :summary reporters, each when chosen.
|
|
42
|
-
def self.html_and_summary(operands, files, config, recorded)
|
|
43
|
-
site_paths, reached = recorded
|
|
44
|
-
reporters = config.reporters
|
|
45
|
-
if reporters.include?(:html)
|
|
46
|
-
HtmlReport.write(operands, files, config, recorded)
|
|
47
|
-
end
|
|
48
|
-
return unless reporters.include?(:summary)
|
|
49
|
-
|
|
50
|
-
cards = WithinMethods.cards(files, config, site_paths, reached)
|
|
51
|
-
summary(config, site_paths, cards)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
55
|
# Prints the summary lines: the paths taken of all possible
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
puts ConsoleSummary.lines(
|
|
56
|
+
# alone, and combined, each def's flow of files as decision_paths
|
|
57
|
+
# and reached have it; then any operators ignored.
|
|
58
|
+
def self.summary(files, config, decision_paths, reached)
|
|
59
|
+
flows = WithinMethods.flows(files, config, decision_paths,
|
|
60
|
+
reached)
|
|
61
|
+
puts ConsoleSummary.lines(decision_paths, flows,
|
|
62
|
+
config.groups) +
|
|
61
63
|
ConsoleSummary.ignored_lines(config.ignored)
|
|
62
64
|
end
|
|
63
65
|
|
|
64
|
-
#
|
|
66
|
+
# decision_paths with every decision in files that it lacks, eg
|
|
65
67
|
# from a JSON report with no paths, given each possible
|
|
66
68
|
# path at a count of zero: unable to say which paths such
|
|
67
|
-
# a
|
|
68
|
-
def self.
|
|
69
|
+
# a decision took, the report claims none.
|
|
70
|
+
def self.every_decision(decision_paths, files)
|
|
69
71
|
none = files.values.each_with_object({}) do |parsed, all|
|
|
70
|
-
parsed[:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
end
|
|
72
|
+
parsed[:decisions].each do |decision, condition|
|
|
73
|
+
possible = DecisionPaths.possible(condition)
|
|
74
|
+
all[decision] = possible.map { |path| { path:, count: 0 } }
|
|
74
75
|
end
|
|
75
76
|
end
|
|
76
|
-
none.merge(
|
|
77
|
+
none.merge(decision_paths)
|
|
77
78
|
end
|
|
78
79
|
|
|
79
|
-
# Prints the gap lines: each path a
|
|
80
|
+
# Prints the gap lines: each path a decision never took, and each
|
|
80
81
|
# path taken that a treatment rules out, as outside lists
|
|
81
|
-
# them, each leaf named by its text in files
|
|
82
|
-
|
|
82
|
+
# them, each leaf named by its text in files; then each path
|
|
83
|
+
# taken, or return or raise reached, that its method rules
|
|
84
|
+
# out, as PathsContext.ruled_out finds them in files under
|
|
85
|
+
# config. recorded is as run has it.
|
|
86
|
+
def self.gaps(operands, files, config, recorded)
|
|
83
87
|
texts = PathsReport.texts(files)
|
|
84
|
-
paths =
|
|
88
|
+
paths, outside, reached =
|
|
89
|
+
recorded.values_at(:decision_paths, :outside, :reached)
|
|
85
90
|
lines = Gaps.lines(operands, paths:, texts:, outside:)
|
|
91
|
+
ruled = PathsContext.ruled_out(files, config, paths, reached)
|
|
92
|
+
lines += Gaps.ruled_by_method(ruled, texts)
|
|
86
93
|
lines.each { |line| puts line }
|
|
87
94
|
end
|
|
88
95
|
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
require 'prism'
|
|
2
|
+
require_relative 'decision'
|
|
3
|
+
require_relative 'leaving'
|
|
4
|
+
|
|
5
|
+
module PathCoverage
|
|
6
|
+
# The rescue forks of each def. Each begin with a rescue forks
|
|
7
|
+
# there, whether it is a def's body, a block's, or nested in a
|
|
8
|
+
# body. Either its body completes, or one of its rescues runs.
|
|
9
|
+
module RescueForks
|
|
10
|
+
# Example: { "k.rb:1:0" => { "k.rb:3:0" => [1, 0...30, 14...20,
|
|
11
|
+
# [38...40]] } } for a def at line 1 whose one rescue is at
|
|
12
|
+
# line 3.
|
|
13
|
+
# { def decision => { fork's name => [its rescues, its begin's
|
|
14
|
+
# byte range, its body's, [each rescue's body's]] } } for each
|
|
15
|
+
# def in source, at path. A fork is named where its first
|
|
16
|
+
# rescue is.
|
|
17
|
+
def self.of(source, path)
|
|
18
|
+
found(source, path).forks
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# The Found that has visited each def in source, at path.
|
|
22
|
+
def self.found(source, path)
|
|
23
|
+
found = Found.new(path)
|
|
24
|
+
Prism.parse(source).value.accept(found)
|
|
25
|
+
found
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Finds the rescue fork of each def it visits.
|
|
29
|
+
class Found < Prism::Visitor
|
|
30
|
+
# Starts with no def visited. Forks are named as at path.
|
|
31
|
+
def initialize(path)
|
|
32
|
+
@path = path
|
|
33
|
+
@forks = {}
|
|
34
|
+
@completions = {}
|
|
35
|
+
@starts = {}
|
|
36
|
+
@values = {}
|
|
37
|
+
@def = nil
|
|
38
|
+
super()
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# forks is { def decision => { fork's name => [its rescues,
|
|
42
|
+
# its begin's byte range, its body's, [each rescue's body's]]
|
|
43
|
+
# } }.
|
|
44
|
+
# completions is { fork's name => where its body completes }.
|
|
45
|
+
# starts is { [fork's name, rescue's number] => the byte
|
|
46
|
+
# offset where that rescue starts to run }. values is { fork's
|
|
47
|
+
# name => the byte range of a rescue modifier's rescue, its
|
|
48
|
+
# value }.
|
|
49
|
+
attr_reader :forks, :completions, :starts, :values
|
|
50
|
+
|
|
51
|
+
# Visits inside node, a def, noting the rescue forks in it as
|
|
52
|
+
# its own.
|
|
53
|
+
def visit_def_node(node)
|
|
54
|
+
outer = @def
|
|
55
|
+
@def = Decision.of(@path, node)
|
|
56
|
+
@forks[@def] = {}
|
|
57
|
+
super
|
|
58
|
+
@def = outer
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Notes node, a begin, as a rescue fork of the def it is in,
|
|
62
|
+
# when it has a rescue, then visits inside it. A def's body
|
|
63
|
+
# with a rescue is a begin, and so is a block's.
|
|
64
|
+
def visit_begin_node(node)
|
|
65
|
+
note_fork(node) unless @def.nil? || node.rescue_clause.nil?
|
|
66
|
+
super
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Notes node, a rescue modifier, x rescue y, as a rescue fork
|
|
70
|
+
# of the def it is in, then visits inside it. Its body is x,
|
|
71
|
+
# and its one rescue is y. Its name is where its rescue is.
|
|
72
|
+
def visit_rescue_modifier_node(node)
|
|
73
|
+
note_modifier(node) unless @def.nil?
|
|
74
|
+
super
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Notes the rescue fork of node, a rescue modifier.
|
|
78
|
+
def note_modifier(node)
|
|
79
|
+
name = Decision.at(@path, node.keyword_loc)
|
|
80
|
+
body = span(node.expression.location)
|
|
81
|
+
value = span(node.rescue_expression.location)
|
|
82
|
+
@forks[@def][name] = [1, span(node.location), body, [value]]
|
|
83
|
+
note_value(name, node.expression, value)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Notes where the rescue modifier named name completes and
|
|
87
|
+
# where its rescue runs. It completes at expression, wrapped,
|
|
88
|
+
# unless that leaves. Its rescue runs at value, wrapped.
|
|
89
|
+
def note_value(name, expression, value)
|
|
90
|
+
if Leaving.word(expression).nil?
|
|
91
|
+
@completions[name] = span(expression.location)
|
|
92
|
+
end
|
|
93
|
+
@values[name] = value
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# The byte range of location.
|
|
97
|
+
def span(location)
|
|
98
|
+
location.start_offset...location.end_offset
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Notes the rescue fork of node, a begin with a rescue. Its
|
|
102
|
+
# name is where its first rescue is.
|
|
103
|
+
def note_fork(node)
|
|
104
|
+
clause = node.rescue_clause
|
|
105
|
+
name = Decision.at(@path, clause.location)
|
|
106
|
+
note_completion(name, node.statements, clause)
|
|
107
|
+
count = noted(name, clause, 1)
|
|
108
|
+
@forks[@def][name] = [count, *spans_of(node, clause)]
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# [the byte range of node, a begin, of its body, and of the
|
|
112
|
+
# body of each rescue from clause, its first].
|
|
113
|
+
def spans_of(node, clause)
|
|
114
|
+
whole = node.location
|
|
115
|
+
body = range_of(node.statements, clause.location.start_offset)
|
|
116
|
+
clauses = []
|
|
117
|
+
until clause.nil?
|
|
118
|
+
clauses << range_of(clause.statements,
|
|
119
|
+
header_end(clause))
|
|
120
|
+
clause = clause.subsequent
|
|
121
|
+
end
|
|
122
|
+
[whole.start_offset...whole.end_offset, body, clauses]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# The byte range of statements, or an empty range at offset
|
|
126
|
+
# when there are none.
|
|
127
|
+
def range_of(statements, offset)
|
|
128
|
+
return offset...offset if statements.nil?
|
|
129
|
+
|
|
130
|
+
loc = statements.location
|
|
131
|
+
loc.start_offset...loc.end_offset
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Notes where a body of statements completes. name is its
|
|
135
|
+
# fork's name, and clause its first rescue. An empty body
|
|
136
|
+
# completes at clause, by a byte offset, for a statement of
|
|
137
|
+
# its own. Otherwise it completes at its last statement, by
|
|
138
|
+
# its byte range, to wrap. A last statement that leaves is
|
|
139
|
+
# not noted, because that body never completes.
|
|
140
|
+
def note_completion(name, statements, clause)
|
|
141
|
+
if statements.nil?
|
|
142
|
+
return @completions[name] = clause.location.start_offset
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
last = statements.body.last
|
|
146
|
+
return unless Leaving.word(last).nil?
|
|
147
|
+
|
|
148
|
+
loc = last.location
|
|
149
|
+
@completions[name] = loc.start_offset...loc.end_offset
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# How many rescues the fork named name has, counting from
|
|
153
|
+
# clause, the rescue numbered number. It notes where each
|
|
154
|
+
# rescue starts to run, after its header. Once the rescues
|
|
155
|
+
# run out it gives number less one.
|
|
156
|
+
def noted(name, clause, number)
|
|
157
|
+
return number - 1 if clause.nil?
|
|
158
|
+
|
|
159
|
+
@starts[[name, number]] = header_end(clause)
|
|
160
|
+
noted(name, clause.subsequent, number + 1)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# The byte offset where the header of clause, a rescue, ends.
|
|
164
|
+
# The header is its keyword, its exceptions, its => and
|
|
165
|
+
# reference, and its then, whichever of them it has.
|
|
166
|
+
def header_end(clause)
|
|
167
|
+
nodes = [*clause.exceptions, clause.reference].compact
|
|
168
|
+
locs = [clause.keyword_loc, clause.operator_loc,
|
|
169
|
+
clause.then_keyword_loc].compact
|
|
170
|
+
(nodes.map(&:location) + locs).map(&:end_offset).max
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
data/lib/path_coverage/result.rb
CHANGED
|
@@ -1,78 +1,79 @@
|
|
|
1
|
-
require_relative '
|
|
1
|
+
require_relative 'decision_paths'
|
|
2
2
|
|
|
3
3
|
module PathCoverage
|
|
4
|
-
# What a run found: every
|
|
4
|
+
# What a run found: every decision the manifest knows of, with
|
|
5
5
|
# the counts its operands were recorded with. Every
|
|
6
6
|
# reporter builds on this.
|
|
7
7
|
class Result
|
|
8
8
|
NEVER_RAN = { truthy: 0, falsy: 0 }.freeze
|
|
9
9
|
|
|
10
|
-
#
|
|
11
|
-
# counts is { [
|
|
12
|
-
# {
|
|
10
|
+
# decisions is { decision => Condition }, from the manifest;
|
|
11
|
+
# counts is { [decision, index] => counts } and decision_paths is
|
|
12
|
+
# { decision => { path => evaluations } }, both from the
|
|
13
13
|
# recorder.
|
|
14
|
-
def initialize(
|
|
15
|
-
@
|
|
14
|
+
def initialize(decisions, counts, decision_paths = {})
|
|
15
|
+
@decisions = decisions
|
|
16
16
|
@counts = counts
|
|
17
|
-
@
|
|
17
|
+
@decision_paths = decision_paths
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
# {
|
|
21
|
-
# of each
|
|
22
|
-
# evaluations that took it, zero for one never
|
|
20
|
+
# { decision => [{ path:, count: }, ...] }: every possible path
|
|
21
|
+
# of each decision, as DecisionPaths gives them, with the
|
|
22
|
+
# number of evaluations that took it, zero for one never
|
|
23
|
+
# taken.
|
|
23
24
|
def paths
|
|
24
|
-
@
|
|
25
|
-
taken = @
|
|
26
|
-
all =
|
|
25
|
+
@decisions.to_h do |decision, condition|
|
|
26
|
+
taken = @decision_paths.fetch(decision, {})
|
|
27
|
+
all = DecisionPaths.possible(condition).map do |path|
|
|
27
28
|
{ path:, count: taken.fetch(path, 0) }
|
|
28
29
|
end
|
|
29
|
-
[
|
|
30
|
+
[decision, all]
|
|
30
31
|
end
|
|
31
32
|
end
|
|
32
33
|
|
|
33
|
-
# {
|
|
34
|
-
# that is none of its
|
|
35
|
-
# nil though treated as present; only
|
|
34
|
+
# { decision => { path => evaluations } } of each path taken
|
|
35
|
+
# that is none of its decision's possible paths, eg a &. receiver
|
|
36
|
+
# nil though treated as present; only decisions with one. Such a
|
|
36
37
|
# path shows a treatment to be wrong, so it is reported, never
|
|
37
38
|
# dropped.
|
|
38
39
|
def outside
|
|
39
|
-
all = @
|
|
40
|
-
taken = @
|
|
41
|
-
[
|
|
40
|
+
all = @decisions.to_h do |decision, condition|
|
|
41
|
+
taken = @decision_paths.fetch(decision, {})
|
|
42
|
+
[decision, taken.except(*DecisionPaths.possible(condition))]
|
|
42
43
|
end
|
|
43
44
|
all.reject { |_, paths| paths.empty? }
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
# The paths taken, as Render.run takes them:
|
|
47
|
+
# The paths taken, as Render.run takes them: decision_paths:,
|
|
47
48
|
# as paths gives them, and outside:.
|
|
48
49
|
def taken
|
|
49
|
-
{
|
|
50
|
+
{ decision_paths: paths, outside: }
|
|
50
51
|
end
|
|
51
52
|
|
|
52
|
-
# {
|
|
53
|
+
# { decision => [counts of operand 0, counts of operand 1, ...] },
|
|
53
54
|
# with zero counts for an operand that never ran, and
|
|
54
55
|
# only: naming the one outcome a fixed leaf can have.
|
|
55
56
|
def operands
|
|
56
|
-
@
|
|
57
|
+
@decisions.to_h do |decision, condition|
|
|
57
58
|
leaves = condition.leaves.each_with_index.map do |range, i|
|
|
58
|
-
leaf(
|
|
59
|
+
leaf(decision, condition, range, i)
|
|
59
60
|
end
|
|
60
|
-
[
|
|
61
|
+
[decision, leaves]
|
|
61
62
|
end
|
|
62
63
|
end
|
|
63
64
|
|
|
64
65
|
private
|
|
65
66
|
|
|
66
67
|
# The counts of one leaf, with only: when it is fixed.
|
|
67
|
-
def leaf(
|
|
68
|
-
counts = counts_of(
|
|
68
|
+
def leaf(decision, condition, range, index)
|
|
69
|
+
counts = counts_of(decision, index)
|
|
69
70
|
only = condition.fixed[range]
|
|
70
71
|
only ? counts.merge(only:) : counts
|
|
71
72
|
end
|
|
72
73
|
|
|
73
74
|
# The recorded counts of one operand, or zeros.
|
|
74
|
-
def counts_of(
|
|
75
|
-
@counts.fetch([
|
|
75
|
+
def counts_of(decision, index)
|
|
76
|
+
@counts.fetch([decision, index], NEVER_RAN)
|
|
76
77
|
end
|
|
77
78
|
end
|
|
78
79
|
end
|