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
data/lib/path_coverage/calls.rb
CHANGED
|
@@ -26,42 +26,74 @@ module PathCoverage
|
|
|
26
26
|
@recorder.when_match(site, index, size, pattern)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
# The call rewritten code makes around the pattern of a case
|
|
30
|
+
# nested in site, the site's index-th leaf; returns the
|
|
31
|
+
# pattern's stand-in.
|
|
32
|
+
def self.pattern(site, index, pattern)
|
|
33
|
+
@recorder.pattern(site, index, pattern)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# The call rewritten code makes around the right side of a
|
|
37
|
+
# write nested in site, its target the site's at-th leaf,
|
|
38
|
+
# outcome being the target's when it runs; returns value
|
|
39
|
+
# unchanged.
|
|
40
|
+
def self.written_at(site, at, outcome, value)
|
|
41
|
+
@recorder.written_at(site, at, outcome, value)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# The call rewritten code makes around a write nested in site,
|
|
45
|
+
# its target the site's at-th leaf, skipped being the target's
|
|
46
|
+
# outcome when its right side never ran; returns value
|
|
47
|
+
# unchanged.
|
|
48
|
+
def self.settle(site, at, skipped, value)
|
|
49
|
+
@recorder.settle(site, at, skipped, value)
|
|
50
|
+
end
|
|
51
|
+
|
|
29
52
|
# The call rewritten code makes before a block method's call
|
|
30
|
-
#
|
|
31
|
-
|
|
32
|
-
|
|
53
|
+
# nested in site runs, its receiver the site's at-th leaf;
|
|
54
|
+
# returns the site's trail.
|
|
55
|
+
def self.begin_items(site, at)
|
|
56
|
+
@recorder.begin_items(site, at)
|
|
33
57
|
end
|
|
34
58
|
|
|
35
|
-
# The call rewritten code makes around
|
|
36
|
-
# block
|
|
37
|
-
|
|
38
|
-
|
|
59
|
+
# The call rewritten code makes around the block's expression
|
|
60
|
+
# of a stop-early block method nested in site, its receiver the
|
|
61
|
+
# site's at-th leaf; returns value unchanged.
|
|
62
|
+
def self.item_at(site, at, value)
|
|
63
|
+
@recorder.item_at(site, at, value)
|
|
39
64
|
end
|
|
40
65
|
|
|
41
66
|
# The call rewritten code makes around the block's expression
|
|
42
|
-
# of
|
|
43
|
-
# value unchanged.
|
|
44
|
-
def self.
|
|
45
|
-
@recorder.
|
|
67
|
+
# of an every-item block method nested in site, its receiver
|
|
68
|
+
# the site's at-th leaf; returns value unchanged.
|
|
69
|
+
def self.answer_at(site, at, value)
|
|
70
|
+
@recorder.answer_at(site, at, value)
|
|
46
71
|
end
|
|
47
72
|
|
|
48
73
|
# The call rewritten code makes around a block method's call
|
|
49
|
-
#
|
|
50
|
-
# value unchanged.
|
|
51
|
-
def self.
|
|
52
|
-
@recorder.
|
|
74
|
+
# nested in site, its receiver the site's at-th leaf, with the
|
|
75
|
+
# trail begin_items gave it; returns value unchanged.
|
|
76
|
+
def self.end_items(site, at, trail, value)
|
|
77
|
+
@recorder.end_items(site, at, trail, value)
|
|
53
78
|
end
|
|
54
79
|
|
|
55
|
-
# The call rewritten code makes
|
|
56
|
-
#
|
|
57
|
-
|
|
58
|
-
|
|
80
|
+
# The call rewritten code makes around a &. receiver, the
|
|
81
|
+
# index-th leaf of site, its chain's leaves starting at first;
|
|
82
|
+
# returns value unchanged.
|
|
83
|
+
def self.present(site, index, first, value)
|
|
84
|
+
@recorder.present(site, index, first, value)
|
|
59
85
|
end
|
|
60
86
|
|
|
61
|
-
# The call rewritten code makes around
|
|
62
|
-
#
|
|
87
|
+
# The call rewritten code makes around a &. chain's value, the
|
|
88
|
+
# index-th leaf of site, its chain's leaves starting at first;
|
|
63
89
|
# returns value unchanged.
|
|
64
|
-
def self.
|
|
65
|
-
@recorder.
|
|
90
|
+
def self.chained(site, index, first, value)
|
|
91
|
+
@recorder.chained(site, index, first, value)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# The call rewritten code makes before each statement that is
|
|
95
|
+
# no site, counting its run.
|
|
96
|
+
def self.reach(name)
|
|
97
|
+
@recorder.reach(name)
|
|
66
98
|
end
|
|
67
99
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module PathCoverage
|
|
2
|
+
# One card of a file's page, as the page lays out the code
|
|
3
|
+
# around it: its first and last lines, its def's column, its
|
|
4
|
+
# status, gaps or covered, whether it is a top card, of sites
|
|
5
|
+
# outside every def, how many sites a top card holds, its
|
|
6
|
+
# button showing that count, nil for a method's, and its HTML.
|
|
7
|
+
Card = Data.define(:first, :last, :column, :status, :top, :sites,
|
|
8
|
+
:html) do
|
|
9
|
+
# True when line is one of the card's lines.
|
|
10
|
+
def holds?(line)
|
|
11
|
+
(first..last).cover?(line)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -6,9 +6,28 @@ module PathCoverage
|
|
|
6
6
|
# decided by their predicate alone.
|
|
7
7
|
STATEMENT_CHOICES = %w[if unless].freeze
|
|
8
8
|
|
|
9
|
+
# The operator of a safe-navigation chain, eg user&.account.
|
|
10
|
+
SAFE = '&.'.freeze
|
|
11
|
+
|
|
12
|
+
# The operator of a leaf with sites inside it, eg
|
|
13
|
+
# ids.select { |i| i.odd? }.any? as an operand of an &&: its
|
|
14
|
+
# operands are those sites' Conditions, then the leaf's own byte
|
|
15
|
+
# range, whose outcome is the leaf's value.
|
|
16
|
+
CONTAINS = 'contains'.freeze
|
|
17
|
+
|
|
18
|
+
# A &. receiver's outcome: not nil, so the call is made, false
|
|
19
|
+
# included, or nil, so the rest of the chain is skipped.
|
|
20
|
+
PRESENCE = ['not nil', 'nil'].freeze
|
|
21
|
+
|
|
22
|
+
# The writes whose target decides whether their right side
|
|
23
|
+
# runs, as an unless or an if decides its arm: x ||= v runs v
|
|
24
|
+
# when x is false, x &&= v when x is true.
|
|
25
|
+
WRITES = %w[||= &&=].freeze
|
|
26
|
+
|
|
9
27
|
# The predicate outcome on which each choice takes its then
|
|
10
|
-
# arm: an unless's is false.
|
|
11
|
-
THEN_ON = Hash.new(true).merge('unless' => false)
|
|
28
|
+
# arm: an unless's is false, as is a ||= write's.
|
|
29
|
+
THEN_ON = Hash.new(true).merge('unless' => false, '||=' => false)
|
|
30
|
+
.freeze
|
|
12
31
|
|
|
13
32
|
# The methods that call their block an item at a time until
|
|
14
33
|
# it decides, its last answer deciding the result.
|
|
@@ -47,6 +66,10 @@ module PathCoverage
|
|
|
47
66
|
[ITEMS[2], ANSWERS[2]]
|
|
48
67
|
].freeze
|
|
49
68
|
|
|
69
|
+
# The block methods whose value follows from their path alone:
|
|
70
|
+
# all but find and detect, whose found item may itself be nil.
|
|
71
|
+
VALUED = [*STOP_EARLY - %w[find detect], *EVERY_ITEM].freeze
|
|
72
|
+
|
|
50
73
|
# Every block method whose call is a site, by its paths.
|
|
51
74
|
BLOCK_PATHS = [
|
|
52
75
|
*STOP_EARLY.map { |name| [name, STOP_EARLY_PATHS] },
|
|
@@ -87,10 +110,17 @@ module PathCoverage
|
|
|
87
110
|
operands.flat_map do |operand|
|
|
88
111
|
case operand
|
|
89
112
|
when Condition then operand.leaves
|
|
90
|
-
when Arm then operand
|
|
113
|
+
when Arm then arm_leaves(operand)
|
|
91
114
|
else [operand]
|
|
92
115
|
end
|
|
93
116
|
end
|
|
94
117
|
end
|
|
118
|
+
|
|
119
|
+
# The leaves of arm's body, none for an arm whose body is no
|
|
120
|
+
# condition.
|
|
121
|
+
def arm_leaves(arm)
|
|
122
|
+
body = arm.body
|
|
123
|
+
body ? body.leaves : []
|
|
124
|
+
end
|
|
95
125
|
end
|
|
96
126
|
end
|
|
@@ -1,41 +1,34 @@
|
|
|
1
|
+
require_relative 'configuration_paths'
|
|
2
|
+
|
|
1
3
|
module PathCoverage
|
|
2
4
|
# Raised for a start block that cannot be applied.
|
|
3
5
|
class ConfigurationError < StandardError; end
|
|
4
6
|
|
|
5
7
|
# The settings given in a PathCoverage.start block.
|
|
6
8
|
class Configuration
|
|
9
|
+
include ConfigurationPaths
|
|
10
|
+
|
|
7
11
|
GLOB_FLAGS = File::FNM_PATHNAME | File::FNM_EXTGLOB
|
|
8
12
|
SETTINGS = %w[
|
|
9
|
-
collector cover coverage_dir
|
|
13
|
+
collector cover coverage_dir group ignore report root
|
|
14
|
+
skip treat
|
|
10
15
|
].freeze
|
|
11
|
-
REPORTERS = %w[gaps html post].freeze
|
|
12
|
-
MEASURES = %w[decisions methods].freeze
|
|
16
|
+
REPORTERS = %w[gaps html post summary].freeze
|
|
13
17
|
|
|
14
18
|
# Evaluates the settings block against a new configuration.
|
|
15
19
|
def initialize(&)
|
|
16
20
|
@globs = []
|
|
21
|
+
@skips = []
|
|
22
|
+
@groups = {}
|
|
17
23
|
@reporters = [:gaps]
|
|
18
|
-
@
|
|
24
|
+
@ignored = []
|
|
25
|
+
@treats = []
|
|
19
26
|
instance_eval(&)
|
|
20
27
|
end
|
|
21
28
|
|
|
22
29
|
# The reporters chosen with report, :gaps when none were.
|
|
23
30
|
attr_reader :reporters
|
|
24
31
|
|
|
25
|
-
# What is measured, chosen with measure.
|
|
26
|
-
# :decisions, the paths within each decision, when nothing
|
|
27
|
-
# was chosen.
|
|
28
|
-
attr_reader :measures
|
|
29
|
-
|
|
30
|
-
# Chooses what is measured.
|
|
31
|
-
# Eg measure :decisions, :methods also measures the paths
|
|
32
|
-
# across each method's decisions.
|
|
33
|
-
# Refuses a name there is no measure for.
|
|
34
|
-
def measure(*names)
|
|
35
|
-
check('measure', names, MEASURES)
|
|
36
|
-
@measures = names.map(&:to_sym)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
32
|
# The dir the reports are written to.
|
|
40
33
|
def output_dir
|
|
41
34
|
@coverage_dir
|
|
@@ -60,6 +53,23 @@ module PathCoverage
|
|
|
60
53
|
@globs << glob
|
|
61
54
|
end
|
|
62
55
|
|
|
56
|
+
# Adds a glob, relative to root, of files not to instrument,
|
|
57
|
+
# though a cover glob matches them, eg skip 'source/vendor/**'.
|
|
58
|
+
def skip(glob)
|
|
59
|
+
@skips << glob
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# { name => [glob, ...] } of each group given, in order.
|
|
63
|
+
# Eg { 'Models' => ['source/models/**/*.rb'] }.
|
|
64
|
+
attr_reader :groups
|
|
65
|
+
|
|
66
|
+
# Names a group of covered files, those matching any of
|
|
67
|
+
# globs, relative to root, so the HTML index gives them a
|
|
68
|
+
# tab of their own, eg group 'Models', 'source/models/**'.
|
|
69
|
+
def group(name, *globs)
|
|
70
|
+
@groups[name] = globs
|
|
71
|
+
end
|
|
72
|
+
|
|
63
73
|
# Chooses the reporters run at exit, eg report :gaps;
|
|
64
74
|
# refuses a name there is no reporter for.
|
|
65
75
|
def report(*names)
|
|
@@ -86,10 +96,11 @@ module PathCoverage
|
|
|
86
96
|
@coverage_dir = dir
|
|
87
97
|
end
|
|
88
98
|
|
|
89
|
-
# Every file the cover globs match under root,
|
|
90
|
-
# paths, whether or not the run loads it.
|
|
99
|
+
# Every file the cover globs match under root, and no skip
|
|
100
|
+
# glob does, as full paths, whether or not the run loads it.
|
|
91
101
|
def files
|
|
92
|
-
Dir.glob(@globs, base: @root).sort
|
|
102
|
+
found = Dir.glob(@globs, base: @root).sort
|
|
103
|
+
found.reject { |f| skipped?(f) }.map { |f| "#{@root}/#{f}" }
|
|
93
104
|
end
|
|
94
105
|
|
|
95
106
|
# Where the JSON report goes.
|
|
@@ -102,13 +113,23 @@ module PathCoverage
|
|
|
102
113
|
path.start_with?("#{@root}/") && matches?(relative(path))
|
|
103
114
|
end
|
|
104
115
|
|
|
105
|
-
# True when the root-relative path matches a cover glob
|
|
116
|
+
# True when the root-relative path matches a cover glob and
|
|
117
|
+
# no skip glob.
|
|
106
118
|
def matches?(relative_path)
|
|
119
|
+
return false if skipped?(relative_path)
|
|
120
|
+
|
|
107
121
|
@globs.any? do |glob|
|
|
108
122
|
File.fnmatch?(glob, relative_path, GLOB_FLAGS)
|
|
109
123
|
end
|
|
110
124
|
end
|
|
111
125
|
|
|
126
|
+
# True when the root-relative path matches a skip glob.
|
|
127
|
+
def skipped?(relative_path)
|
|
128
|
+
@skips.any? do |glob|
|
|
129
|
+
File.fnmatch?(glob, relative_path, GLOB_FLAGS)
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
112
133
|
# path relative to root, eg "source/kata.rb".
|
|
113
134
|
def relative(path)
|
|
114
135
|
path.delete_prefix("#{@root}/")
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require_relative 'kinds'
|
|
2
|
+
|
|
3
|
+
module PathCoverage
|
|
4
|
+
# The settings of a PathCoverage.start block that change which
|
|
5
|
+
# paths a site has: ignore, eg ignore '&&=', and treat, eg
|
|
6
|
+
# treat 'name', as: :present. It relies on its includer's
|
|
7
|
+
# @ignored, @treats and check.
|
|
8
|
+
module ConfigurationPaths
|
|
9
|
+
TREATMENTS = %w[present nonempty].freeze
|
|
10
|
+
|
|
11
|
+
# The operators whose sites are not measured, chosen with
|
|
12
|
+
# ignore, eg ['&&=']; none when nothing was chosen.
|
|
13
|
+
attr_reader :ignored
|
|
14
|
+
|
|
15
|
+
# Chooses operators whose sites are not measured, eg
|
|
16
|
+
# ignore '&&=' measures no &&= write; a site inside one, eg
|
|
17
|
+
# on its right side, still is. Refuses an operator there
|
|
18
|
+
# is no kind of site for.
|
|
19
|
+
def ignore(*operators)
|
|
20
|
+
check('operator', operators, Kinds::BY_OPERATOR.keys)
|
|
21
|
+
@ignored = operators
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Treats calls to the method named name as never nil, with
|
|
25
|
+
# as: :present, so a &. after such a call has no nil path;
|
|
26
|
+
# or as true exactly when its receiver has items, with as:
|
|
27
|
+
# :nonempty, eg any?. It applies in each covered file
|
|
28
|
+
# matching glob, relative to root, or in every one with no
|
|
29
|
+
# glob. Refuses any other treatment.
|
|
30
|
+
def treat(name, as:, in: nil)
|
|
31
|
+
check('treatment', [as], TREATMENTS)
|
|
32
|
+
@treats << [name, as.to_s, binding.local_variable_get(:in)]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# The names of the methods treated as as, eg 'present', in
|
|
36
|
+
# the covered file at relative_path.
|
|
37
|
+
def treated(as, relative_path)
|
|
38
|
+
flags = Configuration::GLOB_FLAGS
|
|
39
|
+
@treats.filter_map do |name, treatment, glob|
|
|
40
|
+
next unless treatment == as
|
|
41
|
+
|
|
42
|
+
name if glob.nil? || File.fnmatch?(glob, relative_path, flags)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# The settings that change which paths a site has, eg
|
|
47
|
+
# { 'ignored' => ['&&='],
|
|
48
|
+
# 'treats' => [['name', 'present', nil]] },
|
|
49
|
+
# each only when set: runs whose fingerprints differ list
|
|
50
|
+
# their sites' paths differently.
|
|
51
|
+
def fingerprint
|
|
52
|
+
print = {}
|
|
53
|
+
print['ignored'] = @ignored unless @ignored.empty?
|
|
54
|
+
print['treats'] = @treats unless @treats.empty?
|
|
55
|
+
print
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require_relative 'summary'
|
|
2
|
+
require_relative 'totals'
|
|
3
|
+
|
|
4
|
+
module PathCoverage
|
|
5
|
+
# The :summary reporter's lines: each total as SimpleCov prints
|
|
6
|
+
# its line and branch coverage, eg
|
|
7
|
+
# "Path coverage within decisions: 519 / 623 (83.31%)". With
|
|
8
|
+
# groups configured each group is a heading, its own totals
|
|
9
|
+
# indented under it, and there is no total over every group.
|
|
10
|
+
module ConsoleSummary
|
|
11
|
+
# The summary lines of site_paths and, when cards, { def
|
|
12
|
+
# site => [taken, size] }, are given, as they are when
|
|
13
|
+
# methods are measured, of cards; groups is { name =>
|
|
14
|
+
# [glob, ...] }.
|
|
15
|
+
def self.lines(site_paths, cards, groups = {})
|
|
16
|
+
return totals_lines(totals(site_paths, cards)) if groups.empty?
|
|
17
|
+
|
|
18
|
+
all = group_totals(site_paths, cards, groups)
|
|
19
|
+
all.flat_map do |name, totals|
|
|
20
|
+
["#{name}:", *totals_lines(totals).map { |line| " #{line}" }]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# { 'decisions' => [taken, possible] } of site_paths, with
|
|
25
|
+
# 'methods' => [taken, possible] of cards when given.
|
|
26
|
+
def self.totals(site_paths, cards)
|
|
27
|
+
totals = { 'decisions' => Totals.decisions(site_paths) }
|
|
28
|
+
return totals if cards.nil?
|
|
29
|
+
|
|
30
|
+
totals.merge('methods' => Totals.methods(cards))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# { group name => totals } of each group's own sites and
|
|
34
|
+
# cards alone.
|
|
35
|
+
def self.group_totals(site_paths, cards, groups)
|
|
36
|
+
groups.to_h do |name, globs|
|
|
37
|
+
own_cards = cards ? own(cards, globs) : nil
|
|
38
|
+
[name, totals(own(site_paths, globs), own_cards)]
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# The entries of sites, keyed by site name, in a file matching
|
|
43
|
+
# any of globs.
|
|
44
|
+
def self.own(sites, globs)
|
|
45
|
+
sites.select do |site, _|
|
|
46
|
+
Summary.matches?(Summary.path_of(site), globs)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# The line naming the operators ignored, eg "Path coverage
|
|
51
|
+
# ignores: &&="; none when none are.
|
|
52
|
+
def self.ignored_lines(ignored)
|
|
53
|
+
return [] if ignored.empty?
|
|
54
|
+
|
|
55
|
+
["Path coverage ignores: #{ignored.join(', ')}"]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# A line per total, eg "Path coverage within methods: 1 / 4
|
|
59
|
+
# (25.00%)".
|
|
60
|
+
def self.totals_lines(totals)
|
|
61
|
+
totals.map do |name, pair|
|
|
62
|
+
"Path coverage within #{name}: #{figure(pair)}"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# [taken, possible] as "taken / possible (percent)", its
|
|
67
|
+
# percent to two places, or - when no path is possible.
|
|
68
|
+
def self.figure((taken, possible))
|
|
69
|
+
return "#{taken} / #{possible} (-)" if possible.zero?
|
|
70
|
+
|
|
71
|
+
percent = format('%.2f%%', 100.0 * taken / possible)
|
|
72
|
+
"#{taken} / #{possible} (#{percent})"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
data/lib/path_coverage/gaps.rb
CHANGED
|
@@ -4,28 +4,47 @@ module PathCoverage
|
|
|
4
4
|
# count stays in the operands and paths for reporters that
|
|
5
5
|
# show them all.
|
|
6
6
|
module Gaps
|
|
7
|
-
# The gap lines of operands and
|
|
8
|
-
# them, in manifest order; texts is { site => each
|
|
9
|
-
# source text }.
|
|
10
|
-
|
|
7
|
+
# The gap lines of operands, paths and outside, as Result
|
|
8
|
+
# gives them, in manifest order; texts is { site => each
|
|
9
|
+
# leaf's source text }. A site's first leaf runs before any
|
|
10
|
+
# other, so a site whose first never ran was never reached.
|
|
11
|
+
def self.lines(operands, paths: {}, texts: {}, outside: {})
|
|
11
12
|
operands.flat_map do |site, counts|
|
|
12
|
-
|
|
13
|
-
next ["#{site} never reached"]
|
|
14
|
-
end
|
|
13
|
+
next ["#{site} never reached"] if never_ran?(counts.first)
|
|
15
14
|
|
|
16
|
-
path_gaps(site, paths.fetch(site, []), texts[site])
|
|
15
|
+
path_gaps(site, paths.fetch(site, []), texts[site]) +
|
|
16
|
+
ruled_out(site, outside.fetch(site, {}), texts[site])
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
# One line per path site took that a treatment rules out,
|
|
21
|
+
# as Result#outside gives them, texts being each leaf's
|
|
22
|
+
# source text.
|
|
23
|
+
def self.ruled_out(site, taken, texts)
|
|
24
|
+
taken.keys.map do |path|
|
|
25
|
+
"#{site} path taken that a treatment rules out: " \
|
|
26
|
+
"#{steps(path, texts)}"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# The outcome of each leaf path reaches, each named by its
|
|
31
|
+
# text, eg "`u.name` nil". A path's first leaf always has an
|
|
32
|
+
# outcome, so it always has a step.
|
|
33
|
+
def self.steps(path, texts)
|
|
34
|
+
path.zip(texts).each_with_object([]) do |(outcome, text), all|
|
|
35
|
+
all << "#{code(text)} #{outcome}" unless outcome.nil?
|
|
36
|
+
end.join(', ')
|
|
37
|
+
end
|
|
38
|
+
|
|
20
39
|
# One line per path site never took, as Result#paths gives
|
|
21
40
|
# them, naming the outcome of each leaf the path reaches,
|
|
22
41
|
# texts being each leaf's source text.
|
|
23
42
|
def self.path_gaps(site, paths, texts)
|
|
24
|
-
paths.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"#{site} path never taken: #{
|
|
43
|
+
paths.each_with_object([]) do |each, lines|
|
|
44
|
+
next unless each[:count].zero?
|
|
45
|
+
|
|
46
|
+
named = steps(each[:path], texts)
|
|
47
|
+
lines << "#{site} path never taken: #{named}"
|
|
29
48
|
end
|
|
30
49
|
end
|
|
31
50
|
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
<body>
|
|
14
14
|
<main class="page">
|
|
15
15
|
<header class="head" data-head="">
|
|
16
|
-
<p class="
|
|
17
|
-
<h1 class="path">{{path}}</h1>
|
|
16
|
+
<div class="top"><p class="title"><a data-index="" href="{{index}}">Path coverage</a></p><h1 class="path"><a data-row="" href="{{index}}#row-{{path}}">{{path}}</a></h1><button type="button" class="theme" aria-label="Light or dark"></button></div>
|
|
18
17
|
{{jumps}}
|
|
19
18
|
</header>
|
|
20
19
|
<div class="box">
|
|
21
|
-
|
|
20
|
+
<div class="rail">
|
|
21
|
+
{{rail}}
|
|
22
22
|
</div>
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
{{listing}}
|
|
24
|
+
<div class="divider" role="separator" aria-orientation="vertical" title="Drag to share the width between paths and code"></div>
|
|
25
25
|
</div>
|
|
26
26
|
</main>
|
|
27
27
|
<script>
|
|
@@ -12,25 +12,13 @@
|
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<main class="page">
|
|
15
|
-
<
|
|
15
|
+
<header class="head" data-head="">
|
|
16
|
+
<div class="top"><h1 class="title">Path coverage</h1><button type="button" class="theme" aria-label="Light or dark"></button></div>
|
|
17
|
+
</header>
|
|
18
|
+
{{tabs}}
|
|
16
19
|
<div class="box">
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<tr>
|
|
20
|
-
<th aria-sort="none"><button type="button" data-column="0" data-type="text">File</button></th>
|
|
21
|
-
<th class="num" aria-sort="none"><button type="button" data-column="1" data-type="number">Sites</button></th>
|
|
22
|
-
<th class="num" aria-sort="none"><button type="button" data-column="2" data-type="number">Within each decision</button></th>
|
|
23
|
-
{{across}}
|
|
24
|
-
</tr>
|
|
25
|
-
</thead>
|
|
26
|
-
<tbody>
|
|
27
|
-
{{rows}}
|
|
28
|
-
</tbody>
|
|
29
|
-
<tfoot>
|
|
30
|
-
{{total}}
|
|
31
|
-
</tfoot>
|
|
32
|
-
</table>
|
|
33
|
-
</div>
|
|
20
|
+
{{tables}}
|
|
21
|
+
</div>{{ignored}}
|
|
34
22
|
</main>
|
|
35
23
|
<script>
|
|
36
24
|
//<![CDATA[
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// The report's settings, eg its theme. Each is carried by
|
|
2
|
+
// every link to another page of the report, as ?name=, since some
|
|
3
|
+
// browsers keep nothing shared between a report's local files, and
|
|
4
|
+
// is also kept in the browser where it can be, for a page opened
|
|
5
|
+
// afresh.
|
|
6
|
+
window.pathCoverageSettings = (function () {
|
|
7
|
+
// The value of setting name the link that opened this page
|
|
8
|
+
// carried, else the one last kept, when it is one of allowed;
|
|
9
|
+
// else null.
|
|
10
|
+
function given(name, allowed) {
|
|
11
|
+
var match = new RegExp('[?&]' + name + '=([a-z]+)').exec(window.location.search);
|
|
12
|
+
if (match && allowed.indexOf(match[1]) >= 0) { return match[1]; }
|
|
13
|
+
try {
|
|
14
|
+
var kept = window.localStorage.getItem('path_coverage.' + name);
|
|
15
|
+
return allowed.indexOf(kept) >= 0 ? kept : null;
|
|
16
|
+
} catch (e) { return null; }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Keeps value as setting name's, where the browser allows it.
|
|
20
|
+
function keep(name, value) {
|
|
21
|
+
try { window.localStorage.setItem('path_coverage.' + name, value); } catch (e) { /* carried by links only */ }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// href, a link to another page of the report, with its ?name=
|
|
25
|
+
// set to value, before any #fragment, its other ?settings kept.
|
|
26
|
+
function carrying(href, name, value) {
|
|
27
|
+
var hash = href.indexOf('#');
|
|
28
|
+
var fragment = hash < 0 ? '' : href.slice(hash);
|
|
29
|
+
var rest = hash < 0 ? href : href.slice(0, hash);
|
|
30
|
+
var query = rest.indexOf('?');
|
|
31
|
+
var page = query < 0 ? rest : rest.slice(0, query);
|
|
32
|
+
var settings = query < 0 ? [] : rest.slice(query + 1).split('&').filter(function (pair) {
|
|
33
|
+
return pair && pair.split('=')[0] !== name;
|
|
34
|
+
});
|
|
35
|
+
settings.push(name + '=' + value);
|
|
36
|
+
return page + '?' + settings.join('&') + fragment;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Makes every link to another of the report's pages carry value
|
|
40
|
+
// as setting name's.
|
|
41
|
+
function carry(name, value) {
|
|
42
|
+
document.querySelectorAll('a[href]').forEach(function (link) {
|
|
43
|
+
var href = link.getAttribute('href');
|
|
44
|
+
if (/^[a-z]+:|^#/.test(href) || !/\.html(\?|#|$)/.test(href)) { return; }
|
|
45
|
+
link.setAttribute('href', carrying(href, name, value));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return { given: given, keep: keep, carry: carry };
|
|
50
|
+
})();
|