puppet-debugger 0.17.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +12 -26
  3. data/.rubocop.yml +64 -232
  4. data/.rubocop_todo.yml +89 -147
  5. data/.vscode/launch.json +15 -0
  6. data/CHANGELOG.md +29 -0
  7. data/Gemfile +9 -6
  8. data/README.md +27 -14
  9. data/Rakefile +11 -12
  10. data/bin/pdb +1 -1
  11. data/lib/awesome_print/ext/awesome_puppet.rb +10 -8
  12. data/lib/plugins/puppet-debugger/input_responders/benchmark.rb +5 -4
  13. data/lib/plugins/puppet-debugger/input_responders/classes.rb +14 -2
  14. data/lib/plugins/puppet-debugger/input_responders/classification.rb +4 -2
  15. data/lib/plugins/puppet-debugger/input_responders/commands.rb +18 -18
  16. data/lib/plugins/puppet-debugger/input_responders/datatypes.rb +22 -6
  17. data/lib/plugins/puppet-debugger/input_responders/environment.rb +4 -2
  18. data/lib/plugins/puppet-debugger/input_responders/exit.rb +5 -3
  19. data/lib/plugins/puppet-debugger/input_responders/facterdb_filter.rb +4 -2
  20. data/lib/plugins/puppet-debugger/input_responders/facts.rb +4 -2
  21. data/lib/plugins/puppet-debugger/input_responders/functions.rb +34 -32
  22. data/lib/plugins/puppet-debugger/input_responders/help.rb +4 -2
  23. data/lib/plugins/puppet-debugger/input_responders/krt.rb +4 -2
  24. data/lib/plugins/puppet-debugger/input_responders/play.rb +22 -24
  25. data/lib/plugins/puppet-debugger/input_responders/reset.rb +5 -3
  26. data/lib/plugins/puppet-debugger/input_responders/resources.rb +16 -7
  27. data/lib/plugins/puppet-debugger/input_responders/set.rb +34 -32
  28. data/lib/plugins/puppet-debugger/input_responders/stacktrace.rb +31 -0
  29. data/lib/plugins/puppet-debugger/input_responders/types.rb +6 -2
  30. data/lib/plugins/puppet-debugger/input_responders/vars.rb +8 -7
  31. data/lib/plugins/puppet-debugger/input_responders/whereami.rb +5 -3
  32. data/lib/puppet-debugger/cli.rb +129 -91
  33. data/lib/puppet-debugger/code/code_file.rb +13 -14
  34. data/lib/puppet-debugger/code/code_range.rb +5 -3
  35. data/lib/puppet-debugger/code/loc.rb +1 -1
  36. data/lib/puppet-debugger/debugger_code.rb +2 -0
  37. data/lib/puppet-debugger/hooks.rb +15 -16
  38. data/lib/puppet-debugger/input_responder_plugin.rb +54 -52
  39. data/lib/puppet-debugger/monkey_patches.rb +4 -1
  40. data/lib/puppet-debugger/plugin_test_helper.rb +9 -8
  41. data/lib/puppet-debugger/support.rb +44 -18
  42. data/lib/puppet-debugger/support/environment.rb +6 -5
  43. data/lib/puppet-debugger/support/errors.rb +25 -27
  44. data/lib/puppet-debugger/support/facts.rb +5 -5
  45. data/lib/puppet-debugger/support/node.rb +4 -7
  46. data/lib/puppet-debugger/support/scope.rb +29 -0
  47. data/lib/puppet-debugger/trollop.rb +38 -31
  48. data/lib/puppet-debugger/version.rb +1 -1
  49. data/lib/puppet/application/debugger.rb +151 -126
  50. data/output.json +1 -0
  51. data/puppet-debugger.gemspec +18 -15
  52. data/spec/awesome_print/ext/awesome_puppet_spec.rb +30 -30
  53. data/spec/fixtures/pe-xl-core-0.puppet.vm.json +1 -0
  54. data/spec/fixtures/sample_start_debugger.pp +3 -2
  55. data/spec/hooks_spec.rb +33 -35
  56. data/spec/input_responder_plugin_spec.rb +7 -6
  57. data/spec/input_responders/benchmark_spec.rb +3 -1
  58. data/spec/input_responders/classes_spec.rb +12 -13
  59. data/spec/input_responders/classification_spec.rb +4 -2
  60. data/spec/input_responders/commands_spec.rb +2 -0
  61. data/spec/input_responders/datatypes_spec.rb +8 -2
  62. data/spec/input_responders/environment_spec.rb +2 -0
  63. data/spec/input_responders/exit_spec.rb +9 -11
  64. data/spec/input_responders/facterdb_filter_spec.rb +2 -0
  65. data/spec/input_responders/facts_spec.rb +2 -0
  66. data/spec/input_responders/functions_spec.rb +30 -28
  67. data/spec/input_responders/help_spec.rb +5 -3
  68. data/spec/input_responders/krt_spec.rb +3 -1
  69. data/spec/input_responders/play_spec.rb +10 -20
  70. data/spec/input_responders/reset_spec.rb +2 -0
  71. data/spec/input_responders/resources_spec.rb +7 -1
  72. data/spec/input_responders/set_spec.rb +3 -1
  73. data/spec/input_responders/stacktrace_spec.rb +15 -0
  74. data/spec/input_responders/types_spec.rb +2 -0
  75. data/spec/input_responders/vars_spec.rb +4 -4
  76. data/spec/input_responders/whereami_spec.rb +2 -0
  77. data/spec/pdb_spec.rb +0 -9
  78. data/spec/puppet/application/debugger_spec.rb +35 -17
  79. data/spec/puppet_debugger_spec.rb +81 -84
  80. data/spec/remote_node_spec.rb +1 -5
  81. data/spec/spec_helper.rb +22 -18
  82. data/spec/support_spec.rb +3 -5
  83. data/test_matrix.rb +1 -1
  84. metadata +54 -21
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "spec_helper"
4
- require "stringio"
5
- describe "PuppetDebugger" do
3
+ require 'spec_helper'
4
+ require 'stringio'
5
+ describe 'PuppetDebugger' do
6
6
  let(:resource) do
