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
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
require_relative 'walk'
|
|
2
|
+
|
|
3
|
+
module PathCoverage
|
|
4
|
+
# The ways each call of a covered method takes: a stack of the
|
|
5
|
+
# calls under way in each thread, each with the way its method
|
|
6
|
+
# is taking, a step going to the innermost call of the method
|
|
7
|
+
# holding its row.
|
|
8
|
+
class CallTrace
|
|
9
|
+
# Starts with no method known and no way taken.
|
|
10
|
+
def initialize
|
|
11
|
+
@entries = {}
|
|
12
|
+
@repeats = {}
|
|
13
|
+
@owners = {}
|
|
14
|
+
@ways = {}
|
|
15
|
+
@stack_key = :"path_coverage_calls_#{object_id}"
|
|
16
|
+
@depths_key = :"path_coverage_depths_#{object_id}"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# { unit's name => { way => count } } of every way ended so
|
|
20
|
+
# far, as Walk counts them.
|
|
21
|
+
attr_reader :ways
|
|
22
|
+
|
|
23
|
+
# Notes the method whose entry is named entry, loops being
|
|
24
|
+
# { its row's name => the names of the loops holding it,
|
|
25
|
+
# outermost first }, and repeats { its row's name => the while
|
|
26
|
+
# or until whose test holds it }, as Walk takes them.
|
|
27
|
+
def know(entry, loops, repeats = {})
|
|
28
|
+
@entries[entry] = loops
|
|
29
|
+
@repeats[entry] = repeats
|
|
30
|
+
loops.each_key { |row| @owners[row] = entry }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Starts a call of a covered method, its method known once it
|
|
34
|
+
# reaches its entry.
|
|
35
|
+
def call
|
|
36
|
+
stack.push(nil)
|
|
37
|
+
depths.push(nil)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Starts a call of a covered method a retry can restart, its
|
|
41
|
+
# frame at depth. A call at the depth of the call under way is
|
|
42
|
+
# that call restarting, so it starts nothing.
|
|
43
|
+
def restartable_call(depth)
|
|
44
|
+
return if depths.last == depth
|
|
45
|
+
|
|
46
|
+
stack.push(nil)
|
|
47
|
+
depths.push(depth)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Notes the statement named name reached. A method's entry
|
|
51
|
+
# starts its call's way. It does not when no call is under way
|
|
52
|
+
# to take it, as when the call began before this trace did. Nor
|
|
53
|
+
# does it when the call's way has started already, as when a
|
|
54
|
+
# retry runs the body again. Any other row is a step of the
|
|
55
|
+
# innermost call of the method holding it.
|
|
56
|
+
def reach(name)
|
|
57
|
+
if @entries.key?(name)
|
|
58
|
+
enter(name) unless stack.empty? || stack.last
|
|
59
|
+
else
|
|
60
|
+
innermost(@owners[name])&.step([name])
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Notes the decision named decision taking path, a step of the
|
|
65
|
+
# innermost call of the method holding it.
|
|
66
|
+
def decided(decision, path)
|
|
67
|
+
innermost(@owners[decision])&.step([decision, path])
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Notes a pass of the loop named loop, a block called with one
|
|
71
|
+
# more item, in the innermost call of the method holding it.
|
|
72
|
+
def pass(loop)
|
|
73
|
+
innermost(@owners[loop])&.passed(loop)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Ends the innermost call under way, counting its way.
|
|
77
|
+
def return
|
|
78
|
+
depths.pop
|
|
79
|
+
stack.pop&.finish
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
private
|
|
83
|
+
|
|
84
|
+
# Starts the way of the innermost call under way, of the
|
|
85
|
+
# method whose entry is named entry.
|
|
86
|
+
def enter(entry)
|
|
87
|
+
stack[-1] = Walk.new(entry, @ways, @entries[entry],
|
|
88
|
+
@repeats[entry])
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# The calls under way in the current thread, innermost last,
|
|
92
|
+
# each the Walk of its way, or nil before it reaches its entry.
|
|
93
|
+
def stack
|
|
94
|
+
Thread.current[@stack_key] ||= []
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# The frame depth of each call under way in the current thread,
|
|
98
|
+
# as stack holds them. It is nil for a call no retry restarts.
|
|
99
|
+
def depths
|
|
100
|
+
Thread.current[@depths_key] ||= []
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# The Walk of the innermost call under way of the method
|
|
104
|
+
# whose entry is named entry, else nil.
|
|
105
|
+
def innermost(entry)
|
|
106
|
+
stack.reverse_each.find { |walk| walk&.entry == entry }
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
data/lib/path_coverage/calls.rb
CHANGED
|
@@ -4,96 +4,126 @@
|
|
|
4
4
|
module PathCoverage
|
|
5
5
|
# The call rewritten code makes around each operand; returns
|
|
6
6
|
# value unchanged.
|
|
7
|
-
def self.record(
|
|
8
|
-
@recorder.record(
|
|
7
|
+
def self.record(decision, index, value)
|
|
8
|
+
@recorder.record(decision, index, value)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
# The call rewritten code makes before a
|
|
12
|
-
#
|
|
13
|
-
def self.enter(
|
|
14
|
-
@recorder.enter(
|
|
11
|
+
# The call rewritten code makes before a decision's first leaf,
|
|
12
|
+
# decision having size leaves; returns the evaluation's trail.
|
|
13
|
+
def self.enter(decision, size)
|
|
14
|
+
@recorder.enter(decision, size)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
# The call rewritten code makes around a
|
|
17
|
+
# The call rewritten code makes around a decision as a whole,
|
|
18
18
|
# with the trail enter gave it; returns value unchanged.
|
|
19
19
|
def self.leave(trail, value)
|
|
20
20
|
@recorder.leave(trail, value)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
# The call rewritten code makes around a case's pattern, the
|
|
24
|
-
# index-th of size at
|
|
25
|
-
def self.when_match(
|
|
26
|
-
@recorder.when_match(
|
|
24
|
+
# index-th of size at decision; returns the pattern's stand-in.
|
|
25
|
+
def self.when_match(decision, index, size, pattern)
|
|
26
|
+
@recorder.when_match(decision, index, size, pattern)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# The call rewritten code makes around the pattern of a case
|
|
30
|
-
# nested in
|
|
30
|
+
# nested in decision, the decision's index-th leaf; returns the
|
|
31
31
|
# pattern's stand-in.
|
|
32
|
-
def self.pattern(
|
|
33
|
-
@recorder.pattern(
|
|
32
|
+
def self.pattern(decision, index, pattern)
|
|
33
|
+
@recorder.pattern(decision, index, pattern)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
# The call rewritten code makes around the right side of a
|
|
37
|
-
# write nested in
|
|
37
|
+
# write nested in decision, its target the decision's at-th leaf,
|
|
38
38
|
# outcome being the target's when it runs; returns value
|
|
39
39
|
# unchanged.
|
|
40
|
-
def self.written_at(
|
|
41
|
-
@recorder.written_at(
|
|
40
|
+
def self.written_at(decision, at, outcome, value)
|
|
41
|
+
@recorder.written_at(decision, at, outcome, value)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
# The call rewritten code makes around a write nested in
|
|
45
|
-
# its target the
|
|
44
|
+
# The call rewritten code makes around a write nested in decision,
|
|
45
|
+
# its target the decision's at-th leaf, skipped being the target's
|
|
46
46
|
# outcome when its right side never ran; returns value
|
|
47
47
|
# unchanged.
|
|
48
|
-
def self.settle(
|
|
49
|
-
@recorder.settle(
|
|
48
|
+
def self.settle(decision, at, skipped, value)
|
|
49
|
+
@recorder.settle(decision, at, skipped, value)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
# The call rewritten code makes before a block method's call
|
|
53
|
-
# nested in
|
|
54
|
-
# returns the
|
|
55
|
-
def self.begin_items(
|
|
56
|
-
@recorder.begin_items(
|
|
53
|
+
# nested in decision runs, its receiver the decision's at-th leaf;
|
|
54
|
+
# returns the decision's trail.
|
|
55
|
+
def self.begin_items(decision, at)
|
|
56
|
+
@recorder.begin_items(decision, at)
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
# The call rewritten code makes around the block's expression
|
|
60
|
-
# of a stop-early block method nested in
|
|
61
|
-
#
|
|
62
|
-
def self.item_at(
|
|
63
|
-
@recorder.item_at(
|
|
60
|
+
# of a stop-early block method nested in decision, its receiver the
|
|
61
|
+
# decision's at-th leaf; returns value unchanged.
|
|
62
|
+
def self.item_at(decision, at, value)
|
|
63
|
+
@recorder.item_at(decision, at, value)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
# The call rewritten code makes around the block's expression
|
|
67
|
-
# of an every-item block method nested in
|
|
68
|
-
# the
|
|
69
|
-
def self.answer_at(
|
|
70
|
-
@recorder.answer_at(
|
|
67
|
+
# of an every-item block method nested in decision, its receiver
|
|
68
|
+
# the decision's at-th leaf; returns value unchanged.
|
|
69
|
+
def self.answer_at(decision, at, value)
|
|
70
|
+
@recorder.answer_at(decision, at, value)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
# The call rewritten code makes around a block method's call
|
|
74
|
-
# nested in
|
|
75
|
-
# trail begin_items gave it; returns value unchanged.
|
|
76
|
-
def self.end_items(
|
|
77
|
-
@recorder.end_items(
|
|
74
|
+
# nested in decision, its receiver the decision's at-th leaf,
|
|
75
|
+
# with the trail begin_items gave it; returns value unchanged.
|
|
76
|
+
def self.end_items(decision, at, trail, value)
|
|
77
|
+
@recorder.end_items(decision, at, trail, value)
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
# The call rewritten code makes around a &. receiver, the
|
|
81
|
-
# index-th leaf of
|
|
81
|
+
# index-th leaf of decision, its chain's leaves starting at first;
|
|
82
82
|
# returns value unchanged.
|
|
83
|
-
def self.present(
|
|
84
|
-
@recorder.present(
|
|
83
|
+
def self.present(decision, index, first, value)
|
|
84
|
+
@recorder.present(decision, index, first, value)
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
# The call rewritten code makes around a &. chain's value, the
|
|
88
|
-
# index-th leaf of
|
|
88
|
+
# index-th leaf of decision, its chain's leaves starting at first;
|
|
89
89
|
# returns value unchanged.
|
|
90
|
-
def self.chained(
|
|
91
|
-
@recorder.chained(
|
|
90
|
+
def self.chained(decision, index, first, value)
|
|
91
|
+
@recorder.chained(decision, index, first, value)
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
# The call rewritten code makes before each statement that is
|
|
95
|
-
# no
|
|
95
|
+
# no decision, counting its run.
|
|
96
96
|
def self.reach(name)
|
|
97
97
|
@recorder.reach(name)
|
|
98
98
|
end
|
|
99
|
+
|
|
100
|
+
# The call rewritten code makes first in each block body holding
|
|
101
|
+
# a row: a pass of the loop named name.
|
|
102
|
+
def self.pass(name)
|
|
103
|
+
@recorder.pass(name)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# The call rewritten code makes around the last statement of a
|
|
107
|
+
# body with a rescue. It notes that the fork named name
|
|
108
|
+
# completed, its body running to its end. It returns value
|
|
109
|
+
# unchanged.
|
|
110
|
+
def self.completed(name, value)
|
|
111
|
+
@recorder.completed(name, value)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# The call rewritten code makes first in the body of the rescue
|
|
115
|
+
# numbered number of the rescue fork named name. It notes that
|
|
116
|
+
# this rescue ran.
|
|
117
|
+
def self.rescued(name, number)
|
|
118
|
+
@recorder.rescued(name, number)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# The call rewritten code makes around the rescue of a rescue
|
|
122
|
+
# modifier, its rescue numbered number of the rescue fork named
|
|
123
|
+
# name. It notes that this rescue ran, and returns value
|
|
124
|
+
# unchanged.
|
|
125
|
+
def self.ran(name, number, value)
|
|
126
|
+
@recorder.rescued(name, number)
|
|
127
|
+
value
|
|
128
|
+
end
|
|
99
129
|
end
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
require 'cgi/escape'
|
|
2
1
|
require 'prism'
|
|
3
2
|
|
|
4
3
|
module PathCoverage
|
|
5
4
|
# The colours of a file's code on its page: each token Prism
|
|
6
5
|
# lexes, as Ruby itself does, gets the class of its kind, eg k
|
|
7
6
|
# for a keyword, so the page's CSS colours it.
|
|
8
|
-
module
|
|
7
|
+
module CodeTokens
|
|
9
8
|
# The class of each coloured token type that is not a keyword
|
|
10
9
|
# or a number: c comment, s string, t constant, v instance
|
|
11
10
|
# variable, o an operator that decides a path.
|
|
@@ -116,52 +115,55 @@ module PathCoverage
|
|
|
116
115
|
end
|
|
117
116
|
end
|
|
118
117
|
|
|
119
|
-
# The names of the operators that decide a path, as a
|
|
118
|
+
# The names of the operators that decide a path, as a decision
|
|
120
119
|
# tree's labels write them. Alone, some lex as other tokens,
|
|
121
120
|
# eg ?: as a character and || as two pipes, so each is
|
|
122
121
|
# coloured as an operator by name.
|
|
123
122
|
DECIDING = %w[&& || &. ?: &&= ||=].freeze
|
|
124
123
|
|
|
125
|
-
#
|
|
126
|
-
#
|
|
127
|
-
#
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
# Example: x && y as { text: 'x && y', tokens: [[2, 4, 'o']] }.
|
|
125
|
+
# text, a fragment of code on one line, eg a decision tree's
|
|
126
|
+
# operator or operand, as page data holds it: its text and the
|
|
127
|
+
# [from, to, class] of each range coloured as the code it is
|
|
128
|
+
# part of; one of DECIDING wholly the operator it names.
|
|
129
|
+
def self.code(text)
|
|
130
|
+
return { text:, tokens: [[0, text.length, 'o']] } if
|
|
131
|
+
DECIDING.include?(text)
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
{ text:, tokens: of(text).fetch(1, []) }
|
|
134
134
|
end
|
|
135
135
|
|
|
136
|
-
# Example: if/else
|
|
137
|
-
#
|
|
138
|
-
#
|
|
139
|
-
#
|
|
140
|
-
#
|
|
141
|
-
def self.
|
|
142
|
-
return
|
|
136
|
+
# Example: if/else, each of if and else a keyword.
|
|
137
|
+
# The code of a row's or a fold's label, coloured as code
|
|
138
|
+
# colours it; but a label naming a choice and its else, eg
|
|
139
|
+
# if/else, each of its words, as code would read /else as a
|
|
140
|
+
# regexp's start.
|
|
141
|
+
def self.label_code(text)
|
|
142
|
+
return code(text) unless text.match?(%r{\A\w+/else\z})
|
|
143
143
|
|
|
144
|
-
text.split('/').map {
|
|
144
|
+
words = text.split('/').map { code(_1) }
|
|
145
|
+
words.reduce { |one, other| joined_code(one, '/', other) }
|
|
145
146
|
end
|
|
146
147
|
|
|
147
|
-
#
|
|
148
|
-
#
|
|
149
|
-
|
|
148
|
+
# Example: ? total > 100, its ? coloured as an operator.
|
|
149
|
+
# The code of a ternary's arm's label: its ? or : coloured as
|
|
150
|
+
# an operator, the code after it as code.
|
|
151
|
+
def self.ternary_arm_code(label)
|
|
150
152
|
mark, code = label.split(' ', 2)
|
|
151
|
-
|
|
153
|
+
marked = { text: mark, tokens: [[0, mark.length, 'o']] }
|
|
154
|
+
joined_code(marked, ' ', code(code.to_s))
|
|
152
155
|
end
|
|
153
156
|
|
|
154
|
-
#
|
|
155
|
-
#
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
token = CGI.escapeHTML(text[from...to])
|
|
162
|
-
%(#{plain}<span class="#{css}">#{token}</span>)
|
|
157
|
+
# Example: if, / and else give if/else, its else's ranges moved
|
|
158
|
+
# on by 3.
|
|
159
|
+
# The code of one, then between, uncoloured, then other.
|
|
160
|
+
def self.joined_code(one, between, other)
|
|
161
|
+
shift = one[:text].length + between.length
|
|
162
|
+
moved = other[:tokens].map do |from, to, css|
|
|
163
|
+
[from + shift, to + shift, css]
|
|
163
164
|
end
|
|
164
|
-
|
|
165
|
+
{ text: one[:text] + between + other[:text],
|
|
166
|
+
tokens: one[:tokens] + moved }
|
|
165
167
|
end
|
|
166
168
|
end
|
|
167
169
|
end
|
|
@@ -2,16 +2,12 @@ module PathCoverage
|
|
|
2
2
|
# The operators whose predicate picks an arm.
|
|
3
3
|
CHOICES = %w[?: if unless].freeze
|
|
4
4
|
|
|
5
|
-
# An arm whose code leaves the method, by its code's start: a
|
|
6
|
-
# return or a raise, captured.
|
|
7
|
-
LEAVES = /\A(return|raise)\b/
|
|
8
|
-
|
|
9
5
|
# The operator of a safe-navigation chain, eg user&.account.
|
|
10
6
|
SAFE = '&.'.freeze
|
|
11
7
|
|
|
12
|
-
# The operator of a leaf with
|
|
8
|
+
# The operator of a leaf with decisions inside it, eg
|
|
13
9
|
# ids.select { |i| i.odd? }.any? as an operand of an &&: its
|
|
14
|
-
# operands are those
|
|
10
|
+
# operands are those decisions' Conditions, then the leaf's own byte
|
|
15
11
|
# range, whose outcome is the leaf's value.
|
|
16
12
|
CONTAINS = 'contains'.freeze
|
|
17
13
|
|
|
@@ -25,9 +21,12 @@ module PathCoverage
|
|
|
25
21
|
WRITES = %w[||= &&=].freeze
|
|
26
22
|
|
|
27
23
|
# The predicate outcome on which each choice takes its then
|
|
28
|
-
# arm: an unless's is false, as is a ||= write's
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
# arm: an unless's is false, as is a ||= write's, and an || or
|
|
25
|
+
# or's, whose leaving right side, eg x or return t, runs when
|
|
26
|
+
# the operand before it is false.
|
|
27
|
+
THEN_ON = Hash.new(true).merge(
|
|
28
|
+
'unless' => false, '||=' => false, '||' => false, 'or' => false
|
|
29
|
+
).freeze
|
|
31
30
|
|
|
32
31
|
# The methods that call their block an item at a time until
|
|
33
32
|
# it decides, its last answer deciding the result.
|
|
@@ -70,7 +69,7 @@ module PathCoverage
|
|
|
70
69
|
# all but find and detect, whose found item may itself be nil.
|
|
71
70
|
VALUED = [*STOP_EARLY - %w[find detect], *EVERY_ITEM].freeze
|
|
72
71
|
|
|
73
|
-
# Every block method whose call is a
|
|
72
|
+
# Every block method whose call is a decision, by its paths.
|
|
74
73
|
BLOCK_PATHS = [
|
|
75
74
|
*STOP_EARLY.map { |name| [name, STOP_EARLY_PATHS] },
|
|
76
75
|
*EVERY_ITEM.map { |name| [name, EVERY_ITEM_PATHS] }
|
|
@@ -80,12 +79,13 @@ module PathCoverage
|
|
|
80
79
|
# :else, extent its byte range, nil for an arm with no
|
|
81
80
|
# statements, and body the Condition it is, when it is one,
|
|
82
81
|
# else nil for a plain value or statements, which decide
|
|
83
|
-
# nothing
|
|
84
|
-
|
|
82
|
+
# nothing; leaves is Leaving's word for its code, return or
|
|
83
|
+
# raise, nil for an arm that does not leave the method.
|
|
84
|
+
Arm = Data.define(:kind, :extent, :body, :leaves)
|
|
85
85
|
|
|
86
|
-
# One
|
|
86
|
+
# One decision's condition as the manifest found it: its operator
|
|
87
87
|
# and its operands, each the byte range of a leaf or a nested
|
|
88
|
-
# Condition. A
|
|
88
|
+
# Condition. A decision's commands are the byte ranges of its
|
|
89
89
|
# leaves that are command calls, eg `ok? id`; its fixed are
|
|
90
90
|
# { byte range => :truthy } for leaves that can have that one
|
|
91
91
|
# outcome only, eg `Clock.new`. Its extent is the byte range
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require_relative 'configuration_limits'
|
|
1
2
|
require_relative 'configuration_paths'
|
|
2
3
|
|
|
3
4
|
module PathCoverage
|
|
@@ -6,14 +7,15 @@ module PathCoverage
|
|
|
6
7
|
|
|
7
8
|
# The settings given in a PathCoverage.start block.
|
|
8
9
|
class Configuration
|
|
10
|
+
include ConfigurationLimits
|
|
9
11
|
include ConfigurationPaths
|
|
10
12
|
|
|
11
13
|
GLOB_FLAGS = File::FNM_PATHNAME | File::FNM_EXTGLOB
|
|
12
14
|
SETTINGS = %w[
|
|
13
|
-
collector cover coverage_dir group ignore
|
|
14
|
-
skip treat
|
|
15
|
+
collector cover coverage_dir group ignore loops max_paths
|
|
16
|
+
report root skip treat
|
|
15
17
|
].freeze
|
|
16
|
-
REPORTERS = %w[gaps
|
|
18
|
+
REPORTERS = %w[gaps post summary ways].freeze
|
|
17
19
|
|
|
18
20
|
# Evaluates the settings block against a new configuration.
|
|
19
21
|
def initialize(&)
|
|
@@ -23,6 +25,7 @@ module PathCoverage
|
|
|
23
25
|
@reporters = [:gaps]
|
|
24
26
|
@ignored = []
|
|
25
27
|
@treats = []
|
|
28
|
+
default_limits
|
|
26
29
|
instance_eval(&)
|
|
27
30
|
end
|
|
28
31
|
|
|
@@ -42,7 +45,7 @@ module PathCoverage
|
|
|
42
45
|
@collector_url = url
|
|
43
46
|
end
|
|
44
47
|
|
|
45
|
-
# Sets the dir that cover globs and
|
|
48
|
+
# Sets the dir that cover globs and decision names are
|
|
46
49
|
# relative to.
|
|
47
50
|
def root(dir)
|
|
48
51
|
@root = dir
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module PathCoverage
|
|
2
|
+
# The settings of a PathCoverage.start block that limit a flow's
|
|
3
|
+
# ways: the most paths a method may have and still be checked,
|
|
4
|
+
# and whether a loop counts as a decision. It relies on its
|
|
5
|
+
# includer's ConfigurationError, and sets @max_paths and @loops
|
|
6
|
+
# from their defaults first.
|
|
7
|
+
module ConfigurationLimits
|
|
8
|
+
# The most paths a method may have and still be checked, by
|
|
9
|
+
# default.
|
|
10
|
+
MAX_PATHS = 4096
|
|
11
|
+
# The most max_paths may be: 65536 paths keep analysing each
|
|
12
|
+
# method's paths to about 2 seconds and 120 MB of JSON.
|
|
13
|
+
PATHS_CAP = 65_536
|
|
14
|
+
|
|
15
|
+
# Sets each limit to its default: a method with more than
|
|
16
|
+
# MAX_PATHS paths fails, and no loop is a decision.
|
|
17
|
+
def default_limits
|
|
18
|
+
@max_paths = MAX_PATHS
|
|
19
|
+
@loops = false
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# The most paths a method may have and still be checked, as
|
|
23
|
+
# max_paths sets it: one with more lists none of its ways, and
|
|
24
|
+
# fails.
|
|
25
|
+
def path_limit = @max_paths
|
|
26
|
+
|
|
27
|
+
# Sets the most paths a method may have and still be checked;
|
|
28
|
+
# refuses more than PATHS_CAP.
|
|
29
|
+
def max_paths(count)
|
|
30
|
+
if count > PATHS_CAP
|
|
31
|
+
raise ConfigurationError, cap_refusal(count)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
@max_paths = count
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Why max_paths refuses count.
|
|
38
|
+
def cap_refusal(count)
|
|
39
|
+
"max paths #{count} is more than #{PATHS_CAP}, the cap that " \
|
|
40
|
+
"keeps analysing each method's paths to about 2 seconds " \
|
|
41
|
+
'and 120 MB of JSON'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# True when each loop counts as a decision, 0 items or 1+.
|
|
45
|
+
def loops? = @loops
|
|
46
|
+
|
|
47
|
+
# Counts each loop as a decision: 0 items or 1+ items.
|
|
48
|
+
def loops
|
|
49
|
+
@loops = true
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -2,20 +2,20 @@ require_relative 'kinds'
|
|
|
2
2
|
|
|
3
3
|
module PathCoverage
|
|
4
4
|
# The settings of a PathCoverage.start block that change which
|
|
5
|
-
# paths a
|
|
5
|
+
# paths a decision has: ignore, eg ignore '&&=', and treat, eg
|
|
6
6
|
# treat 'name', as: :present. It relies on its includer's
|
|
7
7
|
# @ignored, @treats and check.
|
|
8
8
|
module ConfigurationPaths
|
|
9
9
|
TREATMENTS = %w[present nonempty].freeze
|
|
10
10
|
|
|
11
|
-
# The operators whose
|
|
11
|
+
# The operators whose decisions are not measured, chosen with
|
|
12
12
|
# ignore, eg ['&&=']; none when nothing was chosen.
|
|
13
13
|
attr_reader :ignored
|
|
14
14
|
|
|
15
|
-
# Chooses operators whose
|
|
16
|
-
# ignore '&&=' measures no &&= write; a
|
|
15
|
+
# Chooses operators whose decisions are not measured, eg
|
|
16
|
+
# ignore '&&=' measures no &&= write; a decision inside one, eg
|
|
17
17
|
# on its right side, still is. Refuses an operator there
|
|
18
|
-
# is no kind of
|
|
18
|
+
# is no kind of decision for.
|
|
19
19
|
def ignore(*operators)
|
|
20
20
|
check('operator', operators, Kinds::BY_OPERATOR.keys)
|
|
21
21
|
@ignored = operators
|
|
@@ -43,11 +43,11 @@ module PathCoverage
|
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
# The settings that change which paths a
|
|
46
|
+
# The settings that change which paths a decision has, eg
|
|
47
47
|
# { 'ignored' => ['&&='],
|
|
48
48
|
# 'treats' => [['name', 'present', nil]] },
|
|
49
49
|
# each only when set: runs whose fingerprints differ list
|
|
50
|
-
# their
|
|
50
|
+
# their decisions' paths differently.
|
|
51
51
|
def fingerprint
|
|
52
52
|
print = {}
|
|
53
53
|
print['ignored'] = @ignored unless @ignored.empty?
|