pry-moves 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6153285cad4b74e4f713aa6a39220ffccdba822
4
- data.tar.gz: a71792935b64874e19544c929d550ee720df99ef
3
+ metadata.gz: aaa7e6d0742a28752f1a53e912f875e7e17f23c9
4
+ data.tar.gz: c1e6965e00da047cb46f923315bbf31f27a46e3e
5
5
  SHA512:
6
- metadata.gz: 25310e06f4523f1b50a610e4ab896521d8747ce5fc775d80d38b9937c9c91665300cb82e671bc38f0da5aadd22acb3539037a07e72919d686eeb37a3890ab208
7
- data.tar.gz: a00fc3b9880df6f65524cc804a677e2a209d0f0d5f9a207e1b06c0b1735bb731d68ffb3da5b706f43ae629d4bfe95352bd47de82d9b09d95a86ce16df80d0dda
6
+ metadata.gz: 1b0f21d7213ed5df54c332166a4d5fd6a200b017bdf9a757a75958bcbb4e9d6288436c1e44ececb194be14313f7d01f4fdf5150fb541cfcd3a3d0d3a2a2a1e0b
7
+ data.tar.gz: 78416e115156abcd6e5417ed1f8f0f648ae79db5173cd71b7933a35e05ec5ece09d817859cbf6ee5b465194a8304dee636fa9a6eca113937287520d522c95710
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pry-moves (0.1.6)
4
+ pry-moves (0.1.7)
5
5
  binding_of_caller (~> 0.7)
6
6
  pry (>= 0.9.10, < 0.11.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- binding_of_caller (0.7.2)
11
+ binding_of_caller (0.8.0)
12
12
  debug_inspector (>= 0.0.1)
13
13
  coderay (1.1.1)
14
14
  debug_inspector (0.0.3)
@@ -46,4 +46,4 @@ DEPENDENCIES
46
46
  rspec
47
47
 
48
48
  BUNDLED WITH
49
- 1.14.5
49
+ 1.16.6
data/README.md CHANGED
@@ -15,6 +15,7 @@ _An execution control add-on for [Pry][pry]._
15
15
  * `s method_name` - step into method `method_name` (For example from `User.new.method_name`). Partial name match supported.
16
16
  * `s +` - step into function, including hidden frames
17
17
  * `f` - **finish** execution of current frame (block or method) and stop at next line on higher level
18
+ * `iterate` - go to next iteration of current block
18
19
  * `c` - **continue**
19
20
  * `bt` - show latest 5 lines from backtrace
20
21
  * `bt 10` - latest 10 lines
@@ -6,7 +6,7 @@ module PryMoves
6
6
  breakout_navigation :step, param
7
7
  end
8
8
 
9
- block_command 'finish', 'Finish - xule tut neponyatnogo.' do |param|
9
+ block_command 'finish', 'Finish - xule tut neponyatnogo' do |param|
10
10
  breakout_navigation :finish, param
11
11
  end
12
12
 
@@ -14,15 +14,15 @@ module PryMoves
14
14
  breakout_navigation :next, param
15
15
  end
16
16
 
17
- block_command 'nn', 'Execute the next line skipping blocks.' do |param|
17
+ block_command 'nn', 'Execute the next line skipping blocks' do |param|
18
18
  breakout_navigation :next, 'blockless'
19
19
  end
20
20
 
21
- block_command 'iterate', 'Stop on next iteration of this method.' do |param|
21
+ block_command 'iterate', 'Go to next iteration of current block' do |param|
22
22
  breakout_navigation :iterate, param
23
23
  end
24
24
 
25
- block_command 'continue', 'Continue program execution and end the Pry session.' do
25
+ block_command 'continue', 'Continue program execution and end the Pry session' do
26
26
  check_file_context
27
27
  run 'exit-all'
28
28
  end
@@ -10,7 +10,7 @@ class PryWrapper
10
10
  def run(&block)
11
11
  PryMoves.lock
12
12
 
13
- Pry.config.marker = "⛔️ " if @pry_start_options[:exit_from_method]
13
+ Pry.config.marker = "⛔️" if @pry_start_options[:exit_from_method]
14
14
 
15
15
  return_value = nil
16
16
  PryMoves.is_open = true
@@ -51,10 +51,7 @@ module PryMoves::TraceCommands
51
51
  )
52
52
  end
53
53
 
54
- if event == 'return' and before_end?(line)
55
- @pry_start_options[:exit_from_method] = true
56
- true
57
- end
54
+ exit_from_method if event == 'return' and before_end?(line)
58
55
  end
59
56
  end
60
57
 
@@ -86,11 +83,18 @@ module PryMoves::TraceCommands
86
83
  end
87
84
  end
88
85
 