7
7
  "service{'httpd': ensure => running}"
8
8
  end
9
9
 
10
10
  before(:each) do
11
- debugger.handle_input("reset")
11
+ debugger.handle_input('reset')
12
12
  end
13
13
 
14
14
  let(:output) do
@@ -31,56 +31,54 @@ describe "PuppetDebugger" do
31
31
  debugger.parser.evaluate_string(debugger.scope, input)
32
32
  end
33
33
 
34
- describe "native classes" do
35
- describe "create" do
34
+ describe 'native classes' do
35
+ describe 'create' do
36
36
  let(:input) do
37
- "class testfoo {}"
37
+ 'class testfoo {}'
38
38
  end
39
39
  let(:debugger_output) do
40
- "\n => Puppet::Type::Component {\n loglevel\e[0;37m => \e[0m\e[0;36mnotice\e[0m,\n name\e[0;37m => \e[0m\e[0;33m\"Testfoo\"\e[0m,\n title\e[0;37m => \e[0m\e[0;33m\"Class[Testfoo]\"\e[0m\n}\n"
40
+ " => Puppet::Type::Component {\n loglevel\e[0;37m => \e[0m\e[0;36mnotice\e[0m,\n name\e[0;37m => \e[0m\e[0;33m\"Testfoo\"\e[0m,\n title\e[0;37m => \e[0m\e[0;33m\"Class[Testfoo]\"\e[0m\n}\n"
41
41
  end
42
42
  it do
43
43
  debugger.handle_input(input)
44
- expect(output.string).to eq("\n")
45
- expect(debugger.known_resource_types[:hostclasses]).to include("testfoo")
44
+ expect(output.string).to eq('')
45
+ expect(debugger.known_resource_types[:hostclasses]).to include('testfoo')
46
46
  end
47
47
  it do
48
48
  debugger.handle_input(input)
