path_coverage 0.1.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 +315 -107
- data/lib/path_coverage/calls.rb +55 -23
- data/lib/path_coverage/card.rb +14 -0
- data/lib/path_coverage/condition.rb +33 -3
- data/lib/path_coverage/configuration.rb +43 -22
- data/lib/path_coverage/configuration_paths.rb +58 -0
- data/lib/path_coverage/console_summary.rb +75 -0
- data/lib/path_coverage/gaps.rb +32 -13
- data/lib/path_coverage/html/file.html +5 -5
- data/lib/path_coverage/html/index.html +6 -18
- data/lib/path_coverage/html/settings.js +50 -0
- data/lib/path_coverage/html/side.js +341 -413
- data/lib/path_coverage/html/sort.js +24 -21
- data/lib/path_coverage/html/style.css +339 -207
- data/lib/path_coverage/html/tabs.js +15 -0
- 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 +95 -41
- data/lib/path_coverage/html_index_head.rb +29 -0
- 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 +69 -56
- data/lib/path_coverage/html_statements.rb +166 -0
- data/lib/path_coverage/html_syntax.rb +156 -0
- data/lib/path_coverage/html_tabs.rb +26 -0
- data/lib/path_coverage/html_template.rb +6 -0
- data/lib/path_coverage/html_tree.rb +59 -74
- data/lib/path_coverage/json_reader.rb +101 -0
- data/lib/path_coverage/json_writer.rb +52 -7
- data/lib/path_coverage/kernel.rb +55 -53
- data/lib/path_coverage/kinds/base.rb +71 -0
- data/lib/path_coverage/kinds/block.rb +137 -0
- data/lib/path_coverage/kinds/case.rb +92 -0
- data/lib/path_coverage/kinds/chain.rb +45 -0
- data/lib/path_coverage/kinds/choice.rb +68 -0
- data/lib/path_coverage/kinds/contains.rb +113 -0
- data/lib/path_coverage/kinds/safe.rb +153 -0
- data/lib/path_coverage/kinds/write.rb +54 -0
- data/lib/path_coverage/kinds.rb +37 -0
- data/lib/path_coverage/manifest.rb +60 -20
- data/lib/path_coverage/manifest_blocks.rb +48 -10
- data/lib/path_coverage/manifest_case.rb +2 -3
- data/lib/path_coverage/manifest_chains.rb +76 -0
- data/lib/path_coverage/manifest_choices.rb +32 -18
- data/lib/path_coverage/manifest_folding.rb +91 -0
- data/lib/path_coverage/manifest_ignoring.rb +35 -0
- data/lib/path_coverage/manifest_writes.rb +67 -0
- data/lib/path_coverage/merge.rb +19 -3
- data/lib/path_coverage/method_statements.rb +300 -0
- data/lib/path_coverage/post.rb +8 -8
- data/lib/path_coverage/recorder.rb +20 -79
- data/lib/path_coverage/recorder_blocks.rb +68 -0
- data/lib/path_coverage/recorder_cases.rb +23 -0
- data/lib/path_coverage/recorder_chains.rb +40 -0
- data/lib/path_coverage/recorder_writes.rb +26 -0
- data/lib/path_coverage/render.rb +56 -47
- data/lib/path_coverage/result.rb +19 -0
- data/lib/path_coverage/rewriter.rb +69 -107
- data/lib/path_coverage/rewriter_nested.rb +62 -0
- data/lib/path_coverage/site_paths.rb +9 -58
- data/lib/path_coverage/site_tree.rb +21 -57
- data/lib/path_coverage/statement_arms.rb +161 -0
- data/lib/path_coverage/summary.rb +41 -17
- 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 +40 -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,4 +1,5 @@
|
|
|
1
1
|
require_relative 'condition'
|
|
2
|
+
require_relative 'kinds'
|
|
2
3
|
|
|
3
4
|
module PathCoverage
|
|
4
5
|
# The tree shown under a site's line on its file's page: a
|
|
@@ -12,36 +13,43 @@ module PathCoverage
|
|
|
12
13
|
# an arm { arm:, text:, cells:, body: } whether the column
|
|
13
14
|
# took it, body being its condition's tree, nil for a plain
|
|
14
15
|
# arm. Texts are cut from source at the manifest's ranges.
|
|
16
|
+
# An elsif's tree is labelled elsif, as it is written.
|
|
15
17
|
def self.of(source, condition, paths)
|
|
16
18
|
columns = paths.sort_by.with_index do |taken, i|
|
|
17
19
|
[taken[:count].zero? ? 0 : 1, i]
|
|
18
20
|
end
|
|
19
21
|
outcomes = columns.map { |taken| taken[:path] }
|
|
20
22
|
tree = node(source, condition, outcomes, (0..).each)
|
|
23
|
+
tree = tree.merge(label: 'elsif') if elsif?(source, condition)
|
|
21
24
|
tree.merge(counts: columns.map { |taken| taken[:count] })
|
|
22
25
|
end
|
|
23
26
|
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
def self.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
# True for an if site written as an elsif: an if's extent
|
|
28
|
+
# starts at its keyword.
|
|
29
|
+
def self.elsif?(source, condition)
|
|
30
|
+
condition.operator == 'if' &&
|
|
31
|
+
source.byteslice(condition.extent.begin, 5) == 'elsif'
|
|
32
|
+
end
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
# The tree of condition, as its kind builds it, each leaf
|
|
35
|
+
# taking the next index of leaves, so leaves pair with path
|
|
36
|
+
# entries left to right.
|
|
37
|
+
def self.node(source, condition, outcomes, leaves)
|
|
38
|
+
kind = Kinds.of(condition.operator)
|
|
39
|
+
kind.node(source, condition, outcomes, leaves)
|
|
33
40
|
end
|
|
34
41
|
|
|
35
42
|
# condition's operands' nodes, leaves and nested conditions
|
|
36
43
|
# built in order, its arms left for arms to build after.
|
|
37
44
|
def self.operands_of(source, condition, outcomes, leaves)
|
|
38
|
-
condition.operands.map do |operand|
|
|
45
|
+
nodes = condition.operands.map do |operand|
|
|
39
46
|
case operand
|
|
40
47
|
when Condition then node(source, operand, outcomes, leaves)
|
|
41
48
|
when Arm then operand
|
|
42
49
|
else leaf(source, operand, outcomes, leaves.next)
|
|
43
50
|
end
|
|
44
51
|
end
|
|
52
|
+
Kinds.of(condition.operator).texted(source, condition, nodes)
|
|
45
53
|
end
|
|
46
54
|
|
|
47
55
|
# condition's node from its operands' nodes, its ternary
|
|
@@ -55,36 +63,14 @@ module PathCoverage
|
|
|
55
63
|
decided = [predicate[:cells], THEN_ON[condition.operator]]
|
|
56
64
|
arm(source, operand, decided, outcomes, leaves)
|
|
57
65
|
end
|
|
58
|
-
|
|
66
|
+
operator = condition.operator
|
|
67
|
+
cells = Kinds.of(operator).value(operator, operands)
|
|
59
68
|
{ operator: condition.operator, cells:, operands: }
|
|
60
69
|
end
|
|
61
70
|
|
|
62
|
-
# A case's node from its arms, built in order so its whens'
|
|
63
|
-
# patterns pair with path entries left to right: a when is
|
|
64
|
-
# taken on each path one of its patterns matched, and the
|
|
65
|
-
# else on each none did. A case's value is that of no
|
|
66
|
-
# choice, so is nil.
|
|
67
|
-
def self.case_arms(source, arms, outcomes, leaves)
|
|
68
|
-
matched = []
|
|
69
|
-
operands = arms.map do |arm|
|
|
70
|
-
body = arm.body && node(source, arm.body, outcomes, leaves)
|
|
71
|
-
matched << body[:cells].map { |cell| cell == true } if body
|
|
72
|
-
cells = body ? matched.last : unmatched(matched, outcomes)
|
|
73
|
-
{ arm: arm.kind, text: text_of(source, arm), cells:, body: }
|
|
74
|
-
end
|
|
75
|
-
{ operator: 'case', cells: Array.new(outcomes.size), operands: }
|
|
76
|
-
end
|
|
77
|
-
|
|
78
71
|
# An arm's text, nil for one with no statements.
|
|
79
72
|
def self.text_of(source, arm)
|
|
80
|
-
arm.extent
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
# Whether each column matched none of its whens' patterns.
|
|
84
|
-
def self.unmatched(matched, outcomes)
|
|
85
|
-
outcomes.each_index.map do |column|
|
|
86
|
-
matched.none? { |taken| taken[column] }
|
|
87
|
-
end
|
|
73
|
+
arm.extent ? source.byteslice(arm.extent) : nil
|
|
88
74
|
end
|
|
89
75
|
|
|
90
76
|
# One arm of a ternary, an if or an unless: its text, nil
|
|
@@ -94,35 +80,13 @@ module PathCoverage
|
|
|
94
80
|
# condition.
|
|
95
81
|
def self.arm(source, arm, (decided, then_on), outcomes, leaves)
|
|
96
82
|
picked = arm.kind == :then ? then_on : !then_on
|
|
97
|
-
body = arm.body
|
|
83
|
+
body = arm.body ? node(source, arm.body, outcomes, leaves) : nil
|
|
98
84
|
{
|
|
99
85
|
arm: arm.kind, text: text_of(source, arm),
|
|
100
86
|
cells: decided.map { |outcome| outcome == picked }, body:
|
|
101
87
|
}
|
|
102
88
|
end
|
|
103
89
|
|
|
104
|
-
# A condition's value in each column: a ternary's or an
|
|
105
|
-
# if's is its taken arm's body's, nil for a plain arm; a
|
|
106
|
-
# chain's is that of the last operand it reached.
|
|
107
|
-
def self.value(operator, operands)
|
|
108
|
-
if CHOICES.include?(operator)
|
|
109
|
-
_, *arms = operands
|
|
110
|
-
arms.map { |arm| arm[:body]&.fetch(:cells) }
|
|
111
|
-
.then { |bodies| ternary_value(arms, bodies) }
|
|
112
|
-
else
|
|
113
|
-
operands.map { |operand| operand[:cells] }
|
|
114
|
-
.transpose.map { |column| column.compact.last }
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
# Each column's value from the arm it took.
|
|
119
|
-
def self.ternary_value(arms, bodies)
|
|
120
|
-
arms.first[:cells].each_index.map do |column|
|
|
121
|
-
taken = arms.index { |arm| arm[:cells][column] }
|
|
122
|
-
taken && bodies[taken]&.fetch(column)
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
90
|
# One leaf's text and its outcome in each column.
|
|
127
91
|
def self.leaf(source, range, outcomes, index)
|
|
128
92
|
{
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
module PathCoverage
|
|
2
|
+
# The lists of statements a method's card has rows for: a def's
|
|
3
|
+
# body, the arms of each site in it whose arms are statements,
|
|
4
|
+
# and the body of each block in it, as the card lays them out
|
|
5
|
+
# flat. It relies on its includer's rows_in, site? and
|
|
6
|
+
# site_name.
|
|
7
|
+
module StatementArms
|
|
8
|
+
# The nodes a statement's sites are never looked for in: a
|
|
9
|
+
# block's, a lambda's and a begin's statements are rows of
|
|
10
|
+
# their own, after the statement holding them, and a def's
|
|
11
|
+
# body runs only when it is called, its sites rows of its own
|
|
12
|
+
# card.
|
|
13
|
+
UNSEEN = %i[block_node begin_node def_node lambda_node].freeze
|
|
14
|
+
|
|
15
|
+
# Example: return a ? 1 : 2 if x gives the ?:.
|
|
16
|
+
# The sites inside site that are sites of their own, in the
|
|
17
|
+
# order they are written: in its leaves, eg a modifier if's
|
|
18
|
+
# arm or a &. call's receiver; not in its arms of statements,
|
|
19
|
+
# nor in a body, which have rows of their own. A site is
|
|
20
|
+
# named where it starts, so a node starting where a site
|
|
21
|
+
# does, eg a ?:'s predicate, names that site: each is kept
|
|
22
|
+
# once, and site itself not at all. None for a top that is no
|
|
23
|
+
# site, eg a def inside a def, whose sites are on its own card.
|
|
24
|
+
def inner_sites(site)
|
|
25
|
+
return [] unless site?(site)
|
|
26
|
+
|
|
27
|
+
found = heads(site).flat_map { sites_within(_1) }
|
|
28
|
+
named = found.to_h { [site_name(_1), _1] }
|
|
29
|
+
named.except(site_name(site)).values
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# node when it is a site, then each site within it, in
|
|
33
|
+
# order; none in a body or a def.
|
|
34
|
+
def sites_within(node)
|
|
35
|
+
return [] if UNSEEN.include?(node.type)
|
|
36
|
+
|
|
37
|
+
own = site?(node) ? [node] : []
|
|
38
|
+
own + heads(node).flat_map { sites_within(_1) }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Example: items.map { |i| i.price } gives the price row.
|
|
42
|
+
# The rows of the bodies in statement: of each block's and
|
|
43
|
+
# lambda's statements, a block method's included,
|
|
44
|
+
# as its block's sites are sites of their own, and a reach
|
|
45
|
+
# call before its one expression sits outside the
|
|
46
|
+
# expression's own record call; and of each begin's parts.
|
|
47
|
+
def body_rows(statement)
|
|
48
|
+
bodies_in(statement).flat_map do |body|
|
|
49
|
+
rows_in(statements_of(body))
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# The body of each block and lambda in node, run 0 or more
|
|
54
|
+
# times, and each begin: none inside an arm of statements or
|
|
55
|
+
# another body, whose rows are their own, nor in a def, whose
|
|
56
|
+
# rows are its own card's.
|
|
57
|
+
def bodies_in(node)
|
|
58
|
+
case node.type
|
|
59
|
+
when :def_node then []
|
|
60
|
+
when :block_node, :lambda_node then [node.body]
|
|
61
|
+
when :begin_node then [node]
|
|
62
|
+
else heads(node).flat_map { bodies_in(_1) }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# node's children outside its arms of statements: all of
|
|
67
|
+
# them for a node with none, else its predicate, and a
|
|
68
|
+
# case's patterns too.
|
|
69
|
+
def heads(node)
|
|
70
|
+
return node.compact_child_nodes if arms_of(node).empty?
|
|
71
|
+
return [node.predicate] unless node.type == :case_node
|
|
72
|
+
|
|
73
|
+
[node.predicate, *node.conditions.flat_map(&:conditions)]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# The statements of node's arms, then's before else's; none
|
|
77
|
+
# when node has no arms of statements, as a modifier's arm,
|
|
78
|
+
# and a ?:'s, are part of the site's own expression.
|
|
79
|
+
def arms_of(node)
|
|
80
|
+
case node.type
|
|
81
|
+
when :if_node then if_arms(node)
|
|
82
|
+
when :unless_node then unless_arms(node)
|
|
83
|
+
when :case_node then case_arms(node)
|
|
84
|
+
else []
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# A case's arms' statements: each when's in turn, then its
|
|
89
|
+
# else's.
|
|
90
|
+
def case_arms(node)
|
|
91
|
+
whens = node.conditions.flat_map do |clause|
|
|
92
|
+
statements_of(clause.statements)
|
|
93
|
+
end
|
|
94
|
+
whens + else_arms(node.else_clause)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# An if's arms' statements, an elsif standing as a statement
|
|
98
|
+
# of its if's else; none for a ?: or a modifier if.
|
|
99
|
+
def if_arms(node)
|
|
100
|
+
return [] if node.if_keyword_loc.nil? || then_first?(node)
|
|
101
|
+
|
|
102
|
+
statements_of(node.statements) + else_arms(node.subsequent)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# An unless's arms' statements; none for a modifier unless.
|
|
106
|
+
def unless_arms(node)
|
|
107
|
+
return [] if then_first?(node)
|
|
108
|
+
|
|
109
|
+
statements_of(node.statements) + else_arms(node.else_clause)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# True for an if or unless whose then arm is written before
|
|
113
|
+
# its predicate: a modifier, eg x if y.
|
|
114
|
+
def then_first?(node)
|
|
115
|
+
statements = node.statements
|
|
116
|
+
return false if statements.nil?
|
|
117
|
+
|
|
118
|
+
predicate = node.predicate.location.start_offset
|
|
119
|
+
statements.location.start_offset < predicate
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# The statements of an if's else, an elsif as one of them,
|
|
123
|
+
# none for none.
|
|
124
|
+
def else_arms(node)
|
|
125
|
+
return [node] if node&.type == :if_node
|
|
126
|
+
|
|
127
|
+
clause_statements(node)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# The statements of clause, an else or an ensure; none for
|
|
131
|
+
# none.
|
|
132
|
+
def clause_statements(clause)
|
|
133
|
+
clause ? statements_of(clause.statements) : []
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# The top-level statements of a def's body, a block's, or an
|
|
137
|
+
# arm's; with a rescue, those of each part in turn.
|
|
138
|
+
def statements_of(body)
|
|
139
|
+
return begun(body) if body&.type == :begin_node
|
|
140
|
+
|
|
141
|
+
body ? body.body : []
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# A begin's statements, then each rescue's, as each runs when
|
|
145
|
+
# its exception is raised, its else's, run when none is, and
|
|
146
|
+
# its ensure's, run either way.
|
|
147
|
+
def begun(node)
|
|
148
|
+
statements_of(node.statements) + rescued(node.rescue_clause) +
|
|
149
|
+
clause_statements(node.else_clause) +
|
|
150
|
+
clause_statements(node.ensure_clause)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# The statements of clause, a rescue, then of each rescue
|
|
154
|
+
# after it; none for none.
|
|
155
|
+
def rescued(clause)
|
|
156
|
+
return [] if clause.nil?
|
|
157
|
+
|
|
158
|
+
statements_of(clause.statements) + rescued(clause.subsequent)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require_relative 'configuration'
|
|
1
2
|
require_relative 'totals'
|
|
2
3
|
|
|
3
4
|
module PathCoverage
|
|
@@ -6,42 +7,65 @@ module PathCoverage
|
|
|
6
7
|
module Summary
|
|
7
8
|
# One row per file that has sites in site_paths, as
|
|
8
9
|
# Result#paths gives them, in path order: its sites, and
|
|
9
|
-
# its decisions total
|
|
10
|
-
#
|
|
11
|
-
|
|
12
|
-
# methods are measured.
|
|
13
|
-
def self.files(site_paths, methods = {}, paths = nil)
|
|
10
|
+
# its decisions total, and its methods total, its defs' cards
|
|
11
|
+
# in cards, { def site => [taken, size] }, added up.
|
|
12
|
+
def self.files(site_paths, cards)
|
|
14
13
|
by_path = site_paths.group_by { |site, _| path_of(site) }
|
|
15
14
|
by_path.sort.map do |path, sites|
|
|
16
15
|
{
|
|
17
16
|
path:, sites: sites.size,
|
|
18
17
|
decisions: Totals.decisions(sites.to_h),
|
|
19
|
-
methods:
|
|
18
|
+
methods: methods_of(path, cards)
|
|
20
19
|
}
|
|
21
20
|
end
|
|
22
21
|
end
|
|
23
22
|
|
|
24
|
-
# The methods total of the file at path
|
|
25
|
-
#
|
|
26
|
-
def self.methods_of(path,
|
|
27
|
-
|
|
28
|
-
Totals.methods(own, paths)
|
|
23
|
+
# The methods total of the file at path, its defs' cards
|
|
24
|
+
# added up; [0, 0] for a file with no def.
|
|
25
|
+
def self.methods_of(path, cards)
|
|
26
|
+
Totals.methods(cards.select { |site, _| path_of(site) == path })
|
|
29
27
|
end
|
|
30
28
|
|
|
31
|
-
# The sum of each column over rows,
|
|
32
|
-
#
|
|
29
|
+
# The sum of each column over rows; no rows, as for a group
|
|
30
|
+
# no file is in, gives 0 sites and [0, 0] totals.
|
|
33
31
|
def self.total(rows)
|
|
34
|
-
methods = rows.map { |row| row[:methods] }
|
|
35
32
|
{
|
|
36
33
|
sites: rows.sum { |row| row[:sites] },
|
|
37
34
|
decisions: add(rows.map { |row| row[:decisions] }),
|
|
38
|
-
methods:
|
|
35
|
+
methods: add(rows.map { |row| row[:methods] })
|
|
39
36
|
}
|
|
40
37
|
end
|
|
41
38
|
|
|
42
|
-
# [
|
|
39
|
+
# [name, rows, total] for each of groups, { name => [glob,
|
|
40
|
+
# ...] }, in order: the rows whose path matches any of its
|
|
41
|
+
# globs, and their total. Then Ungrouped, the rows no group
|
|
42
|
+
# matches, when there are any.
|
|
43
|
+
def self.groups(rows, groups)
|
|
44
|
+
grouped = groups.map do |name, globs|
|
|
45
|
+
own = rows.select { |row| matches?(row[:path], globs) }
|
|
46
|
+
[name, own, total(own)]
|
|
47
|
+
end
|
|
48
|
+
every = groups.values.flatten
|
|
49
|
+
rest = rows.reject { |row| matches?(row[:path], every) }
|
|
50
|
+
return grouped if rest.empty?
|
|
51
|
+
|
|
52
|
+
grouped << ['Ungrouped', rest, total(rest)]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# True when path matches any of globs.
|
|
56
|
+
def self.matches?(path, globs)
|
|
57
|
+
globs.any? do |glob|
|
|
58
|
+
File.fnmatch?(glob, path, Configuration::GLOB_FLAGS)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# [taken, possible] pairs added together, eg [[1, 3], [2, 4]]
|
|
63
|
+
# gives [3, 7]; no pairs, as for a group no file is in, gives
|
|
64
|
+
# [0, 0].
|
|
43
65
|
def self.add(pairs)
|
|
44
|
-
pairs.
|
|
66
|
+
pairs.reduce([0, 0]) do |(taken, possible), (more, of)|
|
|
67
|
+
[taken + more, possible + of]
|
|
68
|
+
end
|
|
45
69
|
end
|
|
46
70
|
|
|
47
71
|
# The file a site is in: its name minus :line:column.
|
data/lib/path_coverage/totals.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require_relative 'path_gaps'
|
|
2
|
-
|
|
3
1
|
module PathCoverage
|
|
4
2
|
# The two coverage totals, each [taken, possible] paths over
|
|
5
3
|
# every covered file. They count the very paths the gap
|
|
@@ -13,16 +11,12 @@ module PathCoverage
|
|
|
13
11
|
[every.count { |each| each[:count].positive? }, every.size]
|
|
14
12
|
end
|
|
15
13
|
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
every = PathGaps.possible(method.decisions)
|
|
23
|
-
seen = paths.fetch(site, {})
|
|
24
|
-
[taken + every.count { |path| seen.key?(path) },
|
|
25
|
-
possible + every.size]
|
|
14
|
+
# Example: cards [4, 6] and [17, 21] give [21, 27].
|
|
15
|
+
# Paths within each method: cards is { def site => [taken,
|
|
16
|
+
# size] }, each method's card's paths taken of its size.
|
|
17
|
+
def self.methods(cards)
|
|
18
|
+
cards.values.reduce([0, 0]) do |(taken, possible), (more, of)|
|
|
19
|
+
[taken + more, possible + of]
|
|
26
20
|
end
|
|
27
21
|
end
|
|
28
22
|
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
require_relative 'html_cards'
|
|
2
|
+
require_relative 'html_statements'
|
|
3
|
+
require_relative 'method_statements'
|
|
4
|
+
require_relative 'source_lines'
|
|
5
|
+
|
|
6
|
+
module PathCoverage
|
|
7
|
+
# What is measured within each method of a covered file.
|
|
8
|
+
module WithinMethods
|
|
9
|
+
# Where each statement of the covered file at path, parsed
|
|
10
|
+
# as Manifest.parse gives it, that is no site is reached, as
|
|
11
|
+
# MethodStatements.reaches gives them.
|
|
12
|
+
def self.reaches(path, parsed, config)
|
|
13
|
+
source, sites = parsed.values_at(:source, :sites)
|
|
14
|
+
MethodStatements.reaches(source, config.relative(path), sites)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Example: { "k.rb:0:0" => [1, 2], "k.rb:1:0" => [2, 4] }.
|
|
18
|
+
# Each def's card total, [taken, size], in every file in
|
|
19
|
+
# files, { full path => {source:, sites:} }, from paths, as
|
|
20
|
+
# Result#paths gives them, and reached, as Recorder#reached
|
|
21
|
+
# does; and each file's top level's, its sites on no card,
|
|
22
|
+
# named for line 0, which no def is on.
|
|
23
|
+
def self.cards(files, config, paths, reached)
|
|
24
|
+
files.map do |full_path, parsed|
|
|
25
|
+
path = config.relative(full_path)
|
|
26
|
+
source, sites = parsed.values_at(:source, :sites)
|
|
27
|
+
top = MethodStatements.top_level(source, path, paths, sites)
|
|
28
|
+
MethodStatements.totals(source, path, paths, reached, sites)
|
|
29
|
+
.merge("#{path}:0:0" => top)
|
|
30
|
+
end.reduce({}, :merge)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Example: { "k.rb:1:0" => { "name" => "ship", "first" => 1,
|
|
34
|
+
# "last" => 3, "rows" => [{ "at" => "2:04", ... }] } }.
|
|
35
|
+
# Each card in every file in files, a def's and a top card's,
|
|
36
|
+
# as its page draws it, for the JSON report, so a reader
|
|
37
|
+
# finds a card's gap without the page; result a Result,
|
|
38
|
+
# reached as cards takes it.
|
|
39
|
+
def self.listed(files, config, result, reached)
|
|
40
|
+
files.map do |full_path, parsed|
|
|
41
|
+
path = config.relative(full_path)
|
|
42
|
+
listed_in(path, parsed, result.paths, reached)
|
|
43
|
+
.merge(listed_tops(path, parsed, result))
|
|
44
|
+
end.reduce({}, :merge)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# The top cards of the file at path, as its page draws them:
|
|
48
|
+
# each under the site of its first line's start, named for
|
|
49
|
+
# its scope, as listed gives them.
|
|
50
|
+
def self.listed_tops(path, parsed, result)
|
|
51
|
+
source, sites = parsed.values_at(:source, :sites)
|
|
52
|
+
lines = SourceLines.of(source, sites, result.operands)
|
|
53
|
+
scopes = HtmlCards.scopes(source)
|
|
54
|
+
HtmlCards.spans(path, parsed, lines).to_h do |span, rows|
|
|
55
|
+
site = "#{path}:#{span.begin}:0"
|
|
56
|
+
taken = rows.zip(MethodStatements.taken(rows, result.paths))
|
|
57
|
+
[site, card(site, scopes[span.begin], span.end, taken)]
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# The cards of the file at path, parsed as Manifest.parse
|
|
62
|
+
# gives it, as listed gives them.
|
|
63
|
+
def self.listed_in(path, parsed, paths, reached)
|
|
64
|
+
source, sites = parsed.values_at(:source, :sites)
|
|
65
|
+
names = MethodStatements.names(source, path, sites)
|
|
66
|
+
lasts = MethodStatements.lasts(source, path, sites)
|
|
67
|
+
MethodStatements.of(source, path, sites).to_h do |site, rows|
|
|
68
|
+
taken = MethodStatements.taken(rows, paths, reached)
|
|
69
|
+
[site, card(site, names[site], lasts[site], rows.zip(taken))]
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# The card of the def at site named name, ending on line
|
|
74
|
+
# last: its first line, from site, and a row for each
|
|
75
|
+
# [statement, taken] of rows.
|
|
76
|
+
def self.card(site, name, last, rows)
|
|
77
|
+
first = Integer(site.split(':')[-2])
|
|
78
|
+
listed = rows.map { |statement, count| row(statement, count) }
|
|
79
|
+
{ 'name' => name, 'first' => first, 'last' => last,
|
|
80
|
+
'rows' => listed }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# A card's row: statement's line:column, as its page labels
|
|
84
|
+
# it, its top, its paths, count, how many were taken, and
|
|
85
|
+
# its site, nil for a statement that is no site.
|
|
86
|
+
def self.row(statement, count)
|
|
87
|
+
{ 'at' => HtmlStatements.label(statement),
|
|
88
|
+
'top' => statement.top, 'paths' => statement.paths,
|
|
89
|
+
'taken' => count, 'site' => statement.site }
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: path_coverage
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jon Jagger
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: prism
|
|
@@ -26,7 +25,6 @@ dependencies:
|
|
|
26
25
|
version: '1.0'
|
|
27
26
|
description: Records which paths each condition and each method took, and reports
|
|
28
27
|
the paths never taken in the terminal and as HTML.
|
|
29
|
-
email:
|
|
30
28
|
executables:
|
|
31
29
|
- path_coverage_collector
|
|
32
30
|
extensions: []
|
|
@@ -38,51 +36,83 @@ files:
|
|
|
38
36
|
- lib/path_coverage.rb
|
|
39
37
|
- lib/path_coverage/auto.rb
|
|
40
38
|
- lib/path_coverage/calls.rb
|
|
39
|
+
- lib/path_coverage/card.rb
|
|
41
40
|
- lib/path_coverage/collector.rb
|
|
42
41
|
- lib/path_coverage/condition.rb
|
|
43
42
|
- lib/path_coverage/configuration.rb
|
|
43
|
+
- lib/path_coverage/configuration_paths.rb
|
|
44
|
+
- lib/path_coverage/console_summary.rb
|
|
44
45
|
- lib/path_coverage/gaps.rb
|
|
45
46
|
- lib/path_coverage/html/file.html
|
|
46
47
|
- lib/path_coverage/html/index.html
|
|
48
|
+
- lib/path_coverage/html/settings.js
|
|
47
49
|
- lib/path_coverage/html/side.js
|
|
48
50
|
- lib/path_coverage/html/sort.js
|
|
49
51
|
- lib/path_coverage/html/style.css
|
|
50
|
-
- lib/path_coverage/html/
|
|
52
|
+
- lib/path_coverage/html/tabs.js
|
|
53
|
+
- lib/path_coverage/html/theme.js
|
|
54
|
+
- lib/path_coverage/html_branch.rb
|
|
55
|
+
- lib/path_coverage/html_cards.rb
|
|
56
|
+
- lib/path_coverage/html_cells.rb
|
|
51
57
|
- lib/path_coverage/html_file.rb
|
|
52
58
|
- lib/path_coverage/html_index.rb
|
|
59
|
+
- lib/path_coverage/html_index_head.rb
|
|
60
|
+
- lib/path_coverage/html_labels.rb
|
|
61
|
+
- lib/path_coverage/html_methods.rb
|
|
53
62
|
- lib/path_coverage/html_nav.rb
|
|
54
|
-
- lib/path_coverage/html_paths.rb
|
|
55
63
|
- lib/path_coverage/html_report.rb
|
|
64
|
+
- lib/path_coverage/html_statements.rb
|
|
65
|
+
- lib/path_coverage/html_syntax.rb
|
|
66
|
+
- lib/path_coverage/html_tabs.rb
|
|
56
67
|
- lib/path_coverage/html_template.rb
|
|
57
68
|
- lib/path_coverage/html_tree.rb
|
|
69
|
+
- lib/path_coverage/json_reader.rb
|
|
58
70
|
- lib/path_coverage/json_writer.rb
|
|
59
71
|
- lib/path_coverage/kernel.rb
|
|
72
|
+
- lib/path_coverage/kinds.rb
|
|
73
|
+
- lib/path_coverage/kinds/base.rb
|
|
74
|
+
- lib/path_coverage/kinds/block.rb
|
|
75
|
+
- lib/path_coverage/kinds/case.rb
|
|
76
|
+
- lib/path_coverage/kinds/chain.rb
|
|
77
|
+
- lib/path_coverage/kinds/choice.rb
|
|
78
|
+
- lib/path_coverage/kinds/contains.rb
|
|
79
|
+
- lib/path_coverage/kinds/safe.rb
|
|
80
|
+
- lib/path_coverage/kinds/write.rb
|
|
60
81
|
- lib/path_coverage/manifest.rb
|
|
61
82
|
- lib/path_coverage/manifest_blocks.rb
|
|
62
83
|
- lib/path_coverage/manifest_case.rb
|
|
84
|
+
- lib/path_coverage/manifest_chains.rb
|
|
63
85
|
- lib/path_coverage/manifest_choices.rb
|
|
86
|
+
- lib/path_coverage/manifest_folding.rb
|
|
87
|
+
- lib/path_coverage/manifest_ignoring.rb
|
|
88
|
+
- lib/path_coverage/manifest_writes.rb
|
|
64
89
|
- lib/path_coverage/merge.rb
|
|
65
|
-
- lib/path_coverage/
|
|
66
|
-
- lib/path_coverage/path_manifest.rb
|
|
90
|
+
- lib/path_coverage/method_statements.rb
|
|
67
91
|
- lib/path_coverage/paths_report.rb
|
|
68
92
|
- lib/path_coverage/post.rb
|
|
69
93
|
- lib/path_coverage/recorder.rb
|
|
94
|
+
- lib/path_coverage/recorder_blocks.rb
|
|
95
|
+
- lib/path_coverage/recorder_cases.rb
|
|
96
|
+
- lib/path_coverage/recorder_chains.rb
|
|
97
|
+
- lib/path_coverage/recorder_writes.rb
|
|
70
98
|
- lib/path_coverage/render.rb
|
|
71
99
|
- lib/path_coverage/result.rb
|
|
72
100
|
- lib/path_coverage/rewriter.rb
|
|
101
|
+
- lib/path_coverage/rewriter_nested.rb
|
|
73
102
|
- lib/path_coverage/site.rb
|
|
74
103
|
- lib/path_coverage/site_paths.rb
|
|
75
104
|
- lib/path_coverage/site_tree.rb
|
|
76
105
|
- lib/path_coverage/source_lines.rb
|
|
106
|
+
- lib/path_coverage/statement_arms.rb
|
|
77
107
|
- lib/path_coverage/summary.rb
|
|
78
108
|
- lib/path_coverage/totals.rb
|
|
79
109
|
- lib/path_coverage/version.rb
|
|
110
|
+
- lib/path_coverage/within_methods.rb
|
|
80
111
|
homepage: https://github.com/cyber-dojo/path_coverage
|
|
81
112
|
licenses:
|
|
82
113
|
- BSD-2-Clause
|
|
83
114
|
metadata:
|
|
84
115
|
rubygems_mfa_required: 'true'
|
|
85
|
-
post_install_message:
|
|
86
116
|
rdoc_options: []
|
|
87
117
|
require_paths:
|
|
88
118
|
- lib
|
|
@@ -97,8 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
97
127
|
- !ruby/object:Gem::Version
|
|
98
128
|
version: '0'
|
|
99
129
|
requirements: []
|
|
100
|
-
rubygems_version:
|
|
101
|
-
signing_key:
|
|
130
|
+
rubygems_version: 4.0.23
|
|
102
131
|
specification_version: 4
|
|
103
132
|
summary: Path coverage for Ruby, alongside SimpleCov branch coverage
|
|
104
133
|
test_files: []
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Opens and closes the tree a line-number button names in its
|
|
2
|
-
// aria-controls, keeping aria-expanded in step.
|
|
3
|
-
(function () {
|
|
4
|
-
document.querySelectorAll('button[aria-controls]').forEach(function (button) {
|
|
5
|
-
button.addEventListener('click', function () {
|
|
6
|
-
var tree = document.getElementById(button.getAttribute('aria-controls'));
|
|
7
|
-
var open = button.getAttribute('aria-expanded') === 'true';
|
|
8
|
-
button.setAttribute('aria-expanded', open ? 'false' : 'true');
|
|
9
|
-
tree.hidden = open;
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
})();
|