puppet-debugger 0.4.1 → 0.4.2
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/.gitlab-ci.yml +25 -2
- data/.release_me.yaml +11 -0
- data/.rubocop.yml +239 -0
- data/.rubocop_todo.yml +196 -0
- data/.ruby-version +1 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +17 -1
- data/bin/pdb +1 -0
- data/lib/awesome_print/ext/awesome_puppet.rb +6 -5
- data/lib/puppet/application/debugger.rb +24 -24
- data/lib/puppet-debugger/cli.rb +76 -81
- data/lib/puppet-debugger/code/code_file.rb +82 -82
- data/lib/puppet-debugger/code/code_range.rb +56 -57
- data/lib/puppet-debugger/code/loc.rb +68 -70
- data/lib/puppet-debugger/debugger_code.rb +279 -280
- data/lib/puppet-debugger/support/compiler.rb +1 -1
- data/lib/puppet-debugger/support/environment.rb +2 -2
- data/lib/puppet-debugger/support/errors.rb +3 -4
- data/lib/puppet-debugger/support/facts.rb +7 -7
- data/lib/puppet-debugger/support/functions.rb +4 -5
- data/lib/puppet-debugger/support/input_responders.rb +26 -28
- data/lib/puppet-debugger/support/node.rb +7 -6
- data/lib/puppet-debugger/support/play.rb +16 -24
- data/lib/puppet-debugger/support/scope.rb +3 -4
- data/lib/puppet-debugger/support.rb +38 -40
- data/lib/puppet-debugger.rb +38 -17
- data/lib/version.rb +2 -1
- data/spec/facts_spec.rb +7 -6
- data/spec/pdb_spec.rb +1 -0
- data/spec/puppet/application/debugger_spec.rb +2 -3
- data/spec/{puppet-debugger_spec.rb → puppet_debugger_spec.rb} +27 -33
- data/spec/remote_node_spec.rb +13 -14
- data/spec/spec_helper.rb +8 -7
- data/spec/support_spec.rb +19 -24
- data/test_matrix.rb +4 -3
- metadata +6 -2
@@ -1,98 +1,98 @@
|
|
1
1
|
|
2
|
+
# frozen_string_literal: true
|
2
3
|
class CodeFile
|
3
|
-
class SourceNotFound <
|
4
|
+
class SourceNotFound < RuntimeError
|
4
5
|
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
# @return [String] The code contained in the current `@filename`.
|
39
|
-
def code
|
40
|
-
path = abs_path
|
41
|
-
@code_type = type_from_filename(path)
|
42
|
-
File.read(path)
|
43
|
-
end
|
7
|
+
DEFAULT_EXT = '.pp'
|
8
|
+
|
9
|
+
# List of all supported languages.
|
10
|
+
# @return [Hash]
|
11
|
+
EXTENSIONS = {
|
12
|
+
%w(.py) => :python,
|
13
|
+
%w(.js) => :javascript,
|
14
|
+
%w(.pp) => :puppet,
|
15
|
+
%w(.css) => :css,
|
16
|
+
%w(.xml) => :xml,
|
17
|
+
%w(.php) => :php,
|
18
|
+
%w(.html) => :html,
|
19
|
+
%w(.diff) => :diff,
|
20
|
+
%w(.java) => :java,
|
21
|
+
%w(.json) => :json,
|
22
|
+
%w(.c .h) => :c,
|
23
|
+
%w(.rhtml) => :rhtml,
|
24
|
+
%w(.yaml .yml) => :yaml,
|
25
|
+
%w(.cpp .hpp .cc .h cxx) => :cpp,
|
26
|
+
%w(.rb .ru .irbrc .gemspec .pryrc) => :ruby
|
27
|
+
}.freeze
|
28
|
+
|
29
|
+
# @return [Symbol] The type of code stored in this wrapper.
|
30
|
+
attr_reader :code_type
|
31
|
+
|
32
|
+
# @param [String] filename The name of a file with code to be detected
|
33
|
+
# @param [Symbol] code_type The type of code the `filename` contains
|
34
|
+
def initialize(filename, code_type = type_from_filename(filename))
|
35
|
+
@filename = filename
|
36
|
+
@code_type = code_type
|
37
|
+
end
|
44
38
|
|
45
|
-
|
39
|
+
# @return [String] The code contained in the current `@filename`.
|
40
|
+
def code
|
41
|
+
path = abs_path
|
42
|
+
@code_type = type_from_filename(path)
|
43
|
+
File.read(path)
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
# readable for some reason.
|
49
|
-
# @return [String] absolute path for the given `filename`.
|
50
|
-
def abs_path
|
51
|
-
code_path.detect { |path| readable?(path) } or
|
52
|
-
raise SourceNotFound,
|
53
|
-
"Cannot open #{ @filename.inspect } for reading."
|
54
|
-
end
|
46
|
+
private
|
55
47
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
48
|
+
# @raise [MethodSource::SourceNotFoundError] if the `filename` is not
|
49
|
+
# readable for some reason.
|
50
|
+
# @return [String] absolute path for the given `filename`.
|
51
|
+
def abs_path
|
52
|
+
code_path.detect { |path| readable?(path) } ||
|
53
|
+
raise(SourceNotFound,
|
54
|
+
"Cannot open #{@filename.inspect} for reading.")
|
55
|
+
end
|
63
56
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
57
|
+
# @param [String] path
|
58
|
+
# @return [Boolean] if the path, with or without the default ext,
|
59
|
+
# is a readable file then `true`, otherwise `false`.
|
60
|
+
def readable?(path)
|
61
|
+
File.readable?(path) && !File.directory?(path) ||
|
62
|
+
File.readable?(path << DEFAULT_EXT)
|
63
|
+
end
|
69
64
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
def type_from_filename(filename, default = :unknown)
|
76
|
-
_, @code_type = EXTENSIONS.find do |k, _|
|
77
|
-
k.any? { |ext| ext == File.extname(filename) }
|
78
|
-
end
|
65
|
+
# @return [Array] All the paths that contain code that Pry can use for its
|
66
|
+
# API's. Skips directories.
|
67
|
+
def code_path
|
68
|
+
[from_pwd, from_pry_init_pwd, *from_load_path]
|
69
|
+
end
|
79
70
|
|
80
|
-
|
71
|
+
# @param [String] filename
|
72
|
+
# @param [Symbol] default (:unknown) the file type to assume if none could be
|
73
|
+
# detected.
|
74
|
+
# @return [Symbol, nil] The CodeRay type of a file from its extension, or
|
75
|
+
# `nil` if `:unknown`.
|
76
|
+
def type_from_filename(filename, default = :unknown)
|
77
|
+
_, @code_type = EXTENSIONS.find do |k, _|
|
78
|
+
k.any? { |ext| ext == File.extname(filename) }
|
81
79
|
end
|
82
80
|
|
83
|
-
|
84
|
-
|
85
|
-
File.expand_path(@filename, Dir.pwd)
|
86
|
-
end
|
81
|
+
code_type || default
|
82
|
+
end
|
87
83
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
84
|
+
# @return [String]
|
85
|
+
def from_pwd
|
86
|
+
File.expand_path(@filename, Dir.pwd)
|
87
|
+
end
|
92
88
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
89
|
+
# @return [String]
|
90
|
+
def from_pry_init_pwd
|
91
|
+
File.expand_path(@filename, Dir.pwd)
|
92
|
+
end
|
97
93
|
|
94
|
+
# @return [String]
|
95
|
+
def from_load_path
|
96
|
+
$LOAD_PATH.map { |path| File.expand_path(@filename, path) }
|
97
|
+
end
|
98
98
|
end
|
@@ -1,69 +1,68 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class DebuggerCode
|
3
|
+
# Represents a range of lines in a code listing.
|
4
|
+
#
|
5
|
+
# @api private
|
6
|
+
class CodeRange
|
7
|
+
# @param [Integer] start_line
|
8
|
+
# @param [Integer?] end_line
|
9
|
+
def initialize(start_line, end_line = nil)
|
10
|
+
@start_line = start_line
|
11
|
+
@end_line = end_line
|
12
|
+
force_set_end_line
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
# @param [Array<LOC>] lines
|
16
|
+
# @return [Range]
|
17
|
+
def indices_range(lines)
|
18
|
+
Range.new(*indices(lines))
|
19
|
+
end
|
21
20
|
|
22
|
-
|
21
|
+
private
|
23
22
|
|
24
|
-
|
25
|
-
def end_line; @end_line; end
|
23
|
+
attr_reader :start_line
|
26
24
|
|
27
|
-
|
28
|
-
# parameter, `start_line`. Otherwise, leave it as it is.
|
29
|
-
# @return [void]
|
30
|
-
def force_set_end_line
|
31
|
-
if start_line.is_a?(Range)
|
32
|
-
set_end_line_from_range
|
33
|
-
else
|
34
|
-
@end_line ||= start_line
|
35
|
-
end
|
36
|
-
end
|
25
|
+
attr_reader :end_line
|
37
26
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
27
|
+
# If `end_line` is equal to `nil`, then calculate it from the first
|
28
|
+
# parameter, `start_line`. Otherwise, leave it as it is.
|
29
|
+
# @return [void]
|
30
|
+
def force_set_end_line
|
31
|
+
if start_line.is_a?(Range)
|
32
|
+
set_end_line_from_range
|
33
|
+
else
|
34
|
+
@end_line ||= start_line
|
45
35
|
end
|
36
|
+
end
|
46
37
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
38
|
+
# Finds indices of `start_line` and `end_line` in the given Array of
|
39
|
+
# +lines+.
|
40
|
+
#
|
41
|
+
# @param [Array<LOC>] lines
|
42
|
+
# @return [Array<Integer>]
|
43
|
+
def indices(lines)
|
44
|
+
[find_start_index(lines), find_end_index(lines)]
|
45
|
+
end
|
52
46
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
47
|
+
# @return [Integer]
|
48
|
+
def find_start_index(lines)
|
49
|
+
return start_line if start_line < 0
|
50
|
+
lines.index { |loc| loc.lineno >= start_line } || lines.length
|
51
|
+
end
|
58
52
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
@end_line = start_line.last
|
64
|
-
@end_line -= 1 if start_line.exclude_end?
|
65
|
-
@start_line = start_line.first
|
66
|
-
end
|
53
|
+
# @return [Integer]
|
54
|
+
def find_end_index(lines)
|
55
|
+
return end_line if end_line < 0
|
56
|
+
(lines.index { |loc| loc.lineno > end_line } || 0) - 1
|
67
57
|
end
|
68
58
|
|
59
|
+
# For example, if the range is 4..10, then `start_line` would be equal to
|
60
|
+
# 4 and `end_line` to 10.
|
61
|
+
# @return [void]
|
62
|
+
def set_end_line_from_range
|
63
|
+
@end_line = start_line.last
|
64
|
+
@end_line -= 1 if start_line.exclude_end?
|
65
|
+
@start_line = start_line.first
|
66
|
+
end
|
67
|
+
end
|
69
68
|
end
|
@@ -1,80 +1,78 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class DebuggerCode
|
3
|
+
# Represents a line of code. A line of code is a tuple, which consists of a
|
4
|
+
# line and a line number. A `LOC` object's state (namely, the line
|
5
|
+
# parameter) can be changed via instance methods. `Pry::Code` heavily uses
|
6
|
+
# this class.
|
7
|
+
#
|
8
|
+
# @api private
|
9
|
+
# @example
|
10
|
+
# loc = LOC.new("def example\n :example\nend", 1)
|
11
|
+
# puts loc.line
|
12
|
+
# def example
|
13
|
+
# :example
|
14
|
+
# end
|
15
|
+
# #=> nil
|
16
|
+
#
|
17
|
+
# loc.indent(3)
|
18
|
+
# loc.line #=> " def example\n :example\nend"
|
19
|
+
class LOC
|
20
|
+
# @return [Array<String, Integer>]
|
21
|
+
attr_reader :tuple
|
2
22
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# @api private
|
9
|
-
# @example
|
10
|
-
# loc = LOC.new("def example\n :example\nend", 1)
|
11
|
-
# puts loc.line
|
12
|
-
# def example
|
13
|
-
# :example
|
14
|
-
# end
|
15
|
-
# #=> nil
|
16
|
-
#
|
17
|
-
# loc.indent(3)
|
18
|
-
# loc.line #=> " def example\n :example\nend"
|
19
|
-
class LOC
|
20
|
-
|
21
|
-
# @return [Array<String, Integer>]
|
22
|
-
attr_reader :tuple
|
23
|
-
|
24
|
-
# @param [String] line The line of code.
|
25
|
-
# @param [Integer] lineno The position of the +line+.
|
26
|
-
def initialize(line, lineno)
|
27
|
-
@tuple = [line.chomp, lineno.to_i]
|
28
|
-
end
|
29
|
-
|
30
|
-
# @return [Boolean]
|
31
|
-
def ==(other)
|
32
|
-
other.tuple == tuple
|
33
|
-
end
|
23
|
+
# @param [String] line The line of code.
|
24
|
+
# @param [Integer] lineno The position of the +line+.
|
25
|
+
def initialize(line, lineno)
|
26
|
+
@tuple = [line.chomp, lineno.to_i]
|
27
|
+
end
|
34
28
|
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
# @return [Boolean]
|
30
|
+
def ==(other)
|
31
|
+
other.tuple == tuple
|
32
|
+
end
|
38
33
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
34
|
+
def dup
|
35
|
+
self.class.new(line, lineno)
|
36
|
+
end
|
43
37
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
38
|
+
# @return [String]
|
39
|
+
def line
|
40
|
+
tuple.first
|
41
|
+
end
|
48
42
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
padded = lineno.to_s.rjust(max_width)
|
54
|
-
tuple[0] = "#{ padded }: #{ line }"
|
55
|
-
end
|
43
|
+
# @return [Integer]
|
44
|
+
def lineno
|
45
|
+
tuple.last
|
46
|
+
end
|
56
47
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
if lineno == marker_lineno
|
65
|
-
" => #{ line }".cyan
|
66
|
-
else
|
67
|
-
" #{ line }"
|
68
|
-
end
|
69
|
-
end
|
48
|
+
# Prepends the line number `lineno` to the `line`.
|
49
|
+
# @param [Integer] max_width
|
50
|
+
# @return [void]
|
51
|
+
def add_line_number(max_width = 0)
|
52
|
+
padded = lineno.to_s.rjust(max_width)
|
53
|
+
tuple[0] = "#{padded}: #{line}"
|
54
|
+
end
|
70
55
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
56
|
+
# Prepends a marker "=>" or an empty marker to the +line+.
|
57
|
+
#
|
58
|
+
# @param [Integer] marker_lineno If it is equal to the `lineno`, then
|
59
|
+
# prepend a hashrocket. Otherwise, an empty marker.
|
60
|
+
# @return [void]
|
61
|
+
def add_marker(marker_lineno)
|
62
|
+
tuple[0] =
|
63
|
+
if lineno == marker_lineno
|
64
|
+
" => #{line}".cyan
|
65
|
+
else
|
66
|
+
" #{line}"
|
67
|
+
end
|
78
68
|
end
|
79
69
|
|
70
|
+
# Indents the `line` with +distance+ spaces.
|
71
|
+
#
|
72
|
+
# @param [Integer] distance
|
73
|
+
# @return [void]
|
74
|
+
def indent(distance)
|
75
|
+
tuple[0] = "#{' ' * distance}#{line}"
|
76
|
+
end
|
77
|
+
end
|
80
78
|
end
|