49
- debugger.handle_input("include testfoo")
50
- expect(debugger.scope.compiler.catalog.classes).to include("testfoo")
49
+ debugger.handle_input('include testfoo')
50
+ expect(debugger.scope.compiler.catalog.classes).to include('testfoo')
51
51
  end
52
52
  it do
53
53
  debugger.handle_input(input)
54
- debugger.handle_input("include testfoo")
55
- expect(debugger.scope.compiler.catalog.resources.map(&:name)).to include("Testfoo")
54
+ debugger.handle_input('include testfoo')
55
+ expect(debugger.scope.compiler.catalog.resources.map(&:name)).to include('Testfoo')
56
56
  end
57
57
  end
58
58
  end
59
59
 
60
- describe "native definitions" do
61
- describe "create" do
60
+ describe 'native definitions' do
61
+ describe 'create' do
62
62
  let(:input) do
63
- "define testfoodefine {}"
63
+ 'define testfoodefine {}'
64
64
  end
65
65
  let(:debugger_output) do
66
- "\n => Puppet::Type::Component {\n loglevel\e[0;37m => \e[0m\e[0;36mnotice\e[0m,\n name\e[0;37m => \e[0m\e[0;33m\"some_name\"\e[0m,\n title\e[0;37m => \e[0m\e[0;33m\"Testfoo[some_name]\"\e[0m\n}\n"
66
+ " => Puppet::Type::Component {\n loglevel\e[0;37m => \e[0m\e[0;36mnotice\e[0m,\n name\e[0;37m => \e[0m\e[0;33m\"some_name\"\e[0m,\n title\e[0;37m => \e[0m\e[0;33m\"Testfoo[some_name]\"\e[0m\n}\n"
67
67
  end
68
68
  it do
69
69
  debugger.handle_input(input)
70
- expect(debugger.scope.environment.known_resource_types.definitions.keys).to include("testfoodefine")
71
- expect(output.string).to eq("\n")
70
+ expect(debugger.scope.environment.known_resource_types.definitions.keys).to include('testfoodefine')
71
+ expect(output.string).to eq('')
72
72
  end
73
73
  it do
74
74
  debugger.handle_input(input)
75
75
  debugger.handle_input("testfoodefine{'some_name':}")
76
- expect(debugger.scope.compiler.resources.collect(&:name)).to include("some_name")
77
- expect(debugger.scope.compiler.resources.collect(&:type)).to include("Testfoodefine")
78
- expect(output.string).to include("\n => Puppet::Type::Component")
76
+ expect(output.string).to include(' => Puppet::Type::Component')
79
77
  end
80
78
  end
81
79
  end
82
80
 
83
- describe "key_words" do
81
+ describe 'key_words' do
84
82
  it do
85
83
  expect(debugger.key_words.count).to be >= 30 if supports_datatypes?
86
84
  end
@@ -90,9 +88,9 @@ describe "PuppetDebugger" do
90
88
  end
91
89
  end
92
90
 
93
- describe "native functions", native_functions: true do
91
+ describe 'native functions', native_functions: true do
94
92
  let(:func) do
95
- <<-EOF
93
+ <<-OUT
96
94
  function debugger::bool2http($arg) {
97
95
  case $arg {
98
96
  false, undef, /(?i:false)/ : { 'Off' }
@@ -100,165 +98,164 @@ describe "PuppetDebugger" do
100
98
  default : { "$arg" }
101
99
  }
102
100
  }
103
- EOF
101
+ OUT
104
102
  end
105
103
  before(:each) do
106
104
  debugger.handle_input(func)
107
105
  end
108
- describe "create" do
109
- it "shows function" do
110
- expect(output.string).to eq("\n")
106
+ describe 'create' do
107
+ it 'shows function' do
108
+ expect(output.string).to eq('')
111
109
  end
112
110
  end
113
- describe "run" do
111
+ describe 'run' do
114
112
  let(:input) do
115
- <<-EOF
113
+ <<-OUT
116
114
  debugger::bool2http(false)
117
- EOF
115
+ OUT
118
116
  end
119
117
  it do
