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,46 +4,49 @@ require_relative 'totals'
|
|
|
4
4
|
module PathCoverage
|
|
5
5
|
# The :summary reporter's lines: each total as SimpleCov prints
|
|
6
6
|
# its line and branch coverage, eg
|
|
7
|
-
# "
|
|
7
|
+
# "Paths alone: 519 / 623 (83.31%)". With
|
|
8
8
|
# groups configured each group is a heading, its own totals
|
|
9
9
|
# indented under it, and there is no total over every group.
|
|
10
10
|
module ConsoleSummary
|
|
11
|
-
# The summary lines of
|
|
12
|
-
#
|
|
13
|
-
# methods are measured, of
|
|
11
|
+
# The summary lines of decision_paths and, when flows, { def
|
|
12
|
+
# decision => [taken, size] }, are given, as they are when
|
|
13
|
+
# methods are measured, of flows; groups is { name =>
|
|
14
14
|
# [glob, ...] }.
|
|
15
|
-
def self.lines(
|
|
16
|
-
|
|
15
|
+
def self.lines(decision_paths, flows, groups = {})
|
|
16
|
+
if groups.empty?
|
|
17
|
+
return totals_lines(totals(decision_paths,
|
|
18
|
+
flows))
|
|
19
|
+
end
|
|
17
20
|
|
|
18
|
-
all = group_totals(
|
|
21
|
+
all = group_totals(decision_paths, flows, groups)
|
|
19
22
|
all.flat_map do |name, totals|
|
|
20
23
|
["#{name}:", *totals_lines(totals).map { |line| " #{line}" }]
|
|
21
24
|
end
|
|
22
25
|
end
|
|
23
26
|
|
|
24
|
-
# { '
|
|
25
|
-
# '
|
|
26
|
-
def self.totals(
|
|
27
|
-
totals = { '
|
|
28
|
-
return totals if
|
|
27
|
+
# { 'alone' => [taken, possible] } of decision_paths, with
|
|
28
|
+
# 'combined' => [taken, possible] of flows when given.
|
|
29
|
+
def self.totals(decision_paths, flows)
|
|
30
|
+
totals = { 'alone' => Totals.alone(decision_paths) }
|
|
31
|
+
return totals if flows.nil?
|
|
29
32
|
|
|
30
|
-
totals.merge('
|
|
33
|
+
totals.merge('combined' => Totals.combined(flows))
|
|
31
34
|
end
|
|
32
35
|
|
|
33
|
-
# { group name => totals } of each group's own
|
|
34
|
-
#
|
|
35
|
-
def self.group_totals(
|
|
36
|
+
# { group name => totals } of each group's own decisions and
|
|
37
|
+
# flows alone.
|
|
38
|
+
def self.group_totals(decision_paths, flows, groups)
|
|
36
39
|
groups.to_h do |name, globs|
|
|
37
|
-
|
|
38
|
-
[name, totals(own(
|
|
40
|
+
own_flows = flows ? own(flows, globs) : nil
|
|
41
|
+
[name, totals(own(decision_paths, globs), own_flows)]
|
|
39
42
|
end
|
|
40
43
|
end
|
|
41
44
|
|
|
42
|
-
# The entries of
|
|
43
|
-
# any of globs.
|
|
44
|
-
def self.own(
|
|
45
|
-
|
|
46
|
-
Summary.matches?(Summary.path_of(
|
|
45
|
+
# The entries of decisions, keyed by decision name, in a file
|
|
46
|
+
# matching any of globs.
|
|
47
|
+
def self.own(decisions, globs)
|
|
48
|
+
decisions.select do |decision, _|
|
|
49
|
+
Summary.matches?(Summary.path_of(decision), globs)
|
|
47
50
|
end
|
|
48
51
|
end
|
|
49
52
|
|
|
@@ -55,11 +58,10 @@ module PathCoverage
|
|
|
55
58
|
["Path coverage ignores: #{ignored.join(', ')}"]
|
|
56
59
|
end
|
|
57
60
|
|
|
58
|
-
# A line per total, eg "
|
|
59
|
-
# (25.00%)".
|
|
61
|
+
# A line per total, eg "Paths combined: 1 / 4 (25.00%)".
|
|
60
62
|
def self.totals_lines(totals)
|
|
61
63
|
totals.map do |name, pair|
|
|
62
|
-
"
|
|
64
|
+
"Paths #{name}: #{figure(pair)}"
|
|
63
65
|
end
|
|
64
66
|
end
|
|
65
67
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module PathCoverage
|
|
2
2
|
# Names a condition by where it starts in its file, so the
|
|
3
|
-
# rewriter and the manifest agree on which
|
|
4
|
-
module
|
|
3
|
+
# rewriter and the manifest agree on which decision is which.
|
|
4
|
+
module Decision
|
|
5
5
|
# "path:line:column" of node, eg "k.rb:2:2".
|
|
6
6
|
def self.of(path, node)
|
|
7
7
|
at(path, node.location)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require_relative 'condition'
|
|
2
|
+
|
|
3
|
+
module PathCoverage
|
|
4
|
+
# Where in its source each part of a decision's tree is, as
|
|
5
|
+
# [line, column, line, column], so a page can light the code
|
|
6
|
+
# a fold row stands for.
|
|
7
|
+
module DecisionLocations
|
|
8
|
+
# simplecov:disable
|
|
9
|
+
# SPIKE: tree with an at: of [line, column, line, column]
|
|
10
|
+
# on it and on each of its operands: a leaf's from its byte
|
|
11
|
+
# range, a condition's and an arm's from its extent, the
|
|
12
|
+
# whole of it as written. Columns count characters, not
|
|
13
|
+
# bytes. A node past the condition's operands, eg owner at
|
|
14
|
+
# the end of user&.account&.owner, is kept as it is.
|
|
15
|
+
def self.located(source, condition, tree)
|
|
16
|
+
pairs = condition.operands.zip(tree[:operands])
|
|
17
|
+
operands = pairs.map do |operand, node|
|
|
18
|
+
located_operand(source, operand, node)
|
|
19
|
+
end
|
|
20
|
+
rest = tree[:operands].drop(pairs.size)
|
|
21
|
+
tree.merge(at: at(source, condition.extent),
|
|
22
|
+
operands: operands + rest)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# SPIKE: the node of operand with its at:, as located gives
|
|
26
|
+
# a condition's, an arm's or a leaf's.
|
|
27
|
+
def self.located_operand(source, operand, node)
|
|
28
|
+
case operand
|
|
29
|
+
when Condition then located(source, operand, node)
|
|
30
|
+
when Arm then located_arm(source, operand, node)
|
|
31
|
+
else node.merge(at: at(source, operand))
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# An arm's node with its at:, nil for an arm with no
|
|
36
|
+
# statements, and its body's tree located.
|
|
37
|
+
def self.located_arm(source, arm, node)
|
|
38
|
+
body = arm.body ? located(source, arm.body, node[:body]) : nil
|
|
39
|
+
at = arm.extent ? at(source, arm.extent) : nil
|
|
40
|
+
node.merge(at:, body:)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# [line, column, line, column] of the byte range in source.
|
|
44
|
+
def self.at(source, range)
|
|
45
|
+
[*position(source, range.begin), *position(source, range.end)]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# [line, column] of a byte offset in source.
|
|
49
|
+
def self.position(source, offset)
|
|
50
|
+
before = source.byteslice(0, offset)
|
|
51
|
+
newline = before.rindex("\n")
|
|
52
|
+
column = before.length - (newline ? newline + 1 : 0)
|
|
53
|
+
[before.count("\n") + 1, column]
|
|
54
|
+
end
|
|
55
|
+
# simplecov:enable
|
|
56
|
+
|
|
57
|
+
# [line, column, line, column] of condition's else keyword in
|
|
58
|
+
# source, so hovering it can open condition's fold, as
|
|
59
|
+
# hovering its if does; nil for one with no else, or one whose
|
|
60
|
+
# else has no code, or a ?:, whose else is no keyword. The
|
|
61
|
+
# keyword is what comes just before its arm's code, so an
|
|
62
|
+
# elsif, or an else with a comment after it, has none.
|
|
63
|
+
def self.else_at(source, condition)
|
|
64
|
+
return nil if condition.operator == '?:'
|
|
65
|
+
|
|
66
|
+
arm = condition.operands.grep(Arm).to_h { [_1.kind, _1] }[:else]
|
|
67
|
+
extent = arm&.extent
|
|
68
|
+
return nil unless extent
|
|
69
|
+
|
|
70
|
+
start = source.b.byteslice(0, extent.begin) =~ /\belse\s*\z/
|
|
71
|
+
return nil unless start
|
|
72
|
+
|
|
73
|
+
at(source, start...(start + 4))
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -2,31 +2,33 @@ require_relative 'condition'
|
|
|
2
2
|
require_relative 'kinds'
|
|
3
3
|
|
|
4
4
|
module PathCoverage
|
|
5
|
-
# The paths an evaluation of a
|
|
5
|
+
# The paths an evaluation of a decision can take, worked out
|
|
6
6
|
# from its condition alone: the outcome of each leaf, in leaf
|
|
7
7
|
# order, nil for a leaf that evaluation never reaches.
|
|
8
|
-
module
|
|
9
|
-
# Every possible path through
|
|
10
|
-
# false, as its kind gives the ways a
|
|
8
|
+
module DecisionPaths
|
|
9
|
+
# Every possible path through decision's condition, true before
|
|
10
|
+
# false, as its kind gives the ways a decision of it can be
|
|
11
11
|
# evaluated.
|
|
12
|
-
def self.possible(
|
|
13
|
-
ways = Kinds.of(
|
|
12
|
+
def self.possible(decision)
|
|
13
|
+
ways = Kinds.of(decision.operator).root_ways(decision,
|
|
14
|
+
decision.fixed)
|
|
14
15
|
ways.map do |outcomes, _value|
|
|
15
|
-
|
|
16
|
+
decision.leaves.map { |range| outcomes[range] }
|
|
16
17
|
end
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
# Example: [false, true, false, true, false] for an any?.
|
|
20
|
-
#
|
|
21
|
+
# decision's value on each of its possible paths, in the order
|
|
21
22
|
# possible gives them, nil where not known.
|
|
22
|
-
def self.values(
|
|
23
|
-
ways = Kinds.of(
|
|
23
|
+
def self.values(decision)
|
|
24
|
+
ways = Kinds.of(decision.operator).root_ways(decision,
|
|
25
|
+
decision.fixed)
|
|
24
26
|
ways.map(&:last)
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
# [[{ leaf range => outcome }, value], ...] for each way
|
|
28
30
|
# node can be evaluated, value being the outcome of node as
|
|
29
|
-
# a whole, as its kind gives them; fixed is the
|
|
31
|
+
# a whole, as its kind gives them; fixed is the decision's
|
|
30
32
|
# { leaf range => its one outcome }.
|
|
31
33
|
def self.walk(node, fixed)
|
|
32
34
|
return leaf(node, fixed) unless node.is_a?(Condition)
|
|
@@ -2,10 +2,10 @@ require_relative 'condition'
|
|
|
2
2
|
require_relative 'kinds'
|
|
3
3
|
|
|
4
4
|
module PathCoverage
|
|
5
|
-
# The tree shown under a
|
|
6
|
-
# grid whose columns are the
|
|
7
|
-
module
|
|
8
|
-
# { operator:, counts:, cells:, operands: } for one
|
|
5
|
+
# The tree shown under a decision's line on its file's page: a
|
|
6
|
+
# grid whose columns are the decision's paths, never taken first.
|
|
7
|
+
module DecisionTree
|
|
8
|
+
# { operator:, counts:, cells:, operands: } for one decision,
|
|
9
9
|
# from its paths, [{path:, count:}, ...]. counts are the
|
|
10
10
|
# columns' counts. Every node has cells, one per column: a
|
|
11
11
|
# leaf { text:, cells: } its outcome, nil where unreached;
|
|
@@ -18,13 +18,20 @@ module PathCoverage
|
|
|
18
18
|
columns = paths.sort_by.with_index do |taken, i|
|
|
19
19
|
[taken[:count].zero? ? 0 : 1, i]
|
|
20
20
|
end
|
|
21
|
-
|
|
22
|
-
tree = node(source, condition, outcomes, (0..).each)
|
|
23
|
-
tree = tree.merge(label: 'elsif') if elsif?(source, condition)
|
|
21
|
+
tree = built(source, condition, columns.map { _1[:path] })
|
|
24
22
|
tree.merge(counts: columns.map { |taken| taken[:count] })
|
|
25
23
|
end
|
|
26
24
|
|
|
27
|
-
#
|
|
25
|
+
# The tree of condition with no counts, a column for each of
|
|
26
|
+
# outcomes, each path's outcomes, in the order given.
|
|
27
|
+
def self.built(source, condition, outcomes)
|
|
28
|
+
tree = node(source, condition, outcomes, (0..).each)
|
|
29
|
+
return tree unless elsif?(source, condition)
|
|
30
|
+
|
|
31
|
+
tree.merge(label: 'elsif')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# True for an if decision written as an elsif: an if's extent
|
|
28
35
|
# starts at its keyword.
|
|
29
36
|
def self.elsif?(source, condition)
|
|
30
37
|
condition.operator == 'if' &&
|
|
@@ -52,15 +59,17 @@ module PathCoverage
|
|
|
52
59
|
Kinds.of(condition.operator).texted(source, condition, nodes)
|
|
53
60
|
end
|
|
54
61
|
|
|
55
|
-
# condition's node from its operands' nodes, its
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
# condition's node from its operands' nodes, its arms built in
|
|
63
|
+
# order, as each arm's cells follow from those of the operand
|
|
64
|
+
# that decides it: the last operand before it that is no arm,
|
|
65
|
+
# eg a ternary's predicate, or x in x or return t.
|
|
66
|
+
def self.arms(source, condition, built, outcomes, leaves)
|
|
67
|
+
then_on = THEN_ON[condition.operator]
|
|
68
|
+
operands = built.each_with_index.map do |operand, index|
|
|
61
69
|
next operand unless operand.is_a?(Arm)
|
|
62
70
|
|
|
63
|
-
|
|
71
|
+
deciding = built.take(index).grep_v(Arm).last
|
|
72
|
+
decided = [deciding[:cells], then_on]
|
|
64
73
|
arm(source, operand, decided, outcomes, leaves)
|
|
65
74
|
end
|
|
66
75
|
operator = condition.operator
|
|
@@ -82,7 +91,7 @@ module PathCoverage
|
|
|
82
91
|
picked = arm.kind == :then ? then_on : !then_on
|
|
83
92
|
body = arm.body ? node(source, arm.body, outcomes, leaves) : nil
|
|
84
93
|
{
|
|
85
|
-
arm: arm.kind, text: text_of(source, arm),
|
|
94
|
+
arm: arm.kind, text: text_of(source, arm), leaves: arm.leaves,
|
|
86
95
|
cells: decided.map { |outcome| outcome == picked }, body:
|
|
87
96
|
}
|
|
88
97
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module PathCoverage
|
|
2
|
+
# The branches of a decision's tree on a file's page, joining each
|
|
3
|
+
# operand's row to its operator's. A branch is a string of
|
|
4
|
+
# kinds, one letter per cell: t a tee, l an ell, v a bar, h a
|
|
5
|
+
# dash, s a space. The page draws each kind as lines a whole
|
|
6
|
+
# row tall, so a branch joins the rows above and below it.
|
|
7
|
+
module FoldBranches
|
|
8
|
+
# The branch to an operand with more after it.
|
|
9
|
+
TEE = 'ths'.freeze
|
|
10
|
+
# The branch to the last operand.
|
|
11
|
+
ELL = 'lhs'.freeze
|
|
12
|
+
# The indent under an operand with more after it, its bar
|
|
13
|
+
# running on down to them.
|
|
14
|
+
BAR = 'vss'.freeze
|
|
15
|
+
# The indent under the last operand.
|
|
16
|
+
GAP = 'sss'.freeze
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require_relative 'kinds'
|
|
2
|
+
|
|
3
|
+
module PathCoverage
|
|
4
|
+
# The cells of a row of a decision's tree on a file's page, one per
|
|
5
|
+
# path, as page data holds them. A cell says what its path did:
|
|
6
|
+
# its text a letter, eg T or F, or empty with a mark the page
|
|
7
|
+
# draws, eg a tick; with text to show on hover when its mark
|
|
8
|
+
# alone may not say enough.
|
|
9
|
+
module FoldCells
|
|
10
|
+
# [text, mark, hover] of a leaf's or a condition's cell, by
|
|
11
|
+
# the value it took on the path: a letter for each value
|
|
12
|
+
# but a &. receiver's, which is a mark, present or absent,
|
|
13
|
+
# hovering as not nil or nil.
|
|
14
|
+
OUTCOMES = {
|
|
15
|
+
true => ['T'], false => ['F'], nil => [''],
|
|
16
|
+
ITEMS[0] => ['0'], ITEMS[1] => ['1'], ITEMS[2] => ['*'],
|
|
17
|
+
ANSWERS[0] => ['T'], ANSWERS[1] => ['F'], ANSWERS[2] => ['TF'],
|
|
18
|
+
PRESENCE[0] => ['', 'present', PRESENCE[0]],
|
|
19
|
+
PRESENCE[1] => ['', 'absent', PRESENCE[1]]
|
|
20
|
+
}.freeze
|
|
21
|
+
|
|
22
|
+
# [text, mark] of a ternary's arm's cell: taken on a path
|
|
23
|
+
# that took it, else blank.
|
|
24
|
+
TAKEN = { true => ['', 'taken'], false => [''] }.freeze
|
|
25
|
+
|
|
26
|
+
# [text, mark] of the cell of an arm that returns or raises:
|
|
27
|
+
# leaves on a path that took it, so left the method there,
|
|
28
|
+
# else blank.
|
|
29
|
+
LEAVES = { true => ['', 'leaves'], false => [''] }.freeze
|
|
30
|
+
|
|
31
|
+
# Example: true and false give ['T', nil, nil], ['F', nil, nil].
|
|
32
|
+
# The cells of values, as page data holds them, each [text,
|
|
33
|
+
# mark, hover] as names gives it, nil for a mark or hover it
|
|
34
|
+
# has none of.
|
|
35
|
+
def self.values(values, names = OUTCOMES)
|
|
36
|
+
values.map do |value|
|
|
37
|
+
text, mark, hover = names[value]
|
|
38
|
+
[text, mark, hover]
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -1,41 +1,32 @@
|
|
|
1
|
-
require 'cgi/escape'
|
|
2
1
|
require_relative 'condition'
|
|
3
|
-
require_relative '
|
|
4
|
-
require_relative '
|
|
5
|
-
require_relative '
|
|
6
|
-
require_relative 'html_syntax'
|
|
2
|
+
require_relative 'code_tokens'
|
|
3
|
+
require_relative 'fold_branches'
|
|
4
|
+
require_relative 'fold_cells'
|
|
7
5
|
require_relative 'kinds'
|
|
8
6
|
|
|
9
7
|
module PathCoverage
|
|
10
|
-
# The tree of a
|
|
11
|
-
#
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
else_at ? %( data-else="#{else_at.join(',')}") : ''
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# SPIKE: the data-at attribute of a node located in its
|
|
29
|
-
# source, '' for one that is not.
|
|
30
|
-
def self.at(node)
|
|
31
|
-
node[:at] ? %( data-at="#{node[:at].join(',')}") : ''
|
|
8
|
+
# The tree of a decision, from DecisionTree.of, as its row's
|
|
9
|
+
# fold in a flow shows it: a grid whose columns are the
|
|
10
|
+
# decision's paths, as page data holds its rows, each a kind,
|
|
11
|
+
# a branch, a label, where its code is and a cell per path.
|
|
12
|
+
module FoldRows
|
|
13
|
+
# The rows of decision's fold, as page data holds them:
|
|
14
|
+
# decision's own row, naming its operator and each path's
|
|
15
|
+
# count, and where its else keyword is, if it has one; then
|
|
16
|
+
# the rows of its operands.
|
|
17
|
+
def self.rows(decision)
|
|
18
|
+
text = decision.fetch(:label) { decision[:operator] }
|
|
19
|
+
label = CodeTokens.label_code(text)
|
|
20
|
+
own = { kind: 'decision', branch: '', label:, at: decision[:at],
|
|
21
|
+
else: decision[:else_at], counts: decision[:counts] }
|
|
22
|
+
[own, *operand_rows(decision, '')]
|
|
32
23
|
end
|
|
33
24
|
|
|
34
25
|
# The rows of a condition's operands, each branching from
|
|
35
26
|
# its operator after indent; a nested condition's operands,
|
|
36
27
|
# and those of an arm's condition, follow its own row,
|
|
37
|
-
# indented under its branch. A leaf with
|
|
38
|
-
# branches as those
|
|
28
|
+
# indented under its branch. A leaf with decisions inside it
|
|
29
|
+
# branches as those decisions, then the leaf, in the order they
|
|
39
30
|
# run.
|
|
40
31
|
def self.operand_rows(condition, indent)
|
|
41
32
|
own = Kinds.of(condition[:operator]).rows(condition, indent)
|
|
@@ -45,8 +36,8 @@ module PathCoverage
|
|
|
45
36
|
last = operands.size - 1
|
|
46
37
|
operands.each_with_index.flat_map do |operand, i|
|
|
47
38
|
tip = i == last
|
|
48
|
-
branch = indent + (tip ?
|
|
49
|
-
under = indent + (tip ?
|
|
39
|
+
branch = indent + (tip ? FoldBranches::ELL : FoldBranches::TEE)
|
|
40
|
+
under = indent + (tip ? FoldBranches::GAP : FoldBranches::BAR)
|
|
50
41
|
node_rows(operand, branch, under)
|
|
51
42
|
end
|
|
52
43
|
end
|
|
@@ -65,11 +56,9 @@ module PathCoverage
|
|
|
65
56
|
# it: return or raise, coloured as code, marking each path
|
|
66
57
|
# that leaves there, placed at its code.
|
|
67
58
|
def self.leaves_row(node, branch)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
cells = HtmlCells.of(node[:cells], HtmlCells::LEAVES)
|
|
72
|
-
row(%( data-leaves=""#{at(node)}), lead, cells)
|
|
59
|
+
cells = FoldCells.values(node[:cells], FoldCells::LEAVES)
|
|
60
|
+
label = CodeTokens.code(node[:leaves])
|
|
61
|
+
{ kind: 'leaves', branch:, label:, at: node[:at], cells: }
|
|
73
62
|
end
|
|
74
63
|
|
|
75
64
|
# A ternary's arm's row, ? for then and : for else: an arm
|
|
@@ -78,23 +67,21 @@ module PathCoverage
|
|
|
78
67
|
# the paths taking it.
|
|
79
68
|
def self.arm_rows(arm, branch, under)
|
|
80
69
|
body = arm[:body]
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
%(<span class="arm" data-label="">#{label}</span>)
|
|
85
|
-
row = row(%( data-arm=""#{at(arm)}), lead, values)
|
|
70
|
+
label = CodeTokens.ternary_arm_code(Kinds::Choice.arm_label(arm))
|
|
71
|
+
row = { kind: 'arm', branch:, label:, at: arm[:at],
|
|
72
|
+
cells: arm_cells(arm, body) }
|
|
86
73
|
body ? [row, *operand_rows(body, under)] : [row]
|
|
87
74
|
end
|
|
88
75
|
|
|
89
76
|
# The cells of arm's row: its body's values, when its body is
|
|
90
77
|
# a condition; else a tick on each path that took it.
|
|
91
78
|
def self.arm_cells(arm, body)
|
|
92
|
-
return
|
|
79
|
+
return FoldCells.values(body[:cells]) if body
|
|
93
80
|
|
|
94
|
-
|
|
81
|
+
FoldCells.values(arm[:cells], FoldCells::TAKEN)
|
|
95
82
|
end
|
|
96
83
|
|
|
97
|
-
# The operands of condition a
|
|
84
|
+
# The operands of condition a flow's fold shows: a ?:'s arms,
|
|
98
85
|
# as its arms are part of its one expression; for any other,
|
|
99
86
|
# eg an if, a ||= or a case, no arm, as which arm a path takes
|
|
100
87
|
# follows from its leaves, but each arm's body, eg a when's
|
|
@@ -116,13 +103,13 @@ module PathCoverage
|
|
|
116
103
|
# it, so left the method, at where its code is, so hovering it
|
|
117
104
|
# lights the row; nil for an arm that does neither.
|
|
118
105
|
def self.leaving(arm)
|
|
119
|
-
word = arm[:
|
|
106
|
+
word = arm[:leaves]
|
|
120
107
|
word && { leaves: word, cells: arm[:cells], at: arm[:at] }
|
|
121
108
|
end
|
|
122
109
|
|
|
123
110
|
# operands with each node standing for the nodes its kind
|
|
124
|
-
# unfolds it into, eg a leaf with
|
|
125
|
-
#
|
|
111
|
+
# unfolds it into, eg a leaf with decisions inside it for those
|
|
112
|
+
# decisions, then the leaf; a leaf or an arm for itself.
|
|
126
113
|
def self.unfolded(operands)
|
|
127
114
|
operands.flat_map do |operand|
|
|
128
115
|
operator = operand[:operator]
|
|
@@ -130,27 +117,14 @@ module PathCoverage
|
|
|
130
117
|
end
|
|
131
118
|
end
|
|
132
119
|
|
|
133
|
-
# A nested condition's row: its branch, its operator,
|
|
134
|
-
#
|
|
120
|
+
# A nested condition's row: its branch, its operator, or its
|
|
121
|
+
# label when it has one, eg select { for a decision inside a leaf,
|
|
122
|
+
# and its value on each path.
|
|
135
123
|
def self.subtree_row(condition, branch)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
# A row of the grid, with attrs, lead's cells naming it,
|
|
142
|
-
# then values, its cells for each path.
|
|
143
|
-
def self.row(attrs, lead, values)
|
|
144
|
-
%(<div class="row"#{attrs}>#{lead}#{values}</div>)
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
# The cell naming a condition's operator, or its label when
|
|
148
|
-
# it has one, eg select { for a site inside a leaf, coloured
|
|
149
|
-
# as the code it is part of.
|
|
150
|
-
def self.operator(condition)
|
|
151
|
-
label = condition.fetch(:label) { condition[:operator] }
|
|
152
|
-
name = HtmlSyntax.label(label)
|
|
153
|
-
%(<span class="operator" data-operator="">#{name}</span>)
|
|
124
|
+
text = condition.fetch(:label) { condition[:operator] }
|
|
125
|
+
cells = FoldCells.values(condition[:cells])
|
|
126
|
+
{ kind: 'subtree', branch:, label: CodeTokens.label_code(text),
|
|
127
|
+
at: condition[:at], cells: }
|
|
154
128
|
end
|
|
155
129
|
|
|
156
130
|
# One operand's row: its branch, text, coloured as the code it
|
|
@@ -159,11 +133,8 @@ module PathCoverage
|
|
|
159
133
|
# each path.
|
|
160
134
|
def self.operand_row(operand, branch)
|
|
161
135
|
one_line = operand[:text].to_s.gsub(/\s*\n\s*/, ' ')
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
%(<span class="text" data-text="">#{text}</span>)
|
|
165
|
-
attrs = %( data-operand=""#{at(operand)})
|
|
166
|
-
row(attrs, lead, HtmlCells.of(operand[:cells]))
|
|
136
|
+
{ kind: 'operand', branch:, label: CodeTokens.code(one_line),
|
|
137
|
+
at: operand[:at], cells: FoldCells.values(operand[:cells]) }
|
|
167
138
|
end
|
|
168
139
|
end
|
|
169
140
|
end
|
data/lib/path_coverage/gaps.rb
CHANGED
|
@@ -1,32 +1,50 @@
|
|
|
1
1
|
module PathCoverage
|
|
2
|
-
# The terminal worklist: one line per path a
|
|
3
|
-
# took, and nothing for a
|
|
2
|
+
# The terminal worklist: one line per path a decision never
|
|
3
|
+
# took, and nothing for a decision that took them all. Every
|
|
4
4
|
# count stays in the operands and paths for reporters that
|
|
5
5
|
# show them all.
|
|
6
6
|
module Gaps
|
|
7
7
|
# The gap lines of operands, paths and outside, as Result
|
|
8
|
-
# gives them, in manifest order; texts is {
|
|
9
|
-
# leaf's source text }. A
|
|
10
|
-
# other, so a
|
|
8
|
+
# gives them, in manifest order; texts is { decision => each
|
|
9
|
+
# leaf's source text }. A decision's first leaf runs before any
|
|
10
|
+
# other, so a decision whose first never ran was never reached.
|
|
11
11
|
def self.lines(operands, paths: {}, texts: {}, outside: {})
|
|
12
|
-
operands.flat_map do |
|
|
13
|
-
next ["#{
|
|
12
|
+
operands.flat_map do |decision, counts|
|
|
13
|
+
next ["#{decision} never reached"] if never_ran?(counts.first)
|
|
14
14
|
|
|
15
|
-
path_gaps(
|
|
16
|
-
|
|
15
|
+
path_gaps(decision, paths.fetch(decision, []),
|
|
16
|
+
texts[decision]) +
|
|
17
|
+
ruled_out(decision, outside.fetch(decision, {}),
|
|
18
|
+
texts[decision])
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
# One line per path
|
|
22
|
+
# One line per path decision took that a treatment rules out,
|
|
21
23
|
# as Result#outside gives them, texts being each leaf's
|
|
22
24
|
# source text.
|
|
23
|
-
def self.ruled_out(
|
|
25
|
+
def self.ruled_out(decision, taken, texts)
|
|
24
26
|
taken.keys.map do |path|
|
|
25
|
-
"#{
|
|
27
|
+
"#{decision} path taken that a treatment rules out: " \
|
|
26
28
|
"#{steps(path, texts)}"
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
|
|
32
|
+
# Example: ["k.rb:5:11 path taken that its method rules out:
|
|
33
|
+
# `a` true"].
|
|
34
|
+
# One line per path taken, or return or raise reached, that
|
|
35
|
+
# its method rules out, ruled as PathsContext.ruled_out gives
|
|
36
|
+
# them, texts being { decision => each leaf's source text }.
|
|
37
|
+
# Such a line shows a fact derived from the code to be wrong.
|
|
38
|
+
def self.ruled_by_method(ruled, texts)
|
|
39
|
+
ruled.map do |name, path|
|
|
40
|
+
reached = "#{name} reached, though its method rules it out"
|
|
41
|
+
next reached if path.nil?
|
|
42
|
+
|
|
43
|
+
"#{name} path taken that its method rules out: " \
|
|
44
|
+
"#{steps(path, texts[name])}"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
30
48
|
# The outcome of each leaf path reaches, each named by its
|
|
31
49
|
# text, eg "`u.name` nil". A path's first leaf always has an
|
|
32
50
|
# outcome, so it always has a step.
|
|
@@ -36,15 +54,15 @@ module PathCoverage
|
|
|
36
54
|
end.join(', ')
|
|
37
55
|
end
|
|
38
56
|
|
|
39
|
-
# One line per path
|
|
57
|
+
# One line per path decision never took, as Result#paths gives
|
|
40
58
|
# them, naming the outcome of each leaf the path reaches,
|
|
41
59
|
# texts being each leaf's source text.
|
|
42
|
-
def self.path_gaps(
|
|
60
|
+
def self.path_gaps(decision, paths, texts)
|
|
43
61
|
paths.each_with_object([]) do |each, lines|
|
|
44
62
|
next unless each[:count].zero?
|
|
45
63
|
|
|
46
64
|
named = steps(each[:path], texts)
|
|
47
|
-
lines << "#{
|
|
65
|
+
lines << "#{decision} path never taken: #{named}"
|
|
48
66
|
end
|
|
49
67
|
end
|
|
50
68
|
|