byebug 3.4.0 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a070d89045517045b3dc43aa5cd111e27ba6dad
4
- data.tar.gz: 4d1c945dc27077f736c8baae4b73ddfb5321b323
3
+ metadata.gz: 7001ae9053bb3dff2ca95eee6b105c0b1e75b06b
4
+ data.tar.gz: f1d8c6f4b00f51f1460f6833bdc28dcf84f28a4d
5
5
  SHA512:
6
- metadata.gz: a7654e3d51f44a52567296713c0c98cbb712f5ecc4af7242f8174c97b73de07c7fca86227ef58082601e7f879bb91e1a0eb5bb7dbb50e12581885b892fc96e83
7
- data.tar.gz: 8f86297d98eaa6a23e5683d3136fdb6d08a4cb8ececb64bec47a3897d1d3b3a6278843c1ef6f6772be8c098a36f3b8c0c13aee3fad2e31c9cf2f41a998a8e10f
6
+ metadata.gz: 8360f244410378f4b11caae0eabcd6dcc18cacd66562fd7a460d99c5861c03ff5a92a08f027bb9dc5fc25ae3527518e8ac45ed3e5643389fd0cfd9eac2354f75
7
+ data.tar.gz: f9bba361d8ace23476c667df962e610fe1a054de7224c8ae8cf392fa8ee930656d5d6ac7f3f6ddfceb863cdb3f9926c808f785476c3833123a021bbb7d24889d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 3.4.1
2
+ * Fix #54, you can use threads when "evaling" stuff now.
3
+ * Fix bug in list command where user could not list backwards if current
4
+ listing was reaching the end of the file.
5
+
6
+
1
7
  # 3.4.0
2
8
  * Better fix for deivid-rodriguez/pry-byebug#32
3
9
 
data/CONTRIBUTING.md CHANGED
@@ -4,6 +4,7 @@ To make your changes, follow this steps:
4
4
 