120
118
  debugger.handle_input(input)
121
- expect(output.string).to include("Off")
119
+ expect(output.string).to include('Off')
122
120
  end
123
121
  end
124
122
  end
125
123
 
126
- describe "returns a array of resource_types" do
127
- it "returns resource type" do
128
- expect(resource_types.first.class.to_s).to eq("Puppet::Pops::Types::PResourceType")
124
+ describe 'returns a array of resource_types' do
125
+ it 'returns resource type' do
126
+ expect(resource_types.first.class.to_s).to eq('Puppet::Pops::Types::PResourceType')
129
127
  end
130
128
  end
131
129
 
132
- describe "empty" do
130
+ describe 'empty' do
133
131
  let(:input) do
134
- ""
132
+ ''
135
133
  end
136
- it "can run" do
137
- debugger_output = "\n"
134
+ it 'can run' do
135
+ debugger_output = ''
136
+ debugger.handle_input(input)
138
137
  debugger.handle_input(input)
139
138
  expect(output.string).to eq(debugger_output)
140
139
  end
141
- describe "space" do
140
+ describe 'space' do
142
141
  let(:input) do
143
- " "
142
+ ' '
144
143
  end
145
- it "can run" do
146
- debugger_output = "\n"
144
+ it 'can run' do
145
+ debugger_output = ''
147
146
  debugger.handle_input(input)
148
147
  expect(output.string).to eq(debugger_output)
149
148
  end
150
149
  end
151
150
  end
152
151
 
153
- describe "variables" do
152
+ describe 'variables' do
154
153
  let(:input) do
155
154
  "$file_path = '/tmp/test2.txt'"
156
155
  end
157
- it "can process a variable" do
156
+ it 'can process a variable' do
158
157
  debugger.handle_input(input)
159
- expect(output.string).to match(/\/tmp\/test2.txt/)
158
+ expect(output.string).to match(%r{/tmp/test2.txt})
160
159
  end
161
160
  end
162
161
 
163
- describe "resource" do
162
+ describe 'resource' do
164
163
  let(:input) do
165
164
  "file{'/tmp/test2.txt': ensure => present, mode => '0755'}"
166
165
  end
167
- it "can process a resource" do
166
+ it 'can process a resource' do
168
167
  debugger_output = /Puppet::Type::File/
169
168
  debugger.handle_input(input)
170
169
  expect(output.string).to match(debugger_output)
171
170
  end
172
171
  end
173
172
 
174
- describe "bad input" do
173
+ describe 'bad input' do
175
174
  let(:input) do
176
- "Service{"
175
+ 'Service{'
177
176
  end
178
- it "can process" do
177
+ it 'can process' do
179
178
  debugger.handle_input(input)
180
- expect(output.string).to match(%r(Syntax error at end of))
179
+ expect(output.string).to match(/Syntax error at end of/)
181
180
  end
182
181
  end
183
182
 
184
- describe "map block" do
183
+ describe 'map block' do
185
184
  let(:input) do
186
185
  "['/tmp/test3', '/tmp/test4'].map |String $path| { file{$path: ensure => present} }"
187
186
  end
188
- it "can process a each block" do
187
+ it 'can process a each block' do
189
188
  debugger_output = /Puppet::Type::File/
190
189
  debugger.handle_input(input)
191
190
  expect(output.string).to match(debugger_output)
192
191
  end
193
192
  end
194
193
 
195
- describe "each block" do
194
+ describe 'each block' do
196
195
  let(:input) do
197
196
  "['/tmp/test3', '/tmp/test4'].each |String $path| { file{$path: ensure => present} }"
198
197
  end
199
- it "can process a each block" do
198
+ it 'can process a each block' do
200
199
  debugger.handle_input(input)
201
- expect(output.string).to match(/\/tmp\/test3/)
202
- expect(output.string).to match(/\/tmp\/test4/)
200
+ expect(output.string).to match(%r{/tmp/test3})
201
+ expect(output.string).to match(%r{/tmp/test4})
203
202
  end
204
203
  end
205
204
 
