pry-moves 0.1.10 → 1.0.1

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +7 -5
  4. data/README.md +18 -8
  5. data/lib/commands/debug.rb +17 -0
  6. data/lib/commands/finish.rb +26 -0
  7. data/lib/commands/goto.rb +19 -0
  8. data/lib/commands/iterate.rb +22 -0
  9. data/lib/commands/next.rb +37 -0
  10. data/lib/commands/next_breakpoint.rb +22 -0
  11. data/lib/commands/step.rb +83 -0
  12. data/lib/commands/trace_command.rb +87 -0
  13. data/lib/commands/trace_helpers.rb +49 -0
  14. data/lib/commands/traced_method.rb +71 -0
  15. data/lib/debug_sugar.rb +72 -0
  16. data/lib/pry-moves/add_suffix.rb +87 -0
  17. data/lib/pry-moves/backtrace.rb +81 -50
  18. data/lib/pry-moves/bindings_stack.rb +97 -0
  19. data/lib/pry-moves/commands.rb +50 -7
  20. data/lib/pry-moves/formatter.rb +75 -0
  21. data/lib/pry-moves/painter.rb +5 -1
  22. data/lib/pry-moves/pry_ext.rb +64 -16
  23. data/lib/pry-moves/pry_wrapper.rb +30 -17
  24. data/lib/pry-moves/recursion_tracker.rb +94 -0
  25. data/lib/pry-moves/restartable.rb +38 -0
  26. data/lib/pry-moves/version.rb +1 -1
  27. data/lib/pry-moves/watch.rb +3 -0
  28. data/lib/pry-moves.rb +66 -4
  29. data/lib/pry-stack_explorer/VERSION +2 -0
  30. data/lib/pry-stack_explorer/frame_manager.rb +6 -9
  31. data/lib/pry-stack_explorer/pry-stack_explorer.rb +3 -17
  32. data/lib/pry-stack_explorer/{commands.rb → stack_commands.rb} +10 -6
  33. data/lib/pry-stack_explorer/when_started_hook.rb +17 -63
  34. data/playground/Gemfile.lock +9 -9
  35. data/playground/README.md +1 -0
  36. data/playground/playground.rb +94 -9
  37. data/playground/sand.rb +45 -12
  38. data/playground/test.rb +5 -1
  39. data/playground/test.sh +1 -0
  40. data/pry-moves.gemspec +3 -2
  41. data/publish.sh +3 -0
  42. data/spec/backtrace_spec.rb +11 -13
  43. data/spec/blocks_spec.rb +41 -8
  44. data/spec/commands_spec.rb +26 -25
  45. data/spec/pry_debugger.rb +5 -1
  46. data/spec/redirection_spec.rb +7 -0
  47. data/spec/spec_helper.rb +9 -4
  48. data/spec/step_spec.rb +51 -0
  49. metadata +44 -10
  50. data/lib/pry-moves/helpers.rb +0 -50
  51. data/lib/pry-moves/trace_commands.rb +0 -105
  52. data/lib/pry-moves/tracer.rb +0 -169
@@ -16,6 +16,23 @@ class Playground
16
16
  binding.pry # step_into stop
17
17
  something_inside # point to step inside
18
18
  end
19
+
20
+ def skip_hidden_impl
21
+ binding.pry # skip_hidden_impl stop
22
+ hidden_self.something_inside # point to step inside
23
+ end
24
+
25
+ def hidden_self
26
+ hide_from_stack = true # hidden_self 1
27
+ self # hidden_self 2
28
+ end
29
+
30
+ def hidden_stop
31
+ hide_from_stack = true
32
+ binding.pry # hidden stop
33
+ dummy = :ok_next # hidden_stop for next
34
+ dummy = :ok_step # hidden_stop for step
35
+ end
19
36
 
20
37
  def continue
21
38
  binding.pry # first stop
@@ -39,6 +56,16 @@ class Playground
39
56
  step_by_name
40
57
  :after_step_by_name # after_step_by_name
41
58
  end