5
5
  * [Fork the project](https://help.github.com/fork-a-repo)
6
6
  * Create a topic branch - `git checkout -b my_branch`
7
+ * Make sure the latest patch level of Ruby 2.0.0 or higher is installed.
7
8
  * Insert awesome code - See below
8
9
  * Push your branch to your forked repo - `git push origin my_branch`
9
10
  * [Make a pull request](https://help.github.com/articles/using-pull-requests)
data/GUIDE.md CHANGED
@@ -537,7 +537,7 @@ this way finishes, byebug is turned off and the application proceeds at regular
537
537
  speed.
538
538
 
539
539
  Of course, inside the block you will probably want to enter the byebug using
540
- `Byebug.byebug()`, otherwise there would be little point in using the `start`.
540
+ `Byebug.byebug`, otherwise there would be little point in using the `start`.
541
541
  For example, you can do this in `irb`:
542
542
 
543
543
  ```bash
data/README.md CHANGED
@@ -12,18 +12,32 @@ Byebug is a simple to use, feature rich debugger for Ruby 2. It uses the new
12
12
  TracePoint API for execution control and the new Debug Inspector API for call
13
13
  stack navigation, so it doesn't depend on internal core sources. It's developed
14
14
  as a C extension, so it's fast. And it has a full test suite so it's reliable.
15
- Note that byebug works only for ruby 2.0.0 or newer. For debugging ruby 1.9.3 or
16
- older, use [debugger](https://github.com/cldwalker/debugger).
17
15
 
18
16
  It allows you to see what is going on _inside_ a Ruby program while it executes
19
- and can do four main kinds of things to help you catch bugs in the act:
17
+ and offers many of the traditional debugging features such as:
20
18
 
21
- * Start your program or attach to it, specifying anything that might affect its
22
- behavior.
23
- * Make your program stop on specified conditions.
24
- * Examine what has happened when your program has stopped.
25
- * Change things in your program, so you can experiment with correcting the
26
- effects of one bug and go on to learn about another.
19
+ * Stepping: Running your program one line at a time.
20
+ * Breaking: Pausing the program at some event or specified instruction, to
21
+ examine the current state.
22
+ * Evaluating: Basic REPL functionality, although [pry][] does a better job at
23
+ that.
24
+ * Tracking: Keeping track of the different values of your variables or the
25
+ different lines executed by your program.
26
+
27
+
28
+ ## Ruby Version Support
29
+
30
+ Byebug works only for Ruby 2.0.0 or newer. For debugging ruby 1.9.3 or older,
31
+ use [debugger][].
32
+
33
+ Furthermore, Byebug uses the TracePoint API which was just first developed for
34
+ Ruby 2.0.0. Since it was released, a lot of bugs directly impacting Byebug have
35
+ been corrected, so for the best debugging experience, the following Ruby
36
+ versions are recommended:
37
+
38
+ * Ruby 2.0.0-p576 or higher.
39
+ * Ruby 2.1.3 or higher.
40
+ * Ruby 2.2.0-preview1 or higher.
27
41
 
28
42
 
29
43
  ## Install
@@ -41,8 +55,7 @@ wherever you want to start debugging and the execution will stop there. If you
41
55
  are debugging rails, start the server and once the execution gets to your
42
56
  `byebug` command you will get a debugging prompt.
43
57
 
44
- Former [debugger](https://github.com/cldwalker/debugger) or
45
- [ruby-debug](https://github.com/mark-moseley/ruby-debug) users, notice:
58
+ Former [debugger][] or [ruby-debug][] users, notice:
46
59
 
47
60
  * Some gems (rails, rspec) implement debugging flags (-d, --debugger) that early
48
61
  require and start the debugger. These flags are a performance penalty and byebug
@@ -102,9 +115,8 @@ both rails and rspec have deprecated these flags in their latest versions.
102
115
 
103
116
  Byebug tries to follow [semantic versioning](http://semver.org) and tries to
104
117
  bump major version only when backwards incompatible changes are released.
105
- Backwards compatibility is targeted to
106
- [pry-byebug](https://github.com/deivid-rodriguez/pry-byebug) and any other
107
- plugins relying on `byebug`.
118
+ Backwards compatibility is targeted to [pry-byebug][] and any other plugins
119
+ relying on `byebug`.
108
120
 
109
121
 
110
122
  ## Getting Started
@@ -116,14 +128,12 @@ started. Proper documentation will be eventually written.
116
128
 
117
129
  ## Related projects
118
130
 
119
- * [pry-byebug](https://github.com/deivid-rodriguez/pry-byebug) adds `next`,
120
- `step`, `finish`, `continue` and `break` commands to pry using byebug.
121
- * [ruby-debug-passenger](https://github.com/davejamesmiller/ruby-debug-passenger)
122
- adds a rake task that restarts Passenger with byebug connected.
123
- * [minitest-byebug](https://github.com/kaspth/minitest-byebug) starts a byebug
124
- session on minitest failures.
125
- * [sublime-debugger](https://github.com/shuky19/sublime_debugger) provides a plugin
126
- for ruby debugging on Sublime Text.
131
+ * [pry-byebug][] adds `next`, `step`, `finish`, `continue` and `break` commands
132
+ to `pry` using `byebug`.
133
+ * [ruby-debug-passenger][] adds a rake task that restarts Passenger with Byebug
134
+ connected.
135
+ * [minitest-byebug][] starts a byebug session on minitest failures.
136
+ * [sublime_debugger][] provides a plugin for ruby debugging on Sublime Text.
127
137
 
128
138
 
129
139
  ## TODO List (by priority)
@@ -132,15 +142,16 @@ for ruby debugging on Sublime Text.
132
142
  * Add printers support.
133
143
  * Support rubies other than MRI.
134
144
 
145
+ [Getting Started with Development](CONTRIBUTING.md)
146
+
135
147
  ## Credits
136
148
 
137
149
  Everybody who has ever contributed to this forked and reforked piece of
138
150
  software, specially:
139
151
 
140
152
  * @ko1, author of the awesome TracePoint API for Ruby.
141
- * @cldwalker, [debugger](https://github.com/cldwalker/debugger)'s mantainer.
142
- * @denofevil, author of [debase](https://github.com/denofevil/debase), the
143
- starting point of this.
153
+ * @cldwalker, [debugger][]'s mantainer.
154
+ * @denofevil, author of [debase][], the starting point of this.
144
155
  * @kevjames3 for testing, bug reports and the interest in the project.
145
156
  * @FooBarWidget for working and helping with remote debugging.
146
157
 
@@ -156,3 +167,12 @@ starting point of this.
156
167
  [CoverageURL]: https://codeclimate.com/github/deivid-rodriguez/byebug
157
168
  [GittipBadge]: http://img.shields.io/gittip/deivid-rodriguez.svg
158
169
  [GittipURL]: https://www.gittip.com/deivid-rodriguez
170
+
171
+ [debugger]: https://github.com/cldwalker/debugger
172
+ [pry]: https://github.com/pry/pry
173
+ [ruby-debug]: https://github.com/mark-moseley/ruby-debug
174
+ [debase]: https://github.com/denofevil/debase
175
+ [pry-byebug]: https://github.com/deivid-rodriguez/pry-byebug
176
+ [ruby-debug-passenger]: https://github.com/davejamesmiller/ruby-debug-passenger
177
+ [minitest-byebug]: https://github.com/kaspth/minitest-byebug
178
+ [sublime_debugger]: https://github.com/shuky19/sublime_debugger
data/ext/byebug/byebug.c CHANGED
@@ -316,6 +316,16 @@ c_return_event(VALUE trace_point, void *data)
316
316
  cleanup(dc);
317
317
  }
318
318
 
319
+ static void
320
+ thread_event(VALUE trace_point, void *data)
321
+ {
322
+ EVENT_SETUP
323
+
324
+ EVENT_COMMON
325
+
326
+ cleanup(dc);
327
+ }
328
+
319
329
  static void
320
330
  raise_event(VALUE trace_point, void *data)
321
331
  {
@@ -387,19 +397,21 @@ register_tracepoints(VALUE self)
387
397
 
388
398
  if (NIL_P(traces))
389
399
  {
390
- int line_msk = RUBY_EVENT_LINE;
391
- int call_msk = RUBY_EVENT_CALL | RUBY_EVENT_B_CALL | RUBY_EVENT_CLASS;
392
- int return_msk = RUBY_EVENT_RETURN | RUBY_EVENT_B_RETURN | RUBY_EVENT_END;
393
- int c_call_msk = RUBY_EVENT_C_CALL;
394
- int c_return_msk = RUBY_EVENT_C_RETURN;
395
- int raise_msk = RUBY_EVENT_RAISE;
396
-
397
- VALUE tpLine = rb_tracepoint_new(Qnil, line_msk , line_event , 0);
398
- VALUE tpCall = rb_tracepoint_new(Qnil, call_msk , call_event , 0);
399
- VALUE tpReturn = rb_tracepoint_new(Qnil, return_msk , return_event , 0);
400
- VALUE tpCCall = rb_tracepoint_new(Qnil, c_call_msk , c_call_event , 0);
401
- VALUE tpCReturn = rb_tracepoint_new(Qnil, c_return_msk, c_return_event, 0);
402
- VALUE tpRaise = rb_tracepoint_new(Qnil, raise_msk , raise_event , 0);
400
+ int line_msk = RUBY_EVENT_LINE;
401
+ int call_msk = RUBY_EVENT_CALL | RUBY_EVENT_B_CALL | RUBY_EVENT_CLASS;
402
+ int return_msk = RUBY_EVENT_RETURN | RUBY_EVENT_B_RETURN | RUBY_EVENT_END;
403
+ int c_call_msk = RUBY_EVENT_C_CALL;
404
+ int c_ret_msk = RUBY_EVENT_C_RETURN;
405
+ int raise_msk = RUBY_EVENT_RAISE;
406
+ int thread_msk = RUBY_EVENT_THREAD_BEGIN | RUBY_EVENT_THREAD_END;
407
+
408
+ VALUE tpLine = rb_tracepoint_new(Qnil, line_msk , line_event , 0);
409
+ VALUE tpCall = rb_tracepoint_new(Qnil, call_msk , call_event , 0);
410
+ VALUE tpReturn = rb_tracepoint_new(Qnil, return_msk, return_event , 0);
411
+ VALUE tpCCall = rb_tracepoint_new(Qnil, c_call_msk, c_call_event , 0);
412
+ VALUE tpCReturn = rb_tracepoint_new(Qnil, c_ret_msk , c_return_event, 0);
413
+ VALUE tpRaise = rb_tracepoint_new(Qnil, raise_msk , raise_event , 0);
414
+ VALUE tpThread = rb_tracepoint_new(Qnil, thread_msk, thread_event , 0);
403
415
 
404
416
  traces = rb_ary_new();
405
417
  rb_ary_push(traces, tpLine);
@@ -408,6 +420,7 @@ register_tracepoints(VALUE self)
408
420
  rb_ary_push(traces, tpCCall);
409
421
  rb_ary_push(traces, tpCReturn);
410
422
  rb_ary_push(traces, tpRaise);
423
+ rb_ary_push(traces, tpThread);
411
424
 
412
425
  tracepoints = traces;
413
426
  }
@@ -768,23 +781,23 @@ Init_byebug()
768
781
  {
769
782
  mByebug = rb_define_module("Byebug");
770
783
 
771
- rb_define_module_function(mByebug, "add_catchpoint" , bb_add_catchpoint , 1);
772
- rb_define_module_function(mByebug, "breakpoints" , bb_breakpoints , 0);
773
- rb_define_module_function(mByebug, "catchpoints" , bb_catchpoints , 0);
774
- rb_define_module_function(mByebug, "contexts" , bb_contexts , 0);
775
- rb_define_module_function(mByebug, "current_context" , bb_current_context , 0);
776
- rb_define_module_function(mByebug, "debug_load" , bb_load , -1);
777
- rb_define_module_function(mByebug, "post_mortem?" , bb_post_mortem , 0);
778
- rb_define_module_function(mByebug, "post_mortem=" , bb_set_post_mortem , 1);
779
- rb_define_module_function(mByebug, "raised_exception" , bb_raised_exception, 0);
780
- rb_define_module_function(mByebug, "start" , bb_start , 0);
781
- rb_define_module_function(mByebug, "started?" , bb_started , 0);
782
- rb_define_module_function(mByebug, "stop" , bb_stop , 0);
783
- rb_define_module_function(mByebug, "thread_context" , bb_thread_context , 1);
784
- rb_define_module_function(mByebug, "tracing?" , bb_tracing , 0);
785
- rb_define_module_function(mByebug, "tracing=" , bb_set_tracing , 1);
786
- rb_define_module_function(mByebug, "verbose?" , bb_verbose , 0);
787
- rb_define_module_function(mByebug, "verbose=" , bb_set_verbose , 1);
784
+ rb_define_module_function(mByebug, "add_catchpoint" , bb_add_catchpoint , 1);
785
+ rb_define_module_function(mByebug, "breakpoints" , bb_breakpoints , 0);
786
+ rb_define_module_function(mByebug, "catchpoints" , bb_catchpoints , 0);
787
+ rb_define_module_function(mByebug, "contexts" , bb_contexts , 0);
788
+ rb_define_module_function(mByebug, "current_context" , bb_current_context , 0);
789
+ rb_define_module_function(mByebug, "debug_load" , bb_load , -1);
790
+ rb_define_module_function(mByebug, "post_mortem?" , bb_post_mortem , 0);
791
+ rb_define_module_function(mByebug, "post_mortem=" , bb_set_post_mortem , 1);
792
+ rb_define_module_function(mByebug, "raised_exception", bb_raised_exception, 0);
793
+ rb_define_module_function(mByebug, "start" , bb_start , 0);
794
+ rb_define_module_function(mByebug, "started?" , bb_started , 0);
795
+ rb_define_module_function(mByebug, "stop" , bb_stop , 0);
796
+ rb_define_module_function(mByebug, "thread_context" , bb_thread_context , 1);
797
+ rb_define_module_function(mByebug, "tracing?" , bb_tracing , 0);
798
+ rb_define_module_function(mByebug, "tracing=" , bb_set_tracing , 1);
799
+ rb_define_module_function(mByebug, "verbose?" , bb_verbose , 0);
800
+ rb_define_module_function(mByebug, "verbose=" , bb_set_verbose , 1);
788
801
 
789
802
  Init_threads_table(mByebug);
790
803
  Init_context(mByebug);
data/ext/byebug/context.c CHANGED
@@ -431,7 +431,7 @@ Context_step_out(int argc, VALUE *argv, VALUE self)
431
431
 
432
432
  Data_Get_Struct(self, debug_context_t, context);
433
433
 
434
- if (n_frames < 0 || n_frames >= context->calced_stack_size)
434
+ if (n_frames < 0 || n_frames > context->calced_stack_size)
435
435
  rb_raise(rb_eRuntimeError,
436
436
  "You wan't to finish %d frames, but stack size is only %d",
437
437
  n_frames, context->calced_stack_size);
@@ -1,6 +1,13 @@
1
1
  module Byebug
2
- # Stores program being debugged to make restarts possible
3
- PROG_SCRIPT = $PROGRAM_NAME unless defined?(PROG_SCRIPT)
2
+ #
3
+ # Enters byebug right before (or right after if _before_ is false) return
4
+ # events occur. Before entering byebug the init script is read.
5
+ #
6
+ def self.attach(steps_out, before)
7
+ start
8
+ run_init_script(StringIO.new)
9
+ current_context.step_out(steps_out, before)
10
+ end
4
11
  end
5
12
 
6
13
  #
@@ -9,14 +16,8 @@ end
9
16
  # Dropping a `byebug` call anywhere in your code, you get a debug prompt.
10
17
  #
11
18
  module Kernel
12
- #
13
- # Enters byebug right before (or right after if _before_ is false) return
14
- # events occur. Before entering byebug the init script is read.
15
- #
16
19
  def byebug(steps_out = 1, before = true)
17
- Byebug.start
18
- Byebug.run_init_script(StringIO.new)
19
- Byebug.current_context.step_out(steps_out, before)
20
+ Byebug.attach(steps_out + 1, before)
20
21
  end
21
22
 
22
23
  alias_method :debugger, :byebug
@@ -19,8 +19,9 @@ module Byebug
19
19
  b, e = set_line_range(Setting[:listsize], lines.size)
20
20
  return @state.previous_line if b < 0
21
21
 
22
- puts "\n[#{b}, #{e}] in #{@state.file}"
23
- @state.previous_line = display_list(b, e, lines, @state.line)
22
+ display_lines(b, e, lines)
23
+
24
+ @state.previous_line = b > lines.size ? @previous_line : b
24
25
  end
25
26
 
26
27
  class << self
@@ -94,20 +95,16 @@ module Byebug
94
95
  [b, e]
95
96
  end
96
97
 
97
- ##
98
- # Show file lines in LINES from line B to line E where CURRENT is the
99
- # current line number. If we can show from B to E then we return B,
100
- # otherwise we return the previous line @state.previous_line.
101
98
  #
102
- def display_list(b, e, lines, current)
103
- width = e.to_s.size
104
- b.upto(e) do |n|
105
- next unless n > 0 && lines[n - 1]
106
- line = n == current ? '=>' : ' '
107
- line += format(" %#{width}d: %s", n, lines[n - 1].chomp)
108
- puts(line)
99
+ # Show file lines in <lines> from line number <min> to line number <max>.
100
+ #
101
+ def display_lines(min, max, lines)
102
+ puts "\n[#{min}, #{max}] in #{@state.file}"
103
+
104
+ (min..max).to_a.zip(lines[min-1..max-1]).map do |l|
105
+ mark = l[0] == @state.line ? '=> ' : ' '
106
+ puts format("#{mark}%#{max.to_s.size}d: %s", l[0], l[1])
109
107
  end
110
- e == lines.size ? @state.previous_line : b
111
108
  end
112
109
  end
113
110
  end
@@ -10,17 +10,14 @@ module Byebug
10
10
  end
11
11
 
12
12
  def execute
13
- prog = PROG_SCRIPT if defined?(PROG_SCRIPT)
14
- byebug_script = BYEBUG_SCRIPT if defined?(BYEBUG_SCRIPT)
15
-
16
- return errmsg("Don't know name of debugged program") unless prog
13
+ prog = Byebug.debugged_program
17
14
 
18
15
  unless File.exist?(File.expand_path(prog))
19
16
  return errmsg("Ruby program #{prog} doesn't exist")
20
17
  end
21
18
 
22
- if byebug_script
23
- cmd = "#{byebug_script} #{prog}"
19
+ if defined?(BYEBUG_SCRIPT)
20
+ cmd = "#{BYEBUG_SCRIPT} #{prog}"
24
21
  else
25
22
  puts 'Byebug was not called from the outset...'
26
23
  if File.executable?(prog)
@@ -28,7 +28,7 @@ module Byebug
28
28
 
29
29
  def var_global
30
30
  globals = global_variables.reject do |v|
31
- [:$IGNORECASE, :$=, :$KCODE, :$-K].include?(v)
31
+ [:$IGNORECASE, :$=, :$KCODE, :$-K, :$binding].include?(v)
32
32
  end
33
33
 
34
34
  var_list(globals)
data/lib/byebug/core.rb CHANGED
@@ -20,10 +20,18 @@ module Byebug
20
20
 
21
21
  class << self
22
22
  attr_accessor :handler
23
+ attr_writer :debugged_program
23
24
  end
24
25
 
25
26
  Byebug.handler = CommandProcessor.new
26
27
 
28
+ #
29
+ # Program being debugged (or a default one if not set yet)
30
+ #
31
+ def self.debugged_program
32
+ @debugged_program ||= $PROGRAM_NAME
33
+ end
34
+
27
35
  def self.source_reload
28
36
  hsh = 'SCRIPT_LINES__'
29
37
  Object.send(:remove_const, hsh) if Object.const_defined?(hsh)
data/lib/byebug/runner.rb CHANGED
@@ -16,13 +16,15 @@ module Byebug
16
16
  # Debug a script only if syntax checks okay.
17
17
  #
18
18
  def debug_program(options)
19
- output = `ruby -c "#{Byebug::PROG_SCRIPT}" 2>&1`
20
- if $CHILD_STATUS.exitstatus != 0
21
- Byebug.puts output
22
- exit $CHILD_STATUS.exitstatus
19
+ unless File.executable?(Byebug.debugged_program)
20
+ output = `ruby -c "#{Byebug.debugged_program}" 2>&1`
21
+ if $CHILD_STATUS.exitstatus != 0
22
+ Byebug.puts output
23
+ exit $CHILD_STATUS.exitstatus
24
+ end
23
25
  end
24
26
 
25
- status = Byebug.debug_load(Byebug::PROG_SCRIPT, options[:stop])
27
+ status = Byebug.debug_load(Byebug.debugged_program, options[:stop])
26
28
  Byebug.puts "#{status}\n#{status.backtrace}" if status
27
29
  end
28
30
 
@@ -45,6 +47,23 @@ module Byebug
45
47
  prog_script
46
48
  end
47
49
 
50
+ #
51
+ # Save path to program to be debugged
52
+ #
53
+ # Used for restarts.
54
+ #
55
+ def save_debugged_program
56
+ if ARGV.empty?
57
+ Byebug.puts 'You must specify a program to debug...'
58
+ abort
59
+ end
60
+
61
+ prog_script = ARGV.first
62
+ prog_script = whence_file(prog_script) unless File.exist?(prog_script)
63
+
64
+ Byebug.debugged_program = File.expand_path(prog_script)
65
+ end
66
+
48
67
  #
49
68
  # Starts byebug to debug a program
50
69
  #
@@ -61,19 +80,7 @@ module Byebug
61
80
  return
62
81
  end
63
82
 
64
- if ARGV.empty?
65
- Byebug.puts 'You must specify a program to debug...'
66
- abort
67
- end
68
-
69
- # Save debugged program
70
- prog_script = ARGV.pop
71
- prog_script = whence_file(prog_script) unless File.exist?(prog_script)
72
-
73
- if Byebug.const_defined?('PROG_SCRIPT')
74
- Byebug.send(:remove_const, 'PROG_SCRIPT')
75
- end
76
- Byebug.const_set('PROG_SCRIPT', File.expand_path(prog_script))
83
+ save_debugged_program
77
84
 
78
85
  # Set up trace hook for byebug
79
86
  Byebug.start
@@ -1,3 +1,3 @@
1
1
  module Byebug
2
- VERSION = '3.4.0'
2
+ VERSION = '3.4.1'
3
3
  end
@@ -29,7 +29,6 @@ module Byebug
29
29
  end
30
30
 
31
31
  def test_eval_properly_evaluates_an_expression_using_timeout
32
- skip 'for now'
33
32
  enter 'eval Timeout::timeout(60) { 1 }'
34
33
  debug_proc(@example)
35
34
  check_output_includes '1'
@@ -29,17 +29,6 @@ module Byebug
29
29
  super
30
30
  end
31
31
 
32
- def lines_between(min, max, mark_current = true)
33
- lines = [*File.open(__FILE__)][min-1..max-1]
34
- numbers = (min..max).to_a
35
- output = numbers.zip(lines).map { |l| format("%2d: %s", l[0], l[1]) }
36
- if mark_current
37
- middle = (output.size/2.0).ceil
38
- output[middle] = "=> #{output[middle]}"
39
- end
40
- output
41
- end
42
-
43
32
  def test_lists_source_code_lines
44
33
  Setting[:listsize] = 10
45
34
  enter 'list'
@@ -61,7 +50,10 @@ module Byebug
61
50
  end
62
51
 
63
52
  def test_moves_range_down_when_it_goes_after_the_end_of_file
64
- skip "Can't test this with the current setup"
53
+ n_lines = %x{wc -l #{__FILE__}}.split.first.to_i
54
+ enter 'break 18', 'cont', "list #{n_lines-3}-#{n_lines+6}"
55
+ debug_proc(@example)
56
+ check_output_includes "[#{n_lines-9}, #{n_lines}] in #{__FILE__}"
65
57
  end
66
58
 
67
59
  def test_lists_the_whole_file_if_number_of_lines_is_smaller_than_listsize
@@ -75,47 +67,50 @@ module Byebug
75
67
  def test_lists_surrounding_lines_after_the_first_call_to_list
76
68
  enter 'break 8', 'cont', 'list'
77
69
  debug_proc(@example)
78
- check_output_includes("[3, 12] in #{__FILE__}", *lines_between(3, 12))
70
+ check_output_includes "[3, 12] in #{__FILE__}"
79
71
  end
80
72
 
81
73
  def test_lists_forwards_after_the_second_call_to_list
82
74
  enter 'break 8', 'cont', 'list', 'list'
83
75
  debug_proc(@example)
84
- check_output_includes("[13, 22] in #{__FILE__}",
85
- *lines_between(13, 22, false))
76
+ check_output_includes "[13, 22] in #{__FILE__}"
86
77
  end
87
78
 
88
79
  def test_lists_surrounding_lines_after_the_first_call_to_list_minus
89
80
  enter 'break 18', 'cont', 'list -'
90
81
  debug_proc(@example)
91
- check_output_includes("[13, 22] in #{__FILE__}", *lines_between(13, 22))
82
+ check_output_includes "[13, 22] in #{__FILE__}"
92
83
  end
93
84
 
94
85
  def test_lists_backwards_after_the_second_call_to_list_minus
95
86
  enter 'break 18', 'cont', 'list -', 'list -'
96
87
  debug_proc(@example)
97
- check_output_includes("[3, 12] in #{__FILE__}",
98
- *lines_between(3, 12, false))
88
+ check_output_includes "[3, 12] in #{__FILE__}"
89
+ end
90
+
91
+ def test_lists_backwards_from_end_of_file
92
+ n_lines = %x{wc -l #{__FILE__}}.split.first.to_i
93
+ enter 'break 18', 'cont', "list #{n_lines-9}-#{n_lines}", 'list -'
94
+ debug_proc(@example)
95
+ check_output_includes "[#{n_lines-19}, #{n_lines-10}] in #{__FILE__}"
99
96
  end
100
97
 
101
98
  def test_lists_surrounding_lines_when_list_equals_is_called
102
99
  enter 'break 8', 'cont', 'list ='
103
100
  debug_proc(@example)
104
- check_output_includes("[3, 12] in #{__FILE__}", *lines_between(3, 12))
101
+ check_output_includes "[3, 12] in #{__FILE__}"
105
102
  end
106
103
 
107
104
  def test_lists_specific_range_when_requested_in_hyphen_format
108
105
  enter 'list 7-9'
109
106
  debug_proc(@example)
110
- check_output_includes("[7, 9] in #{__FILE__}",
111
- *lines_between(7, 9, false))
107
+ check_output_includes "[7, 9] in #{__FILE__}"
112
108
  end
113
109
 
114
110
  def test_lists_specific_range_when_requested_in_comma_format
115
111
  enter 'list 7,9'
116
112
  debug_proc(@example)
117
- check_output_includes("[7, 9] in #{__FILE__}",
118
- *lines_between(7, 9, false))
113
+ check_output_includes "[7, 9] in #{__FILE__}"
119
114
  end
120
115
 
121
116
  def test_lists_nothing_if_unexistent_range_is_specified
@@ -135,15 +130,13 @@ module Byebug
135
130
  def test_list_proper_lines_when_range_around_specific_line_with_hyphen
136
131
  enter 'list 17-'
137
132
  debug_proc(@example)
138
- check_output_includes("[12, 21] in #{__FILE__}",
139
- *lines_between(12, 21, false))
133
+ check_output_includes "[12, 21] in #{__FILE__}"
140
134
  end
141
135
 
142
136
  def test_list_proper_lines_when_range_around_specific_line_with_comma
143
137
  enter 'list 17,'
144
138
  debug_proc(@example)
145
- check_output_includes("[12, 21] in #{__FILE__}",
146
- *lines_between(12, 21, false))
139
+ check_output_includes "[12, 21] in #{__FILE__}"
147
140
  end
148
141
 
149
142
  def test_shows_an_error_when_the_file_to_list_does_not_exist
@@ -15,15 +15,9 @@ module Byebug
15
15
  RestartExample.new.concat_args(a, b, c)
16
16
  end
17
17
 
18
- @old_prog_script = Byebug::PROG_SCRIPT if defined?(Byebug::PROG_SCRIPT)
19
-
20
18
  super
21
19
  end
22
20
 
23
- def after
24
- force_set_const(Byebug, 'PROG_SCRIPT', @old_prog_script)
25
- end
26
-
27
21
  def must_restart(cmd = nil)
28
22
  expectation = RestartCommand.any_instance.expects(:exec)
29
23
  expectation = expectation.with(cmd) if cmd
@@ -32,23 +26,26 @@ module Byebug
32
26
 
33
27
  def test_restarts_with_manual_arguments
34
28
  force_set_const(Byebug, 'BYEBUG_SCRIPT', 'byebug_script')
35
- cmd = "#{BYEBUG_SCRIPT} #{PROG_SCRIPT} 1 2 3"
29
+ cmd = "#{BYEBUG_SCRIPT} #{Byebug.debugged_program} 1 2 3"
36
30
  must_restart(cmd)
31
+
37
32
  enter 'restart 1 2 3'
38
33
  debug_proc(@example)
39
34
  check_output_includes "Re exec'ing:\n\t#{cmd}"
40
35
  end
41
36
 
42
- def test_does_not_restart_when_no_script_specified
43
- force_unset_const(Byebug, 'PROG_SCRIPT')
44
- must_restart.never
37
+ def test_restart_with_a_default_script_if_nil_script_specified
38
+ force_set_const(Byebug, 'BYEBUG_SCRIPT', 'byebug_script')
39
+ Byebug.debugged_program = nil
40
+ must_restart
41
+
45
42
  enter 'restart'
46
43
  debug_proc(@example)
47
- check_error_includes "Don't know name of debugged program"
44
+ check_output_includes(/Re exec'ing:\s*#{BYEBUG_SCRIPT} #{$PROGRAM_NAME}/)
48
45
  end
49
46
 
50
47
  def test_does_not_restart_when_script_specified_does_not_exist
51
- force_set_const(Byebug, 'PROG_SCRIPT', 'blabla')
48
+ Byebug.debugged_program = 'blabla'
52
49
  must_restart.never
53
50
  enter 'restart'
54
51
  debug_proc(@example)
@@ -61,8 +58,9 @@ module Byebug
61
58
  enter 'restart'
62
59
  debug_proc(@example)
63
60
  check_output_includes 'Byebug was not called from the outset...'
64
- check_output_includes "Ruby program #{PROG_SCRIPT} not executable... " \
65
- "We'll wrap it in a ruby call"
61
+ check_output_includes \
62
+ "Ruby program #{Byebug.debugged_program} not executable... " \
63
+ "We'll wrap it in a ruby call"
66
64
  end
67
65
  end
68
66
  end
@@ -5,7 +5,7 @@ module Byebug
5
5
  def initialize
6
6
  @inst_a = 1
7
7
  @inst_b = 2
8
- @inst_c = "1" * 40
8
+ @inst_c = '1' * 40
9
9
  @inst_d = BasicObject.new
10
10
  end
11
11
 
data/test/runner_test.rb CHANGED
@@ -63,6 +63,13 @@ module Byebug
63
63
  Byebug::Runner.new.run
64
64
  end
65
65
 
66
+ def test_saved_debugged_program
67
+ ARGV.replace(%w(my_script -opt value))
68
+
69
+ Byebug::Runner.new.save_debugged_program
70
+ assert_match 'my_script', Byebug.debugged_program
71
+ end
72
+
66
73
  def test_run_with_no_rc_option
67
74
  ARGV.replace(%w(--no-rc my_script))
68
75
  Byebug.expects(:start)
data/test/test_helper.rb CHANGED
@@ -33,22 +33,18 @@ module Byebug
33
33
 
34
34
  byebug_bin = File.expand_path('../../../bin/byebug', __FILE__)
35
35
  force_set_const(Byebug, 'BYEBUG_SCRIPT', byebug_bin)
36
+ Byebug.debugged_program = $PROGRAM_NAME
36
37
 
37
38
  # include test files as ignored files
38
39
  glob_exp = File.expand_path('../../{lib,test/support}/**/*.rb', __FILE__)
39
40
  ignored_files = Dir.glob(glob_exp) + ['test/test_helper.rb']
40
41
  force_set_const(Byebug, 'IGNORED_FILES', ignored_files)
41
-
42
- force_set_const(Byebug, 'PROG_SCRIPT', $PROGRAM_NAME)
43
42
  end
44
43
 
45
44
  include Byebug::TestUtils
46
45
  end
47
46
  end
48
47
 
49
- # Init globals to avoid warnings
50
- $binding = binding # this is from irb...
51
-
52
48
  # Load the test files from the command line.
53
49
  argv = ARGV.select do |argument|
54
50
  case argument
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: byebug
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Rodriguez
@@ -10,48 +10,48 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-09-01 00:00:00.000000000 Z
13
+ date: 2014-09-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: columnize
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ~>
19
+ - - "~>"
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0.8'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ~>
26
+ - - "~>"
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0.8'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: slop
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ~>
33
+ - - "~>"
34
34
  - !ruby/object:Gem::Version
35
35
  version: '3.6'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ~>
40
+ - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '3.6'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: debugger-linecache
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ~>
47
+ - - "~>"
48
48
  - !ruby/object:Gem::Version
49
49
  version: '1.2'
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ~>
54
+ - - "~>"
55
55
  - !ruby/object:Gem::Version
56
56
  version: '1.2'
57
57
  description: |-
@@ -70,9 +70,9 @@ extra_rdoc_files:
70
70
  - README.md
71
71
  - GUIDE.md
72
72
  files:
73
- - .gitignore
74
- - .rubocop.yml
75
- - .travis.yml
73
+ - ".gitignore"
74
+ - ".rubocop.yml"
75
+ - ".travis.yml"
76
76
  - CHANGELOG.md
77
77
  - CONTRIBUTING.md
78
78
  - GUIDE.md
@@ -207,12 +207,12 @@ require_paths:
207
207
  - lib
208
208
  required_ruby_version: !ruby/object:Gem::Requirement
209
209
  requirements:
210
- - - '>='
210
+ - - ">="
211
211
  - !ruby/object:Gem::Version
212
212
  version: 2.0.0
213
213
  required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  requirements:
215
- - - '>='
215
+ - - ">="
216
216
  - !ruby/object:Gem::Version
217
217
  version: '0'
218
218
  requirements: []