206
- describe "string" do
205
+ describe 'string' do
207
206
  let(:input) do
208
- "String"
207
+ 'String'
209
208
  end
210
- it "shows type" do
209
+ it 'shows type' do
211
210
  debugger.handle_input(input)
212
- expect(output.string).to eq("\n => String\n")
211
+ expect(output.string).to eq(" => String\n")
213
212
  end
214
213
  end
215
- describe "Array", type_function: true do
214
+ describe 'Array', type_function: true do
216
215
  let(:input) do
217
- "type([1,2,3,4])"
216
+ 'type([1,2,3,4])'
218
217
  end
219
- it "shows type" do
220
- if Gem::Version.new(Puppet.version) > Gem::Version.new("4.4")
221
- out = "\n => Tuple[Integer[1, 1], Integer[2, 2], Integer[3, 3], Integer[4, 4]]\n"
222
- debugger.handle_input(input)
223
- expect(output.string).to eq(out)
224
- end
218
+ it 'shows type' do
219
+ debugger.handle_input(input)
220
+ out = " => Tuple[Integer[1, 1], Integer[2, 2], Integer[3, 3], Integer[4, 4]]\n"
221
+ expect(output.string).to eq(out)
225
222
  end
226
223
  end
227
224
 
228
- describe "multi diemension array" do
225
+ describe 'multi diemension array' do
229
226
  let(:input) do
230
- "[[1, [23,4], [22], [1,[2232]]]]"
227
+ '[[1, [23,4], [22], [1,[2232]]]]'
231
228
  end
232
229
 
233
- it "handles multi array" do
230
+ it 'handles multi array' do
234
231
  debugger.handle_input(input)
235
- expect(output.string.count("[")).to be >= 17
232
+ expect(output.string.count('[')).to be >= 17
236
233
  end
237
234
  end
238
235
 
239
- describe "command_completion" do
240
- it "should complete on tabs" do
236
+ describe 'command_completion' do
237
+ it 'should complete on tabs' do
241
238
  allow(Readline).to receive(:line_buffer).and_return("\n")
242
- expect(debugger.command_completion.call("").count).to be >= 200
239
+ expect(debugger.command_completion.call('').count).to be >= 200
243
240
  end
244
241
 
245
- it "#key_words" do
242
+ it '#key_words' do
246
243
  expect(debugger.key_words.count).to be >= 100
247
244
  end
248
245
  end
249
246
 
250
- describe "error message" do
247
+ describe 'error message' do
251
248
  let(:input) do
252
249
  "file{'/tmp/test': ensure => present, contact => 'blah'}"
253
250
  end
254
- if Gem::Version.new(Puppet.version) >= Gem::Version.new("4.0")
255
- it "show error message" do
251
+ if Gem::Version.new(Puppet.version) >= Gem::Version.new('4.0')
252
+ it 'show error message' do
256
253
  debugger_output = /no\ parameter\ named\ 'contact'/
257
254
  debugger.handle_input(input)
258
255
  expect(output.string).to match(debugger_output)
259
256
  end
260
257
  else
261
- it "show error message" do
258
+ it 'show error message' do
262
259
  debugger_output = /Invalid\ parameter\ contact/
263
260
  debugger.handle_input(input)
264
261
  expect(output.string).to match(debugger_output)
@@ -41,7 +41,7 @@ describe 'PuppetDebugger' do
41
41
 
42
42
  describe 'set' do
43
43
  it 'sends message about resetting' do
44
- expect(output.string).to eq("\nResetting to use node puppetdev.localdomain\n")
44
+ expect(output.string).to eq(" => Resetting to use node puppetdev.localdomain\n")
45
45
  end
46
46
 
47
47
  it 'return node name' do
@@ -74,10 +74,6 @@ describe 'PuppetDebugger' do
74
74
  let(:node_name) do
75
75
  'invalid.localdomain'
76
76
  end
77
- # this test stopped working in the puppet 5.x series
78
- xit 'name' do
79
- expect { debugger.node.name }.to raise_error(PuppetDebugger::Exception::UndefinedNode)
80
- end
81
77
  end
