path_coverage 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +112 -113
- data/lib/path_coverage/calls.rb +4 -11
- data/lib/path_coverage/card.rb +14 -0
- data/lib/path_coverage/condition.rb +8 -1
- data/lib/path_coverage/configuration.rb +1 -17
- data/lib/path_coverage/configuration_paths.rb +4 -2
- data/lib/path_coverage/console_summary.rb +15 -17
- data/lib/path_coverage/gaps.rb +12 -9
- data/lib/path_coverage/html/file.html +5 -5
- data/lib/path_coverage/html/index.html +3 -1
- data/lib/path_coverage/html/settings.js +50 -0
- data/lib/path_coverage/html/side.js +341 -432
- data/lib/path_coverage/html/style.css +330 -225
- data/lib/path_coverage/html/theme.js +27 -0
- data/lib/path_coverage/html_branch.rb +30 -0
- data/lib/path_coverage/html_cards.rb +111 -0
- data/lib/path_coverage/html_cells.rb +66 -0
- data/lib/path_coverage/html_file.rb +82 -68
- data/lib/path_coverage/html_index.rb +28 -29
- data/lib/path_coverage/html_index_head.rb +10 -30
- data/lib/path_coverage/html_labels.rb +23 -0
- data/lib/path_coverage/html_methods.rb +66 -0
- data/lib/path_coverage/html_nav.rb +50 -50
- data/lib/path_coverage/html_report.rb +45 -49
- data/lib/path_coverage/html_statements.rb +166 -0
- data/lib/path_coverage/html_syntax.rb +156 -0
- data/lib/path_coverage/html_template.rb +6 -0
- data/lib/path_coverage/html_tree.rb +36 -72
- data/lib/path_coverage/json_reader.rb +21 -14
- data/lib/path_coverage/json_writer.rb +26 -13
- data/lib/path_coverage/kernel.rb +29 -49
- data/lib/path_coverage/kinds/block.rb +2 -1
- data/lib/path_coverage/kinds/case.rb +7 -4
- data/lib/path_coverage/kinds/contains.rb +6 -4
- data/lib/path_coverage/kinds/safe.rb +5 -3
- data/lib/path_coverage/manifest.rb +2 -1
- data/lib/path_coverage/manifest_blocks.rb +3 -4
- data/lib/path_coverage/manifest_case.rb +2 -3
- data/lib/path_coverage/manifest_choices.rb +4 -3
- data/lib/path_coverage/manifest_folding.rb +1 -1
- data/lib/path_coverage/merge.rb +3 -3
- data/lib/path_coverage/method_statements.rb +300 -0
- data/lib/path_coverage/recorder.rb +12 -31
- data/lib/path_coverage/render.rb +19 -22
- data/lib/path_coverage/rewriter.rb +36 -55
- data/lib/path_coverage/site_tree.rb +9 -0
- data/lib/path_coverage/statement_arms.rb +161 -0
- data/lib/path_coverage/summary.rb +11 -15
- data/lib/path_coverage/totals.rb +6 -12
- data/lib/path_coverage/version.rb +1 -1
- data/lib/path_coverage/within_methods.rb +92 -0
- metadata +16 -11
- data/lib/path_coverage/html/toggle.js +0 -12
- data/lib/path_coverage/html_paths.rb +0 -138
- data/lib/path_coverage/path_gaps.rb +0 -41
- data/lib/path_coverage/path_manifest.rb +0 -110
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
require 'prism'
|
|
2
|
-
require_relative 'manifest'
|
|
3
|
-
require_relative 'site'
|
|
4
|
-
|
|
5
|
-
module PathCoverage
|
|
6
|
-
# One if a method's path passes: its line, the byte range of
|
|
7
|
-
# its predicate, and whether that predicate is a command call.
|
|
8
|
-
# exits is the outcome whose arm always leaves the method,
|
|
9
|
-
# ending the path there, or nil when neither arm does.
|
|
10
|
-
Decision = Data.define(:line, :range, :command, :exits) do
|
|
11
|
-
# A decision with no arm that leaves by default.
|
|
12
|
-
def initialize(line:, range:, command:, exits: nil)
|
|
13
|
-
super
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# A method whose calls each take one path through its
|
|
18
|
-
# decisions, in source order. entry is the byte offset of its
|
|
19
|
-
# first decision's statement, where each call's path starts.
|
|
20
|
-
PathMethod = Data.define(:name, :entry, :decisions)
|
|
21
|
-
|
|
22
|
-
# Finds, without running it, the decisions of each method in
|
|
23
|
-
# source whose paths are to be counted.
|
|
24
|
-
module PathManifest
|
|
25
|
-
# { def site => PathMethod } for each def in source.
|
|
26
|
-
def self.methods(source, path)
|
|
27
|
-
collector = PathMethods.new(path)
|
|
28
|
-
Prism.parse(source).value.accept(collector)
|
|
29
|
-
collector.methods
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Collects each def and the ifs at the top level of its body.
|
|
33
|
-
class PathMethods < Prism::Visitor
|
|
34
|
-
# Starts with no methods found.
|
|
35
|
-
def initialize(path)
|
|
36
|
-
@path = path
|
|
37
|
-
@methods = {}
|
|
38
|
-
super()
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# The methods found so far.
|
|
42
|
-
attr_reader :methods
|
|
43
|
-
|
|
44
|
-
# Notes node's top-level ifs as its decisions, when it has
|
|
45
|
-
# at least two (with fewer its paths are its branches),
|
|
46
|
-
# then any def inside it, each a method of its own.
|
|
47
|
-
def visit_def_node(node)
|
|
48
|
-
ifs = statements_of(node.body).select do |statement|
|
|
49
|
-
statement.type == :if_node
|
|
50
|
-
end
|
|
51
|
-
note(node, ifs) if ifs.size >= 2
|
|
52
|
-
super
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# Notes node as a method whose decisions are ifs.
|
|
56
|
-
def note(node, ifs)
|
|
57
|
-
@methods[Site.of(@path, node)] = PathMethod.new(
|
|
58
|
-
name: node.name,
|
|
59
|
-
entry: ifs.first.location.start_offset,
|
|
60
|
-
decisions: ifs.map { |statement| decision(statement) }
|
|
61
|
-
)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# The top-level statements of a def's body: those before
|
|
65
|
-
# any rescue, and none for an empty or endless def.
|
|
66
|
-
def statements_of(body)
|
|
67
|
-
body = body.statements if body&.type == :begin_node
|
|
68
|
-
body&.type == :statements_node ? body.body : []
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# The Decision of an if statement.
|
|
72
|
-
def decision(statement)
|
|
73
|
-
predicate = statement.predicate
|
|
74
|
-
loc = predicate.location
|
|
75
|
-
Decision.new(
|
|
76
|
-
line: loc.start_line,
|
|
77
|
-
range: loc.start_offset...loc.end_offset,
|
|
78
|
-
command: Manifest.command?(predicate) || false,
|
|
79
|
-
exits: exits(statement)
|
|
80
|
-
)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
LEAVING_CALLS = %i[fail raise].freeze
|
|
84
|
-
|
|
85
|
-
# The outcome of an if statement whose arm always leaves
|
|
86
|
-
# the method: true for its then arm, false for its else
|
|
87
|
-
# arm, nil for neither.
|
|
88
|
-
def exits(statement)
|
|
89
|
-
return true if leaves?(statement.statements)
|
|
90
|
-
|
|
91
|
-
otherwise = statement.subsequent
|
|
92
|
-
false if otherwise&.type == :else_node &&
|
|
93
|
-
leaves?(otherwise.statements)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# True when the last of statements is a return, or a
|
|
97
|
-
# fail or raise of the method's own; false for an empty
|
|
98
|
-
# arm, which has no statements.
|
|
99
|
-
def leaves?(statements)
|
|
100
|
-
return false if statements.nil?
|
|
101
|
-
|
|
102
|
-
last = statements.body.last
|
|
103
|
-
return true if last.type == :return_node
|
|
104
|
-
|
|
105
|
-
last.type == :call_node && last.receiver.nil? &&
|
|
106
|
-
LEAVING_CALLS.include?(last.name)
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|