59
+
60
+ def early_return_wrap
61
+ early_return
62
+ :after_return # after early return
63
+ end
64
+
65
+ def early_return
66
+ return true if level_c # at early return
67
+ dummy = 1
68
+ end
42
69
 
43
70
  def level_a
44
71
  level_b # inside of level_a
@@ -52,7 +79,7 @@ class Playground
52
79
  def level_c(param = nil)
53
80
  binding.pry # stop in level_c
54
81
  self
55
- end
82
+ end # exit from level_c
56
83
 
57
84
  def nested_block(early_return: false)
58
85
  binding.pry # stop in nested_block
@@ -62,7 +89,7 @@ class Playground
62
89
  end
63
90
  :after_block # after block
64
91
  end
65
-
92
+
66
93
  def native_block(early_return: false)
67
94
  binding.pry # stop in native_block
68
95
  2.times do |i| # iterator line
@@ -72,25 +99,83 @@ class Playground
72
99
  :after_block # after block
73
100
  end
74
101
 
102
+ def one_line_in_block
103
+ binding.pry # stop in one_line_in_block
104
+ iterator do |i| # iterator line
105
+ dummy = 1 # inside block
106
+ end
107
+ :after_block # after block
108
+ end
109
+
110
+ def one_line_block
111
+ binding.pry # stop in one_line_block
112
+ iterator { |i| dummy = 1 } # iterator line
113
+ :after_block # after block
114
+ end
115
+
116
+ def parentheses_in_loop
117
+ binding.pry # stop in parentheses_in_loop
118
+ i = 2
119
+ while (i = i - 1) > 0 # iterator line
120
+ dummy = 1 # inside block
121
+ end
122
+ :after_block # after block
123
+ end
124
+
75
125
  def zaloop(pass = :root)
76
126
  binding.pry if pass == :root # stop in zaloop
77
- iterator do |i|
127
+ iterator do |i| # iterator line
78
128
  dummy = 1 # inside block
79
129
  zaloop i if pass == :root
130
+ return unless pass == :root # after sub-zaloop
80
131
  end
81
132
  :after_block # after block
82
- end
133
+ end # exit from zaloop
83
134
 
84
135
  def method_with_redirection
85
- debug_redirect = '=level_a' # at method_with_redirection
136
+ debug_redirect = :level_a # at method_with_redirection
86
137
  level_a
87
138
  end
88
139
 
140
+ def instant_redirection
141
+ debug_redirect = '=something_inside'
142
+ binding.pry # at instant_redirection
143
+ something_inside
144
+ end
145
+
89
146
  def redirection_host
90
147
  binding.pry # redirection host
91
148
  method_with_redirection
92
149
  end
93
150
 
151
+ def something_inside
152
+ :something # some internal line
153
+ end
154
+
155
+ def method_with_breakpoints
156
+ binding.pry # method_with_breakpoints host
157
+ dummy = 1 # some internal line
158
+ debug_ # breakpoint
159
+ dummy = 1 # after breakpoint
160
+ dummy = 1 # after after breakpoint
161
+ debug_ # breakpoint 2
162
+ dummy = 1 # after breakpoint 2
163
+ end
164
+
165
+ def skip_test
166
+ binding.pry # stop in skip_test
167
+ skipped_method.not_skipped_method # next step
168
+ end
169
+
170
+ def skipped_method
171
+ pry_moves_skip = true # at skipped_method
172
+ self # at skipped_method
173
+ end
174
+
175
+ def not_skipped_method
176
+ :not_skipped_method # at not_skipped_method
177
+ end
178
+
94
179
  private
95
180
 
96
181
  def iterator
@@ -99,10 +184,10 @@ class Playground
99
184
  yield i
100
185
  :post_yield # post_yield
101
186
  end
102
- end
103
-
104
- def something_inside
105
- :something # some internal line
187
+ end # exit from iterator
188
+
189
+ def debug_
190
+ :something # inside of debug method
106
191
  end
107
192
 
108
193
  end
data/playground/sand.rb CHANGED
@@ -1,24 +1,57 @@
1
1
  require 'pry-moves'
2
2
  require './tracer.rb'