82
78
 
83
79
  it 'set node name' do
data/spec/spec_helper.rb CHANGED
@@ -1,25 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'simplecov'
4
3
  require_relative '../lib/puppet-debugger'
5
4
  require 'yaml'
6
- ENV['COVERAGE'] = 'true'
5
+ ENV['CI'] = 'true'
7
6
 
8
- module SimpleCov::Configuration
9
- def clean_filters
10
- @filters = []
7
+ if ENV['COVERAGE']
8
+ require 'simplecov'
9
+
10
+ module SimpleCov::Configuration
11
+ def clean_filters
12
+ @filters = []
13
+ end
11
14
  end
12
- end
13
15
 
14
- SimpleCov.configure do
15
- clean_filters
16
- load_profile 'test_frameworks'
17
- end
16
+ SimpleCov.configure do
17
+ clean_filters
18
+ load_profile 'test_frameworks'
19
+ end
18
20
 
19
- SimpleCov.start do
20
- add_filter '/.rvm/'
21
- add_filter 'vendor'
22
- add_filter 'bundler'
21
+ if ENV['COVERAGE']
22
+ SimpleCov.start do
23
+ add_filter '/.rvm/'
24
+ add_filter 'vendor'
25
+ add_filter 'bundler'
26
+ end
27
+ end
23
28
  end
24
29
 
25
30
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -30,17 +35,17 @@ require 'puppet-debugger'
30
35
  ENV['REPL_FACTERDB_FILTER'] = 'operatingsystem=Fedora and operatingsystemrelease=23 and architecture=x86_64 and facterversion=/^2\\.4/'
31
36
  # Requires supporting files with custom matchers and macros, etc,
32
37
  # in ./support/ and its subdirectories.
33
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
38
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
34
39
 
35
40
  def stdlib_path
36
41
  File.join(Puppet[:basemodulepath].split(':').first, 'stdlib')
37
42
  end
38
43
 
39
44
  def install_stdlib
40
- `bundle exec puppet module install puppetlabs/stdlib` unless File.exists?(stdlib_path)
45
+ `bundle exec puppet module install puppetlabs/stdlib` unless File.exist?(stdlib_path)
41
46
  end
42
47
 
43
- #install_stdlib
48
+ # install_stdlib
44
49
 
45
50
  def fixtures_dir
46
51
  File.join(File.dirname(__FILE__), 'fixtures')
@@ -62,7 +67,6 @@ def supports_datatypes?
62
67
  Gem::Version.new(Puppet.version) >= Gem::Version.new('4.5')
63
68
  end
64
69
 
65
-
66
70
  RSpec.configure do |config|
67
71
  config.filter_run_excluding native_functions: !supports_native_functions?
68
72
  RSpec::Expectations.configuration.on_potential_false_positives = :nothing
data/spec/support_spec.rb CHANGED
@@ -21,19 +21,19 @@ describe 'support' do
21
21
  end
22
22
 
23
23
  let(:manifest_file) do
24
- file = File.open('/tmp/debugger_puppet_manifest.pp', 'w') do |f|
24
+ File.open('/tmp/debugger_puppet_manifest.pp', 'w') do |f|
25
25
  f.write(manifest_code)
26
26
  end
27
27
  '/tmp/debugger_puppet_manifest.pp'
28
28
  end
29
29
 
30
30
  let(:manifest_code) do
31
- <<-EOF
31
+ <<-OUT
32
32
  file{'/tmp/test.txt': ensure => absent } \n
33
33
  notify{'hello_there':} \n
34
34
  service{'httpd': ensure => running}\n
35
35
 
36
- EOF
36
+ OUT
37
37
  end
38
38
 
39
39
  after(:each) do
@@ -61,6 +61,4 @@ describe 'support' do
61
61
  expect(debugger.node.facts.values).to be_instance_of(Hash)
62
62
  expect(debugger.node.facts.values['fqdn']).to eq('foo.example.com')
63
63
  end
64
-
65
-
66
64
  end