path_coverage 0.2.0 → 0.3.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 +112 -113
- data/lib/path_coverage/calls.rb +4 -11
- data/lib/path_coverage/card.rb +14 -0
- data/lib/path_coverage/condition.rb +8 -1
- data/lib/path_coverage/configuration.rb +1 -17
- data/lib/path_coverage/configuration_paths.rb +4 -2
- data/lib/path_coverage/console_summary.rb +15 -17
- data/lib/path_coverage/gaps.rb +12 -9
- data/lib/path_coverage/html/file.html +5 -5
- data/lib/path_coverage/html/index.html +3 -1
- data/lib/path_coverage/html/settings.js +50 -0
- data/lib/path_coverage/html/side.js +341 -432
- data/lib/path_coverage/html/style.css +330 -225
- data/lib/path_coverage/html/theme.js +27 -0
- data/lib/path_coverage/html_branch.rb +30 -0
- data/lib/path_coverage/html_cards.rb +111 -0
- data/lib/path_coverage/html_cells.rb +66 -0
- data/lib/path_coverage/html_file.rb +82 -68
- data/lib/path_coverage/html_index.rb +28 -29
- data/lib/path_coverage/html_index_head.rb +10 -30
- data/lib/path_coverage/html_labels.rb +23 -0
- data/lib/path_coverage/html_methods.rb +66 -0
- data/lib/path_coverage/html_nav.rb +50 -50
- data/lib/path_coverage/html_report.rb +45 -49
- data/lib/path_coverage/html_statements.rb +166 -0
- data/lib/path_coverage/html_syntax.rb +156 -0
- data/lib/path_coverage/html_template.rb +6 -0
- data/lib/path_coverage/html_tree.rb +36 -72
- data/lib/path_coverage/json_reader.rb +21 -14
- data/lib/path_coverage/json_writer.rb +26 -13
- data/lib/path_coverage/kernel.rb +29 -49
- data/lib/path_coverage/kinds/block.rb +2 -1
- data/lib/path_coverage/kinds/case.rb +7 -4
- data/lib/path_coverage/kinds/contains.rb +6 -4
- data/lib/path_coverage/kinds/safe.rb +5 -3
- data/lib/path_coverage/manifest.rb +2 -1
- data/lib/path_coverage/manifest_blocks.rb +3 -4
- data/lib/path_coverage/manifest_case.rb +2 -3
- data/lib/path_coverage/manifest_choices.rb +4 -3
- data/lib/path_coverage/manifest_folding.rb +1 -1
- data/lib/path_coverage/merge.rb +3 -3
- data/lib/path_coverage/method_statements.rb +300 -0
- data/lib/path_coverage/recorder.rb +12 -31
- data/lib/path_coverage/render.rb +19 -22
- data/lib/path_coverage/rewriter.rb +36 -55
- data/lib/path_coverage/site_tree.rb +9 -0
- data/lib/path_coverage/statement_arms.rb +161 -0
- data/lib/path_coverage/summary.rb +11 -15
- data/lib/path_coverage/totals.rb +6 -12
- data/lib/path_coverage/version.rb +1 -1
- data/lib/path_coverage/within_methods.rb +92 -0
- metadata +16 -11
- data/lib/path_coverage/html/toggle.js +0 -12
- data/lib/path_coverage/html_paths.rb +0 -138
- data/lib/path_coverage/path_gaps.rb +0 -41
- data/lib/path_coverage/path_manifest.rb +0 -110
|
@@ -1,60 +1,22 @@
|
|
|
1
1
|
require 'cgi/escape'
|
|
2
2
|
require_relative 'condition'
|
|
3
|
+
require_relative 'html_branch'
|
|
4
|
+
require_relative 'html_cells'
|
|
5
|
+
require_relative 'html_labels'
|
|
6
|
+
require_relative 'html_syntax'
|
|
3
7
|
require_relative 'kinds'
|
|
4
8
|
|
|
5
9
|
module PathCoverage
|
|
6
|
-
# The tree of a
|
|
7
|
-
#
|
|
10
|
+
# The tree of a site, from SiteTree.of, as its row's fold in a
|
|
11
|
+
# card shows it: a grid whose columns are the site's paths.
|
|
8
12
|
module HtmlTree
|
|
9
|
-
OUTCOMES = {
|
|
10
|
-
true => 'T', false => 'F', nil => '',
|
|
11
|
-
ITEMS[0] => '0', ITEMS[1] => '1', ITEMS[2] => '*',
|
|
12
|
-
ANSWERS[0] => 'T', ANSWERS[1] => 'F', ANSWERS[2] => 'TF',
|
|
13
|
-
PRESENCE[0] => [0x25CF].pack('U'),
|
|
14
|
-
PRESENCE[1] => [0x2205].pack('U')
|
|
15
|
-
}.freeze
|
|
16
|
-
|
|
17
|
-
# A tick marks a path taking an arm.
|
|
18
|
-
TAKEN = { true => [0x2713].pack('U'), false => '' }.freeze
|
|
19
|
-
|
|
20
|
-
# The tree of a span, open when its sites have gaps, else
|
|
21
|
-
# hidden: each site's rows in a group of their own.
|
|
22
|
-
def self.of(number, site_trees, open)
|
|
23
|
-
groups = site_trees.map do |site|
|
|
24
|
-
rows = site_rows(site).join
|
|
25
|
-
%(<div class="site" data-site="">#{rows}</div>)
|
|
26
|
-
end
|
|
27
|
-
hidden = open ? '' : ' hidden="hidden"'
|
|
28
|
-
body = groups.join
|
|
29
|
-
%(<div class="tree" id="tree-#{number}"#{hidden}>#{body}</div>)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
13
|
# A site's row, naming its operator and each path's count,
|
|
33
14
|
# then the rows of its operands.
|
|
34
15
|
def self.site_rows(site)
|
|
35
|
-
counts =
|
|
16
|
+
counts = HtmlCells.counts(site[:counts])
|
|
36
17
|
[row(at(site), operator(site), counts), *operand_rows(site, '')]
|
|
37
18
|
end
|
|
38
19
|
|
|
39
|
-
# One cell per path's count, a path never taken marked as a
|
|
40
|
-
# gap.
|
|
41
|
-
def self.count_cells(counts)
|
|
42
|
-
counts.map do |count|
|
|
43
|
-
css = count.zero? ? 'count never' : 'count'
|
|
44
|
-
%(<span class="#{css}" data-count="">#{count}</span>)
|
|
45
|
-
end.join
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
# One cell per path, naming each with names; a &. receiver's,
|
|
49
|
-
# shown as a glyph, titled not nil or nil for its hover text.
|
|
50
|
-
def self.cells(values, names = OUTCOMES)
|
|
51
|
-
values.map do |value|
|
|
52
|
-
title = PRESENCE.include?(value) ? %( title="#{value}") : ''
|
|
53
|
-
attrs = %(class="cell" data-cell=""#{title})
|
|
54
|
-
%(<span #{attrs}>#{names[value]}</span>)
|
|
55
|
-
end.join
|
|
56
|
-
end
|
|
57
|
-
|
|
58
20
|
# SPIKE: the data-at attribute of a node located in its
|
|
59
21
|
# source, '' for one that is not.
|
|
60
22
|
def self.at(node)
|
|
@@ -75,8 +37,8 @@ module PathCoverage
|
|
|
75
37
|
last = operands.size - 1
|
|
76
38
|
operands.each_with_index.flat_map do |operand, i|
|
|
77
39
|
tip = i == last
|
|
78
|
-
branch = indent + (tip ?
|
|
79
|
-
under = indent + (tip ?
|
|
40
|
+
branch = indent + (tip ? HtmlBranch::ELL : HtmlBranch::TEE)
|
|
41
|
+
under = indent + (tip ? HtmlBranch::GAP : HtmlBranch::BAR)
|
|
80
42
|
node_rows(operand, branch, under, condition[:operator])
|
|
81
43
|
end
|
|
82
44
|
end
|
|
@@ -96,22 +58,27 @@ module PathCoverage
|
|
|
96
58
|
# An arm's row: a ternary's, ? for then and : for else, an
|
|
97
59
|
# arm holding a condition showing the condition's operator
|
|
98
60
|
# and value, its operands below, a plain arm its text; an
|
|
99
|
-
# if's named then or else, as its text is statements
|
|
100
|
-
#
|
|
61
|
+
# if's named then or else, as its text is statements; its then
|
|
62
|
+
# label marked as a name, as no then is written in its code,
|
|
63
|
+
# where its else is. A plain arm marks the paths taking it.
|
|
101
64
|
def self.arm_rows(arm, branch, under, choice)
|
|
102
65
|
body = arm[:body]
|
|
103
|
-
values =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
66
|
+
values = arm_cells(arm, body)
|
|
67
|
+
named = STATEMENT_CHOICES.include?(choice) && arm[:arm] == :then
|
|
68
|
+
text = HtmlLabels.arm(arm, choice, named)
|
|
69
|
+
flag = named ? ' data-named=""' : ''
|
|
70
|
+
lead = HtmlBranch.cell(branch) +
|
|
71
|
+
%(<span class="arm" data-label=""#{flag}>#{text}</span>)
|
|
107
72
|
row = row(%( data-arm=""#{at(arm)}), lead, values)
|
|
108
73
|
body ? [row, *operand_rows(body, under)] : [row]
|
|
109
74
|
end
|
|
110
75
|
|
|
111
|
-
# The
|
|
112
|
-
#
|
|
113
|
-
def self.
|
|
114
|
-
|
|
76
|
+
# The cells of arm's row: its body's values, when its body is
|
|
77
|
+
# a condition; else a tick on each path that took it.
|
|
78
|
+
def self.arm_cells(arm, body)
|
|
79
|
+
return HtmlCells.of(body[:cells]) if body
|
|
80
|
+
|
|
81
|
+
HtmlCells.of(arm[:cells], HtmlCells::TAKEN)
|
|
115
82
|
end
|
|
116
83
|
|
|
117
84
|
# operands with each node standing for the nodes its kind
|
|
@@ -127,9 +94,9 @@ module PathCoverage
|
|
|
127
94
|
# A nested condition's row: its branch, its operator, and
|
|
128
95
|
# its value on each path.
|
|
129
96
|
def self.subtree_row(condition, branch)
|
|
130
|
-
lead =
|
|
97
|
+
lead = HtmlBranch.cell(branch) + operator(condition)
|
|
131
98
|
attrs = %( data-subtree=""#{at(condition)})
|
|
132
|
-
row(attrs, lead,
|
|
99
|
+
row(attrs, lead, HtmlCells.of(condition[:cells]))
|
|
133
100
|
end
|
|
134
101
|
|
|
135
102
|
# A row of the grid, with attrs, lead's cells naming it,
|
|
@@ -139,29 +106,26 @@ module PathCoverage
|
|
|
139
106
|
end
|
|
140
107
|
|
|
141
108
|
# The cell naming a condition's operator, or its label when
|
|
142
|
-
# it has one, eg select { for a site inside a leaf
|
|
109
|
+
# it has one, eg select { for a site inside a leaf, coloured
|
|
110
|
+
# as the code it is part of.
|
|
143
111
|
def self.operator(condition)
|
|
144
|
-
|
|
112
|
+
label = condition.fetch(:label) { condition[:operator] }
|
|
113
|
+
name = HtmlSyntax.fragment(label)
|
|
145
114
|
%(<span class="operator" data-operator="">#{name}</span>)
|
|
146
115
|
end
|
|
147
116
|
|
|
148
|
-
# One operand's row: its branch, text,
|
|
149
|
-
# each path.
|
|
117
|
+
# One operand's row: its branch, text, coloured as the code it
|
|
118
|
+
# is, and its outcome on each path.
|
|
150
119
|
# An operand that is only called, eg owner at the end of
|
|
151
120
|
# user&.account&.owner, has a tick on each path that called
|
|
152
121
|
# it instead.
|
|
153
122
|
def self.operand_row(operand, branch)
|
|
154
|
-
text =
|
|
155
|
-
lead =
|
|
123
|
+
text = HtmlSyntax.fragment(operand[:text].to_s)
|
|
124
|
+
lead = HtmlBranch.cell(branch) +
|
|
156
125
|
%(<span class="text" data-text="">#{text}</span>)
|
|
157
126
|
attrs = %( data-operand=""#{at(operand)})
|
|
158
|
-
names = operand[:called] ? TAKEN : OUTCOMES
|
|
159
|
-
row(attrs, lead,
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
# The cell drawing a row's branch from its operator.
|
|
163
|
-
def self.branch_cell(branch)
|
|
164
|
-
%(<span class="branch" data-branch="">#{branch}</span>)
|
|
127
|
+
names = operand[:called] ? HtmlCells::TAKEN : HtmlCells::OUTCOMES
|
|
128
|
+
row(attrs, lead, HtmlCells.of(operand[:cells], names))
|
|
165
129
|
end
|
|
166
130
|
end
|
|
167
131
|
end
|
|
@@ -17,18 +17,27 @@ module PathCoverage
|
|
|
17
17
|
Merge.operands(paths.map { |path| read(path, fingerprint) })
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
# The method paths of the JSON reports at paths, merged.
|
|
21
|
-
def self.method_paths(paths)
|
|
22
|
-
merged(paths, 'method_paths')
|
|
23
|
-
end
|
|
24
|
-
|
|
25
20
|
# The paths taken of the JSON reports at paths, as
|
|
26
21
|
# Render.run takes them: site_paths:, each site's possible
|
|
27
|
-
# paths,
|
|
28
|
-
# merged.
|
|
22
|
+
# paths, outside:, those a treatment rules out, and reached:,
|
|
23
|
+
# each statement's reaches, each merged.
|
|
29
24
|
def self.taken(paths)
|
|
30
25
|
site_paths = Merge.paths(paths.map { |path| paths_of(path) })
|
|
31
|
-
|
|
26
|
+
outside = merged(paths, 'outside')
|
|
27
|
+
{ site_paths:, outside:, reached: reached(paths) }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Example: { "k.rb:2:2" => 2 } and { "k.rb:2:2" => 1 } give
|
|
31
|
+
# { "k.rb:2:2" => 3 }.
|
|
32
|
+
# The reaches of the JSON reports at paths, each statement's
|
|
33
|
+
# summed; nil when none has any, eg reports the :post reporter
|
|
34
|
+
# sent, so a render cannot say what was reached.
|
|
35
|
+
def self.reached(paths)
|
|
36
|
+
reports = paths.map { |path| JSON.parse(File.read(path)) }
|
|
37
|
+
runs = reports.map { |report| report['reached'] }.compact
|
|
38
|
+
return nil if runs.empty?
|
|
39
|
+
|
|
40
|
+
runs.reduce { |all, run| all.merge(run) { |_, a, b| a + b } }
|
|
32
41
|
end
|
|
33
42
|
|
|
34
43
|
# Raises unless json, the JSON report at path, measured the
|
|
@@ -46,14 +55,12 @@ module PathCoverage
|
|
|
46
55
|
# The key lists of the JSON reports at paths, as listed_of
|
|
47
56
|
# gives them, each path's count the sum of every report's.
|
|
48
57
|
def self.merged(paths, key)
|
|
49
|
-
Merge.
|
|
58
|
+
Merge.listed(paths.map { |path| listed_of(path, key) })
|
|
50
59
|
end
|
|
51
60
|
|
|
52
|
-
# The JSON report at path's list under key, eg its
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
# that did not measure methods, so the render claims no
|
|
56
|
-
# path taken.
|
|
61
|
+
# The JSON report at path's list under key, eg its paths a
|
|
62
|
+
# treatment rules out, { site => { path => count } }; none
|
|
63
|
+
# for a report that has none, so the render claims none.
|
|
57
64
|
def self.listed_of(path, key)
|
|
58
65
|
json = JSON.parse(File.read(path))
|
|
59
66
|
json.fetch(key, {}).transform_values do |taken|
|
|
@@ -6,11 +6,9 @@ module PathCoverage
|
|
|
6
6
|
# other reporter can read back.
|
|
7
7
|
module JsonWriter
|
|
8
8
|
# Writes operands, as Result gives them, paths, as
|
|
9
|
-
# PathsReport gives them, totals, as Kernel.totals gives
|
|
10
|
-
# them,
|
|
11
|
-
#
|
|
12
|
-
# {site: {leaves:, taken:}}, "method_paths": {site:
|
|
13
|
-
# [{path:, count:}, ...]}, "totals": {"decisions": [taken,
|
|
9
|
+
# PathsReport gives them, and totals, as Kernel.totals gives
|
|
10
|
+
# them, to path as {"sites": {site: [counts, ...]}, "paths":
|
|
11
|
+
# {site: {leaves:, taken:}}, "totals": {"decisions": [taken,
|
|
14
12
|
# possible]}}.
|
|
15
13
|
# parts are json's.
|
|
16
14
|
def self.write(operands, path, paths = {}, **parts)
|
|
@@ -18,25 +16,40 @@ module PathCoverage
|
|
|
18
16
|
end
|
|
19
17
|
|
|
20
18
|
# The keys of parts listed as { site => [{path:, count:}] }:
|
|
21
|
-
# each
|
|
22
|
-
#
|
|
23
|
-
LISTED = %i[
|
|
19
|
+
# each path taken that a treatment rules out, as
|
|
20
|
+
# Result#outside gives them.
|
|
21
|
+
LISTED = %i[outside].freeze
|
|
24
22
|
|
|
25
|
-
# operands, and any paths, and parts'
|
|
26
|
-
#
|
|
23
|
+
# operands, and any paths, and parts' outside:, totals: and
|
|
24
|
+
# cards:, as WithinMethods.listed gives them, as the JSON
|
|
25
|
+
# report's text, with
|
|
27
26
|
# parts' fingerprint:, as Configuration#fingerprint gives
|
|
28
|
-
# it,
|
|
27
|
+
# it, the names of the kinds measured, and parts' reached:,
|
|
28
|
+
# as Recorder#reached gives it, even empty, as a run that
|
|
29
|
+
# reached no statement says so; none when not given.
|
|
29
30
|
def self.json(operands, paths = {}, **parts)
|
|
30
31
|
fingerprint = parts.fetch(:fingerprint, {})
|
|
31
32
|
report = { 'sites' => operands, **fingerprint }
|
|
32
33
|
report['paths'] = paths unless paths.empty?
|
|
33
34
|
report.merge!(lists(parts))
|
|
34
|
-
|
|
35
|
-
report
|
|
35
|
+
report['reached'] = parts[:reached] if parts.key?(:reached)
|
|
36
|
+
report.merge!(kept(parts))
|
|
36
37
|
report['kinds'] = Kinds.names
|
|
37
38
|
JSON.pretty_generate(report)
|
|
38
39
|
end
|
|
39
40
|
|
|
41
|
+
# The keys of parts written as they are, when not empty.
|
|
42
|
+
KEPT = %i[totals cards].freeze
|
|
43
|
+
|
|
44
|
+
# { key => its value } of each of parts' KEPT keys that has
|
|
45
|
+
# a value not empty.
|
|
46
|
+
def self.kept(parts)
|
|
47
|
+
KEPT.filter_map do |key|
|
|
48
|
+
value = parts.fetch(key, {})
|
|
49
|
+
[key.to_s, value] unless value.empty?
|
|
50
|
+
end.to_h
|
|
51
|
+
end
|
|
52
|
+
|
|
40
53
|
# { key => its list } of each of parts' LISTED keys that
|
|
41
54
|
# has one, as listed gives them.
|
|
42
55
|
def self.lists(parts)
|
data/lib/path_coverage/kernel.rb
CHANGED
|
@@ -4,13 +4,12 @@ require_relative 'configuration'
|
|
|
4
4
|
require_relative 'console_summary'
|
|
5
5
|
require_relative 'json_writer'
|
|
6
6
|
require_relative 'manifest'
|
|
7
|
-
require_relative 'path_gaps'
|
|
8
|
-
require_relative 'path_manifest'
|
|
9
7
|
require_relative 'paths_report'
|
|
10
8
|
require_relative 'recorder'
|
|
11
9
|
require_relative 'render'
|
|
12
10
|
require_relative 'result'
|
|
13
11
|
require_relative 'rewriter'
|
|
12
|
+
require_relative 'within_methods'
|
|
14
13
|
|
|
15
14
|
# Path coverage for Ruby. This file is the kernel: it loads
|
|
16
15
|
# before any covered file and is never itself instrumented, since
|
|
@@ -23,7 +22,8 @@ module PathCoverage
|
|
|
23
22
|
# again.
|
|
24
23
|
@parsed = {}
|
|
25
24
|
|
|
26
|
-
# The
|
|
25
|
+
# The recorder of the latest start, that every instrumented
|
|
26
|
+
# operand reports to.
|
|
27
27
|
def self.recorder
|
|
28
28
|
@recorder
|
|
29
29
|
end
|
|
@@ -37,9 +37,12 @@ module PathCoverage
|
|
|
37
37
|
# Instruments every file later required that the settings
|
|
38
38
|
# block covers, and reports when the process exits. on_exit
|
|
39
39
|
# is Kernel#at_exit except in tests, which must not print
|
|
40
|
-
# a report as their own process exits.
|
|
40
|
+
# a report as their own process exits. Each start records
|
|
41
|
+
# afresh, so a later start, as a later test makes, never
|
|
42
|
+
# counts an earlier one's evaluations.
|
|
41
43
|
def self.start(on_exit: method(:at_exit), &)
|
|
42
44
|
config = Configuration.new(&)
|
|
45
|
+
@recorder = Recorder.new
|
|
43
46
|
install_hook if @config.nil?
|
|
44
47
|
@config = config
|
|
45
48
|
on_exit.call { report(config) }
|
|
@@ -90,43 +93,20 @@ module PathCoverage
|
|
|
90
93
|
return unless config.covers?(path)
|
|
91
94
|
|
|
92
95
|
parsed = @parsed[path] = Manifest.parse(path, config)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
rewritten = Rewriter.rewrite(parsed[:
|
|
96
|
+
source = parsed[:source]
|
|
97
|
+
reaches = WithinMethods.reaches(path, parsed, config)
|
|
98
|
+
rewritten = Rewriter.rewrite(source, parsed[:sites], reaches)
|
|
96
99
|
RubyVM::InstructionSequence.compile(rewritten, path, path)
|
|
97
100
|
end
|
|
98
101
|
|
|
99
|
-
# The methods of the covered file at path whose paths are
|
|
100
|
-
# counted, none unless config measures methods.
|
|
101
|
-
def self.path_methods(path, source, config)
|
|
102
|
-
return {} unless config.measures.include?(:methods)
|
|
103
|
-
|
|
104
|
-
PathManifest.methods(source, config.relative(path))
|
|
105
|
-
end
|
|
106
|
-
|
|
107
102
|
# Writes the JSON report, then runs the chosen reporters, for
|
|
108
103
|
# every covered file whether or not the run loaded it, into
|
|
109
|
-
# coverage_dir, created first if need be.
|
|
110
|
-
# taken follow the condition gaps.
|
|
104
|
+
# coverage_dir, created first if need be.
|
|
111
105
|
def self.report(config)
|
|
112
106
|
files = parsed_files(config)
|
|
113
107
|
result = collect(files, config)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
Render.run(result.operands, files, config, paths, **result.taken)
|
|
117
|
-
return unless config.reporters.include?(:gaps)
|
|
118
|
-
|
|
119
|
-
methods = path_methods_of(files, config)
|
|
120
|
-
PathGaps.lines(methods, @recorder.paths).each { |line| puts line }
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# The methods whose paths are counted of every covered file,
|
|
124
|
-
# in one manifest.
|
|
125
|
-
def self.path_methods_of(files, config)
|
|
126
|
-
all = files.map do |path, parsed|
|
|
127
|
-
path_methods(path, parsed[:source], config)
|
|
128
|
-
end
|
|
129
|
-
all.reduce({}, :merge)
|
|
108
|
+
Render.run(result.operands, files, config,
|
|
109
|
+
**result.taken, reached: @recorder.reached)
|
|
130
110
|
end
|
|
131
111
|
|
|
132
112
|
# The Result of every covered file, with the counts and site
|
|
@@ -141,33 +121,33 @@ module PathCoverage
|
|
|
141
121
|
end
|
|
142
122
|
|
|
143
123
|
# Writes result as the JSON report at config's json_path: its
|
|
144
|
-
# operands, site paths, paths a treatment rules out,
|
|
145
|
-
#
|
|
124
|
+
# operands, site paths, paths a treatment rules out, totals,
|
|
125
|
+
# each def's card, the statements the recorder reached, so a
|
|
146
126
|
# render from the JSON alone has them, and config's
|
|
147
127
|
# fingerprint.
|
|
148
128
|
def self.write_json(result, files, config)
|
|
149
129
|
report = PathsReport.of(result.paths, files)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
130
|
+
reached = @recorder.reached
|
|
131
|
+
cards = WithinMethods.listed(files, config, result, reached)
|
|
132
|
+
parts = {
|
|
133
|
+
totals: totals(result, files, config), outside: result.outside,
|
|
134
|
+
cards:, fingerprint: config.fingerprint, reached:
|
|
135
|
+
}
|
|
136
|
+
path = config.json_path
|
|
137
|
+
JsonWriter.write(result.operands, path, report, **parts)
|
|
155
138
|
end
|
|
156
139
|
|
|
157
140
|
# The JSON report's totals, each [taken, possible] paths:
|
|
158
|
-
# within each decision, and
|
|
159
|
-
#
|
|
160
|
-
# own too, under groups.
|
|
141
|
+
# within each decision, and within each method; with groups
|
|
142
|
+
# configured, each group's own too, under groups.
|
|
161
143
|
def self.totals(result, files, config)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
totals = ConsoleSummary.totals(result.paths, methods, paths)
|
|
144
|
+
reached = @recorder.reached
|
|
145
|
+
cards = WithinMethods.cards(files, config, result.paths, reached)
|
|
146
|
+
totals = ConsoleSummary.totals(result.paths, cards)
|
|
166
147
|
groups = config.groups
|
|
167
148
|
return totals if groups.empty?
|
|
168
149
|
|
|
169
|
-
|
|
170
|
-
own = summary.group_totals(result.paths, methods, paths, groups)
|
|
150
|
+
own = ConsoleSummary.group_totals(result.paths, cards, groups)
|
|
171
151
|
totals.merge('groups' => own)
|
|
172
152
|
end
|
|
173
153
|
|
|
@@ -52,8 +52,9 @@ module PathCoverage
|
|
|
52
52
|
'partition' => ALWAYS,
|
|
53
53
|
'take_while' => lambda do |items, answer|
|
|
54
54
|
next false if items == ITEMS[0]
|
|
55
|
+
next answer if answer
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
items == ITEMS[1] ? false : nil
|
|
57
58
|
end
|
|
58
59
|
}.freeze
|
|
59
60
|
|
|
@@ -50,18 +50,21 @@ module PathCoverage
|
|
|
50
50
|
# matched holds the cells of each when before it, and a
|
|
51
51
|
# when's own are added.
|
|
52
52
|
def self.arm_node(source, arm, matched, (outcomes, leaves))
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
condition = arm.body
|
|
54
|
+
body = if condition
|
|
55
|
+
SiteTree.node(source, condition, outcomes, leaves)
|
|
56
|
+
end
|
|
55
57
|
matched << body[:cells].map { |cell| cell == true } if body
|
|
56
58
|
cells = body ? matched.last : unmatched(matched, outcomes)
|
|
57
59
|
text = SiteTree.text_of(source, arm)
|
|
58
60
|
{ arm: arm.kind, text:, cells:, body: }
|
|
59
61
|
end
|
|
60
62
|
|
|
61
|
-
# Whether each column matched none of its whens' patterns
|
|
63
|
+
# Whether each column matched none of its whens' patterns:
|
|
64
|
+
# a when's cell is true where it matched.
|
|
62
65
|
def self.unmatched(matched, outcomes)
|
|
63
66
|
outcomes.each_index.map do |column|
|
|
64
|
-
matched.
|
|
67
|
+
!matched.map { |taken| taken[column] }.include?(true)
|
|
65
68
|
end
|
|
66
69
|
end
|
|
67
70
|
|
|
@@ -52,15 +52,17 @@ module PathCoverage
|
|
|
52
52
|
receiver = inner.max_by { |site| site.extent.size }
|
|
53
53
|
return Block.items?(receiver, outcomes)
|
|
54
54
|
end
|
|
55
|
-
whole = inner.
|
|
55
|
+
whole = inner.to_h { |site| [site.extent, site] }[range]
|
|
56
56
|
whole && value_on(whole, outcomes, fixed)
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
# site's value on its way that took outcomes, one of its
|
|
60
|
-
# own, nil when its kind cannot tell.
|
|
60
|
+
# own, nil when its kind cannot tell. outcomes always hold
|
|
61
|
+
# one of site's ways, so one is always found.
|
|
61
62
|
def self.value_on(site, outcomes, fixed)
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
SitePaths.walk(site, fixed).each do |more, value|
|
|
64
|
+
return value if more <= outcomes
|
|
65
|
+
end
|
|
64
66
|
end
|
|
65
67
|
|
|
66
68
|
# Its value in each column: the leaf's own, its last operand.
|
|
@@ -44,9 +44,11 @@ module PathCoverage
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
# Its value in each column: false where a receiver was nil,
|
|
47
|
-
# as the chain then gives nil, else its last leaf's.
|
|
47
|
+
# as the chain then gives nil, else its last leaf's. Only the
|
|
48
|
+
# chain's end, after its last leaf, can be a node only
|
|
49
|
+
# called, so it alone is left out.
|
|
48
50
|
def self.value(_operator, operands)
|
|
49
|
-
leaves = operands.
|
|
51
|
+
leaves = operands.last[:called] ? operands[0...-1] : operands
|
|
50
52
|
columns = leaves.map { |operand| operand[:cells] }.transpose
|
|
51
53
|
columns.map do |column|
|
|
52
54
|
column.include?(PRESENCE[1]) ? false : column.last
|
|
@@ -142,7 +144,7 @@ module PathCoverage
|
|
|
142
144
|
# is reached only when the one before is not nil.
|
|
143
145
|
def self.rows(chain, indent)
|
|
144
146
|
chain[:operands].each_with_index.map do |operand, depth|
|
|
145
|
-
branch = "#{indent}#{
|
|
147
|
+
branch = "#{indent}#{HtmlBranch::GAP * depth}#{HtmlBranch::ELL}"
|
|
146
148
|
HtmlTree.operand_row(operand, branch)
|
|
147
149
|
end
|
|
148
150
|
end
|
|
@@ -236,7 +236,8 @@ module PathCoverage
|
|
|
236
236
|
def grouped(operand)
|
|
237
237
|
return operand unless operand.type == :parentheses_node
|
|
238
238
|
|
|
239
|
-
|
|
239
|
+
body = operand.body
|
|
240
|
+
statements = body ? body.body : []
|
|
240
241
|
statements.size == 1 ? statements.first : operand
|
|
241
242
|
end
|
|
242
243
|
end
|
|
@@ -20,11 +20,10 @@ module PathCoverage
|
|
|
20
20
|
plain_call?(node) && value?(block_expression(node.block))
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
# True for a call on a receiver, with no arguments
|
|
24
|
-
#
|
|
23
|
+
# True for a call on a receiver, with no arguments. A call by
|
|
24
|
+
# &. never gets here, as it is a site of its own first.
|
|
25
25
|
def plain_call?(node)
|
|
26
|
-
!node.receiver.nil? && node.arguments.nil?
|
|
27
|
-
!node.safe_navigation?
|
|
26
|
+
!node.receiver.nil? && node.arguments.nil?
|
|
28
27
|
end
|
|
29
28
|
|
|
30
29
|
# True for a block's one expression that is a value, so can
|
|
@@ -13,9 +13,8 @@ module PathCoverage
|
|
|
13
13
|
def case_site?(node)
|
|
14
14
|
return false if node.predicate.nil?
|
|
15
15
|
|
|
16
|
-
node.conditions.
|
|
17
|
-
|
|
18
|
-
end
|
|
16
|
+
patterns = node.conditions.flat_map(&:conditions)
|
|
17
|
+
!patterns.map(&:type).include?(:splat_node)
|
|
19
18
|
end
|
|
20
19
|
|
|
21
20
|
# A case as a Condition, its extent its case keyword to the
|
|
@@ -117,10 +117,11 @@ module PathCoverage
|
|
|
117
117
|
Arm.new(kind:, extent:, body:)
|
|
118
118
|
end
|
|
119
119
|
|
|
120
|
-
# True for a condition that folds into a ternary's site:
|
|
121
|
-
#
|
|
120
|
+
# True for a condition that folds into a ternary's site: a
|
|
121
|
+
# ternary, never ignored, as the ternary it folds into is
|
|
122
|
+
# not; or an &&, ||, and or or not ignored.
|
|
122
123
|
def foldable?(node)
|
|
123
|
-
|
|
124
|
+
ternary?(node) || (operator?(node) && !ignored?(node))
|
|
124
125
|
end
|
|
125
126
|
|
|
126
127
|
# True for a ternary, an if with no if keyword.
|
|
@@ -70,7 +70,7 @@ module PathCoverage
|
|
|
70
70
|
|
|
71
71
|
receiver = extent_of(grouped(node.receiver))
|
|
72
72
|
@nonempty.include?(node.name.to_s) &&
|
|
73
|
-
inner.
|
|
73
|
+
inner.map(&:extent).include?(receiver)
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
# A block's body is a new scope: it runs once per item.
|
data/lib/path_coverage/merge.rb
CHANGED
|
@@ -28,11 +28,11 @@ module PathCoverage
|
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
# One
|
|
32
|
-
#
|
|
31
|
+
# One listed hash, { site => { path => count } }, eg the
|
|
32
|
+
# paths a treatment rules out, each path's count the sum of
|
|
33
33
|
# every run's, eg [true, false] taken once in each of two
|
|
34
34
|
# runs is taken twice.
|
|
35
|
-
def self.
|
|
35
|
+
def self.listed(runs)
|
|
36
36
|
runs.reduce do |total, run|
|
|
37
37
|
total.merge(run) do |_site, mine, theirs|
|
|
38
38
|
mine.merge(theirs) { |_path, a, b| a + b }
|