89
- def trace_iteration(event, file, line, binding_)
90
- raise 'not implemented'
91
- # implementation:
92
- # 1) ставить метки там, где происходит сама итерация?
93
- # 2) можно догадываться по имени методов в стеке вверху: each / each_with_index
86
+ def trace_iterate(event, file, line, binding_)
87
+ return exit_from_method if event == 'return' and
88
+ within_current_method?(file, line)
89
+
90
+ # промотка итерации -
91
+ # попасть на ту же или предыдущую строку или выйти из дайджеста
92
+ # будучи в том же методе
93
+ event == 'line' and @recursion_level == 0 and
94
+ within_current_method?(file, line) and
95
+ (line <= @iteration_start_line or
96
+ @caller_digest != frame_digest(binding_.of_caller(3))
97
+ )
94
98
  end
95
99
 
96
100
  end
@@ -38,6 +38,9 @@ class Tracer
38
38
  if @command[:param] == 'blockless'
39
39
  @stay_at_frame = frame_digest(binding_)
40
40
  end
41
+ when :iterate
42
+ @iteration_start_line = binding_.eval('__LINE__')
43
+ @caller_digest = frame_digest(binding_)
41
44
  end
42
45
 
43
46
  start_tracing
@@ -152,5 +155,10 @@ class Tracer
152
155
  @command[:pry].output.puts text
153
156
  end
154
157
 
158
+ def exit_from_method
159
+ @pry_start_options[:exit_from_method] = true
160
+ true
161
+ end
162
+
155
163
  end
156
164
  end
@@ -1,3 +1,3 @@
1
1
  module PryMoves
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- pry-moves (0.1.6)
4
+ pry-moves (0.1.7)
5
5
  binding_of_caller (~> 0.7)