3
- require './playground.rb'
4
3
 
5
4
 
6
- def debug?(something)
7
- puts something
5
+ def fi(param)
6
+ a = 2 + 1
7
+ puts param
8
8
  end
9
9
 
10
- def sentence
11
- :opa
12
- end
10
+ class A
11
+
12
+ def initialize
13
+ puts :xuilo
14
+ end
15
+
16
+ def aa
17
+ puts 'aa: step 1'
18
+ puts 'aa: step 2'
19
+ end
13
20
 
21
+ def bb
22
+ debug_redirect = :aa
23
+ hide_from_stack = true
24
+ puts 'bb: step 1'
25
+ puts 'bb: step 2'
26
+ aa
27
+ end
14
28
 
15
- def aaa
16
- puts :ok
17
- "rule#{1}"
18
- binding.pry if debug? "rule#{1}"
19
- puts :ok
29
+ def cc
30
+ koko = :love
31
+ binding.pry
32
+ bb
33
+ (2..4).each do |i|
34
+ puts i
35
+ end
36
+ puts :two
37
+ end
38
+ alias cc_al cc
20
39
 
21
40
  end
22
41
 
42
+ puts :prepare
43
+
44
+ A.new.cc_al
45
+ A.new.cc_al
46
+
47
+
48
+ bb = 1
49
+
50
+ exit
51
+
52
+ pp = 123 if debucher?
53
+ binding.pry if debucher?
54
+
23
55
  binding.pry
24
- aaa
56
+
57
+ puts :ok
data/playground/test.rb CHANGED
@@ -2,4 +2,8 @@ require 'pry-moves'
2
2
  require_relative '../playground/playground.rb'
3
3
 
4
4
  i = Playground.new
5
- i.recursion
5
+ if ARGV[0]
6
+ i.send ARGV[0]
7
+ else
8
+ i.zaloop
9
+ end
@@ -0,0 +1 @@
1
+ bundle exec ruby playground/test.rb $@
data/pry-moves.gemspec CHANGED
@@ -18,8 +18,9 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  # Dependencies
21
- gem.required_ruby_version = '>= 1.8.7'
22
- gem.add_runtime_dependency 'pry', '>= 0.10.4', '< 0.12.0'
21
+ gem.required_ruby_version = '>= 1.8.7', '< 3'
22
+ gem.add_runtime_dependency 'pry', '>= 0.10.4', '< 0.13'
23
23
  gem.add_runtime_dependency 'binding_of_caller', '~> 0.7'
24
+ gem.add_runtime_dependency 'colorize', '~> 0.8'
24
25
  gem.add_development_dependency 'pry-remote', '~> 0.1.6'
25
26
  end
data/publish.sh ADDED
@@ -0,0 +1,3 @@
1
+ bundle exec rspec && \
2
+ gem build pry-moves.gemspec && \
3
+ gem push pry-moves-`ruby -e 'require "./lib/pry-moves/version.rb"; puts PryMoves::VERSION'`.gem
@@ -7,25 +7,23 @@ describe 'backtrace' do
7
7
  [nil, 'stop in level_c'],
8
8
  ['bt', lambda{|b, output|
9
9
  lines = output.split("\n").reverse
10
- expect(lines[0]).to end_with 'level_c(param=?)'
11
- expect(lines[1]).to end_with 'level_a()'
12
- expect(lines[2]).to include 'Playground:'
13
- expect(lines[3]).to end_with ':block'
14
- expect(lines[4]).to include 'RSpec::ExampleGroups'
15
- expect(lines.count).to be 5
10
+ expect(lines[0]).to end_with 'level_c(param=? nil)'
11
+ expect(lines[1]).to end_with 'frames hidden: 1'
12
+ expect(lines[2]).to end_with 'level_a()'
13
+ expect(lines[3]).to include 'Playground'
14
+ expect(lines[4]).to end_with ':block'
15
+ expect(lines[5]).to include 'RSpec::ExampleGroups'
16
+ expect(lines.count).to be 7
16
17
  }],