6
6
  pry (>= 0.9.10, < 0.11.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- binding_of_caller (0.7.2)
11
+ binding_of_caller (0.8.0)
12
12
  debug_inspector (>= 0.0.1)
13
13
  coderay (1.1.1)
14
14
  debug_inspector (0.0.3)
@@ -26,4 +26,4 @@ DEPENDENCIES
26
26
  pry-moves!
27
27
 
28
28
  BUNDLED WITH
29
- 1.14.5
29
+ 1.16.6
@@ -54,11 +54,20 @@ class Playground
54
54
  self
55
55
  end
56
56
 
57
- def with_simple_block
58
- binding.pry # stop in with_simple_block
59
- iterator do |i|
57
+ def nested_block(early_return: false)
58
+ binding.pry # stop in nested_block
59
+ iterator do |i| # iterator line
60
+ dummy = 1 # inside block
61
+ return if early_return
62
+ end
63
+ :after_block # after block
64
+ end
65
+
66
+ def native_block(early_return: false)
67
+ binding.pry # stop in native_block
68
+ 2.times do |i| # iterator line
60
69
  dummy = 1 # inside block
61
- dummy = 2
70
+ return if early_return
62
71
  end
63
72
  :after_block # after block
64
73
  end
data/playground/sand.rb CHANGED
@@ -10,33 +10,25 @@ end
10
10
  class A
11
11
 
12
12
  def initialize
13
- hide_from_stack = true
14
13
  puts :xuilo
15
14
  end
16
15
 
17
- def kozi
18
- puts 'aa2 1'
19
- puts 'aa2 2'
20
- end
21
-
22
16
  def aa
23
- debug_redirect = :kozi
24
17
  puts 'aa: step 1'
25
18
  puts 'aa: step 2'
26
- kozi
27
19
  end
28
20
 
29
21
  def bb
30
- #debug_redirect = :aa
22
+ debug_redirect = :aa
23
+ hide_from_stack = true
31
24
  puts 'bb: step 1'
32
25
  puts 'bb: step 2'
33
26
  aa
34
27
  end
35
28
 
36
29
  def cc
37
- #debug_redirect = :bb
38
- hide_from_stack = true
39
30
  koko = :love
31
+ binding.pry
40
32
  bb
41
33
  (2..4).each do |i|
42
34
  puts i
@@ -47,12 +39,35 @@ class A
47
39
 
48
40
  end
49
41
 
50
- require './playground.rb'
51
- Playground.new.basic_next
42
+ def fff
43
+ binding.pry # stop in native_block
44
+ #2.times do |i|
45
+ iterator do |i|
46
+ dummy = 1 # inside block
47
+ return
48
+ dummy = 2
49
+ end
50
+ puts :ss
51
+ :after_block # after block
52
+ end
53
+
54
+ def iterator
55
+ 2.times do |i|
56
+ dummy = :pre_yield # pre_yield
57
+ yield i
58
+ :post_yield # post_yield
59
+ end
60
+ end
61
+
62
+ def ff
63
+ fff
64
+ puts :aaa
65
+ end
66
+
67
+ ff
52
68
 
53
69
  puts :prepare
54
70
 
55
- binding.pry
56
71
  A.new.cc_al
57
72
  A.new.cc_al
58
73
 
data/spec/blocks_spec.rb CHANGED
@@ -28,12 +28,12 @@ describe 'blocks' do
28
28
 
29
29
  it 'should finish simple block' do
30
30
  breakpoints [
31
- [nil, 'stop in with_simple_block'],
32
- ['n', ''],
31
+ [nil, 'stop in nested_block'],
32
+ ['n', 'iterator line'],
33
33
  ['', 'inside block'],
34
34
  ['f', 'after block']
35
35
  ]
36
- Playground.new.with_simple_block
36
+ Playground.new.nested_block
37
37
  end
38
38
 
39
39
  it 'should finish block with sub-calls' do
@@ -47,5 +47,54 @@ describe 'blocks' do
47
47
  Playground.new.zaloop
48
48
  end
49
49
 
50
+ it 'should iterate over native block' do
51
+ breakpoints [
52
+ [nil, 'stop in native_block'],
53
+ ['n', 'iterator line'],
54
+ ['n', 'inside block'],
55
+ ['i', {output: '=> 0'}],
56
+ ['iterate', 'inside block'],
57
+ ['i', {output: '=> 1'}],
58
+ ['iterate', 'after block'],
59
+ ]
60
+ Playground.new.native_block
61
+ end
62
+
63
+ it 'should iterate over nested block' do
64
+ breakpoints [
65
+ [nil, 'stop in nested_block'],
66
+ ['n', 'iterator line'],
67
+ ['n', 'inside block'],
68
+ ['i', {output: '=> 0'}],
69
+ ['iterate', 'inside block'],
70
+ ['i', {output: '=> 1'}],
71
+ ['iterate', 'after block'],
72
+ ]
73
+ Playground.new.nested_block
74
+ end
50
75
 
76
+ it 'should return during iterating native block' do
77
+ breakpoints [
78
+ [nil, 'stop in native_block'],
79
+ ['n', 'iterator line'],
80
+ ['n', 'inside block'],
81
+ ['iterate', 'iterator line'],
82
+ ['n', 'exit'],
83
+ ]
84
+ Playground.new.native_block early_return: true
85
+ :exit # exit
86
+ end
87
+
88
+ it 'should return during iterating nested block' do
89
+ breakpoints [
90
+ [nil, 'stop in nested_block'],
91
+ ['n', 'iterator line'],
92
+ ['n', 'inside block'],
93
+ ['iterate', 'iterator line'],
94
+ ['n', 'exit'],
95
+ ]
96
+ Playground.new.nested_block early_return: true
97
+ :exit # exit
98
+ end
99
+
51
100
  end
data/spec/pry_debugger.rb CHANGED
@@ -2,31 +2,41 @@ module PryDebugger
2
2
 
3
3
  module Breakpoints
4
4
  def breakpoints(breakpoints)
5
+ steps = []
5
6
  breakpoints.each_with_index do |b, index|
6
7
  next_b = breakpoints[index+1]
7
- b[0] = next_b ? next_b[0] : nil
8
+ steps << {
9
+ cmd: b[0],
10
+ expected: b[1],
11
+ next_cmd: next_b ? next_b[0] : nil,
12
+ index: index
13
+ }
8
14
  end
9
15
 
10
16
  PryDebugger.breakpoints =
11
- breakpoints.map do |b|
17
+ steps.map do |step|
12
18
  Proc.new do |label, binding_, output|
13
- compare(b[1], label, binding_, output)
14
- b[0]
19
+ compare(step, label, binding_, output)
20
+ step[:next_cmd]
15
21
  end
16
22
  end
17
23
  end
18
24
 
19
- def compare(subj, label, binding_, output)
20
- if subj.is_a? Proc
21
- subj.call binding_, output
22
- elsif subj.is_a? Hash
23
- if subj[:output_includes]
24
- expect(output).to include subj[:output_includes]
25
+ def compare(step, label, binding_, output)
26
+ exp = step[:expected]
27
+ if exp.is_a? Proc
28
+ exp.call binding_, output
29
+ elsif exp.is_a? Hash
30
+ if exp[:output_includes]
31
+ expect(output).to include exp[:output_includes]
25
32
  else
26
- expect(output).to eq subj[:output]
33
+ expect(output).to eq exp[:output]
27
34
  end
28
- elsif not subj.nil?
29
- expect(label).to eq subj
35
+ elsif not exp.nil?
36
+ err = <<-TEXT
37
+ [#{step[:index]}] #{step[:cmd]} => '#{exp}', got '#{label}'
38
+ TEXT
39
+ expect(label).to eq(exp), err
30
40
  end
31
41
  end
32
42
  end
@@ -81,8 +91,8 @@ module PryDebugger
81
91
  raise 'Next breakpoint handler missing' if @breakpoints_procs.size == 0
82
92
  #puts (@breakpoint_call += 1)
83
93
  output = @output.take_away
84
- output.match(/^ => .*#(.*)/)
85
- label = ($1 || '').strip
94
+ output.match(/^ (=>|⛔️) .*#(.*)/)
95
+ label = ($2 || '').strip
86
96
  @breakpoints_procs.shift.call label, binding_, output.strip
87
97
  end
88
98
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-moves
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - garmoshka-mo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-09 00:00:00.000000000 Z
11
+ date: 2018-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  requirements: []
128
128
  rubyforge_project:
129
- rubygems_version: 2.6.8
129
+ rubygems_version: 2.5.2.3
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: Debugger for ruby