17
- ['bt all', lambda{|b, output|
18
+ ['bt hidden', lambda{|b, output|
18
19
  lines = output.split("\n").reverse
19
20
  # show hidden frame
20
21
  expect(lines[1]).to end_with 'level_b()'
21
- expect(lines.count).to be 6
22
+ expect(lines.count).to be 11
22
23
  }],
23
- ['bt 2', lambda{|b, output|
24
+ ['up', lambda{|b, output|
24
25
  lines = output.split("\n").reverse
25
- expect(lines[0]).to end_with 'level_c(param=?)'
26
- expect(lines[1]).to end_with 'level_a()'
27
- expect(lines[3]).to start_with 'Latest 2 lines'
28
- expect(lines.count).to be 4
26
+ expect(lines[1]).to end_with 'level_b # inside of level_a'
29
27
  }],
30
28
  ]
31
29
  Playground.new.level_a
data/spec/blocks_spec.rb CHANGED
@@ -5,7 +5,7 @@ describe 'blocks' do
5
5
  it 'should go next over blocks' do
6
6
  breakpoints [
7
7
  [nil, 'stop in zaloop'],
8
- ['n', ''],
8
+ ['n', 'iterator line'],
9
9
  # repeat commands
10
10
  ['', 'inside block'],
11
11
  ['', nil],
@@ -15,11 +15,10 @@ describe 'blocks' do
15
15
  ['', 'inside block'],
16
16
  ['pass', {output: '=> 0'}],
17
17
 
18
- ['f', 'after block'],
19
- ['pass', {output: '=> 0'}],
18
+ ['f', 'iterator line'],
19
+ ['f', 'after sub-zaloop'],
20
+ ['pass', {output: '=> :root'}],
20
21
 
21
- ['f', 'post_yield'], # Тут хорошо бы, чтобы сразу шёл на "after block",
22
- # но пока и не понятно, как это угадать
23
22
  ['f', 'after block'],
24
23
  ['pass', {output: '=> :root'}],
25
24
  ]
@@ -39,7 +38,7 @@ describe 'blocks' do
39
38
  it 'should finish block with sub-calls' do
40
39
  breakpoints [
41
40
  [nil, 'stop in zaloop'],
42
- ['n', ''],
41
+ ['n', 'iterator line'],
43
42
  ['', 'inside block'],
44
43
  ['f', 'after block'],
45
44
  ['pass', {output: '=> :root'}],
@@ -79,7 +78,7 @@ describe 'blocks' do
79
78
  ['n', 'iterator line'],
80
79
  ['n', 'inside block'],
81
80
  ['iterate', 'iterator line'],
82
- ['n', 'exit'],
81
+ ['n', 'exit']
83
82
  ]
84
83
  Playground.new.native_block early_return: true
85
84
  :exit # exit
@@ -91,10 +90,44 @@ describe 'blocks' do
91
90
  ['n', 'iterator line'],
92
91
  ['n', 'inside block'],
93
92
  ['iterate', 'iterator line'],
94
- ['n', 'exit'],
93
+ ['n', 'exit']
95
94
  ]
96
95
  Playground.new.nested_block early_return: true
97
96
  :exit # exit
98
97
  end
98
+
99
+ it 'should iterate over one-line in block' do
100
+ breakpoints [
101
+ [nil, 'stop in one_line_in_block'],
102
+ ['n', 'iterator line'],
103
+ ['n', 'inside block'],
104
+ ['i', {output: '=> 0'}],
105
+ ['n', 'inside block'],
106
+ ['i', {output: '=> 1'}],
107
+ ['n', 'after block'],
108
+ ]
109
+ Playground.new.one_line_in_block
110
+ end
111
+
112
+ it 'should skip one-line block' do
113
+ breakpoints [
114
+ [nil, 'stop in one_line_block'],
115
+ ['n', 'iterator line'],
116
+ ['n', 'after block']
117
+ ]
118
+ Playground.new.one_line_block
119
+ end
120
+
121
+ it 'should skip parentheses in loop' do
122
+ breakpoints [
123
+ [nil, 'stop in parentheses_in_loop'],
124
+ ['n', nil],
125
+ ['n', 'iterator line'],
126
+ ['n', 'inside block'],
127
+ ['n', 'iterator line'],
128
+ ['n', 'after block']
129
+ ]
130
+ Playground.new.parentheses_in_loop
131
+ end
99
132
 
100
133
  end
@@ -2,7 +2,7 @@ require_relative 'spec_helper'
2
2
 
3
3
  describe 'PryMoves commands' do
4
4
 
5
- it 'should make one step next' do
5
+ it 'should make one move next' do
6
6
  breakpoints [
7
7
  [nil, 'basic next stop'],
8
8
  ['n', 'next step'],
@@ -10,7 +10,7 @@ describe 'PryMoves commands' do
10
10
  Playground.new.basic_next
11
11
  end
12
12
 
13
- it 'should stop on second breakpoint' do
13
+ it 'should stop on second binding.pry' do
14
14
  breakpoints [
15
15
  [nil, 'first stop'],
16
16
  ['c', 'second stop'],
@@ -18,37 +18,19 @@ describe 'PryMoves commands' do
18
18
  Playground.new.continue
19
19
  end
20
20
 
21
- it 'should step into func and walk over stack' do
21
+ it 'should walk over stack' do
22
22
  breakpoints [
23
23
  [nil, 'step_into stop'],
24
24
  ['s', 'point to step inside'],
25
25
  ['s', 'some internal line'],
26
26
  ['up', 'point to step inside'],
27
- ['up', nil ],
28
- ['up', {output_includes: 'top of stack'} ],
29
- ['down', nil ],
27
+ ['up', 'spec example beginning' ],
28
+ #['up', {output_includes: 'top of stack'} ],
29
+ ['down', 'point to step inside'],
30
30
  ['down', 'some internal line'],
31
31
  ['down', {output_includes: 'bottom of stack'} ],
32
32
  ]
33
- Playground.new.step_into
34
- end
35
-
36
- it 'should step into func by name' do
37
- breakpoints [
38
- [nil, 'stop in step_by_name'],
39
- ['s level_c', 'stop in level_c'],
40
- ['param', {output: '=> :target'}],
41
- ['n', nil],
42
- ]
43
- Playground.new.step_by_name
44
- end
45
-
46
- it 'should stop after inability to step into func by name' do
47
- breakpoints [
48
- [nil, 'stop in step_by_name'],
49
- ['s absent_function', 'after_step_by_name'],
50
- ]
51
- Playground.new.step_by_name_wrap
33
+ Playground.new.step_into # spec example beginning
52
34
  end
53
35
 
54
36
  it 'should go next over recursion calls' do
@@ -61,6 +43,15 @@ describe 'PryMoves commands' do
61
43
  Playground.new.recursion
62
44
  end
63
45
 
46
+ it 'should stop after finishing early return' do
47
+ breakpoints [
48
+ [nil, 'stop in level_c'],
49
+ ['f', 'at early return'],
50
+ ['f', 'after early return']
51
+ ]
52
+ Playground.new.early_return_wrap
53
+ end
54
+
64
55
  it 'should debug' do
65
56
  breakpoints [
66
57
  [nil, 'basic next stop'],
@@ -70,4 +61,14 @@ describe 'PryMoves commands' do
70
61
  Playground.new.basic_next
71
62
  end
72
63
 
64
+ it 'should next breakpoint' do
65
+ breakpoints [
66
+ [nil, 'method_with_breakpoints host'],
67
+ ['b', 'breakpoint'],
68
+ ['n', 'after breakpoint'],
69
+ ['b', 'breakpoint 2']
70
+ ]
71
+ Playground.new.method_with_breakpoints
72
+ end
73
+
73
74
  end
data/spec/pry_debugger.rb CHANGED
@@ -24,13 +24,17 @@ module PryDebugger
24
24
 
25
25
  def compare(step, label, binding_, output)
26
26
  exp = step[:expected]
27
+ puts "\nSTEP #{step[:index]}:\n#{output}" if ENV['PRINT']
27
28
  if exp.is_a? Proc
28
29
  exp.call binding_, output
29
30
  elsif exp.is_a? Hash
30
31
  if exp[:output_includes]
31
32
  expect(output).to include exp[:output_includes]
32
33
  else
33
- expect(output).to eq exp[:output]
34
+ err = <<-TEXT
35
+ [#{step[:index]}] #{step[:cmd]} expected output '#{exp[:output]}', got '#{output}'
36
+ TEXT
37
+ expect(output).to eq(exp[:output]), err
34
38
  end
35
39
  elsif not exp.nil?
36
40
  err = <<-TEXT
@@ -31,4 +31,11 @@ describe 'redirection' do
31
31
  Playground.new.redirection_host
32
32
  end
33
33
 
34
+ it "instantly redirects binding.pry" do
35
+ breakpoints [
36
+ [nil, 'some internal line']
37
+ ]
38
+ Playground.new.instant_redirection
39
+ end
40
+
34
41
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ $VERBOSE = nil # Disable warnings for whole specs
2
+
1
3
  require 'pry'
2
4
  require_relative 'pry_debugger'
3
5
  require_relative '../playground/playground.rb'
@@ -14,7 +16,8 @@ RSpec.configure do |config|
14
16
 
15
17
  config.after(:example) do |example|
16
18
  unless example.exception
17
- expect(PryDebugger.breakpoints.count).to be(0), "not all breakpoints launched: #{PryDebugger.breakpoints.count}"
19
+ expect(PryDebugger.breakpoints.count).to be(0),
20
+ "not all breakpoints launched: #{PryDebugger.breakpoints.count}"
18
21
  end
19
22
  end
20
23
 
@@ -34,9 +37,11 @@ RSpec::Core::BacktraceFormatter.class_eval do
34
37
 
35
38
  FILTER = /(\/gems\/|\/lib\/pry\/|spec\/pry_debugger\.rb)/
36
39
  def backtrace_line(line)
37
- return if @lines == 3 and not ENV['TRACE']
38
- #return if line.match FILTER
39
- return unless line.include? '/playground.rb'
40
+ unless ENV['TRACE']
41
+ return if @lines == 3
42
+ #return if line.match FILTER
43
+ return unless line.include? '/playground.rb'
44
+ end
40
45
 
41
46
  result = native_backtrace_line(line)
42
47
  if result
data/spec/step_spec.rb ADDED
@@ -0,0 +1,51 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe 'step' do
4
+
5
+ it 'should step into func by name' do
6
+ breakpoints [
7
+ [nil, 'stop in step_by_name'],
8
+ ['s level_c', 'stop in level_c'],
9
+ ['param', {output: '=> :target'}],
10
+ ['n', nil],
11
+ ]
12
+ Playground.new.step_by_name
13
+ end
14
+
15
+ it 'should stop after inability to step into func by name' do
16
+ breakpoints [
17
+ [nil, 'stop in step_by_name'],
18
+ ['s absent_function', 'after_step_by_name'],
19
+ ]
20
+ Playground.new.step_by_name_wrap
21
+ end
22
+
23
+ it 'should skip hidden frames' do
24
+ breakpoints [
25
+ [nil, 'skip_hidden_impl stop'],
26
+ ['s', 'point to step inside'],
27
+ ['s', 'some internal line']
28
+ ]
29
+ Playground.new.skip_hidden_impl
30
+ end
31
+
32
+ it 'should step down to hidden frame and resume there' do
33
+ breakpoints [
34
+ [nil, 'at root'],
35
+ ['down', 'hidden stop'],
36
+ ['n', 'hidden_stop for next'],
37
+ ['s', 'hidden_stop for step']
38
+ ]
39
+ Playground.new.hidden_stop # at root
40
+ end
41
+
42
+ it 'should skip hidden method' do
43
+ breakpoints [
44
+ [nil, 'stop in skip_test'],
45
+ ['n', 'next step'],
46
+ ['s', 'at not_skipped_method']
47
+ ]
48
+ Playground.new.skip_test
49
+ end
50
+
51
+ end