byebug 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/GUIDE.md +210 -4
  4. data/README.md +93 -64
  5. data/bin/byebug +10 -4
  6. data/byebug.gemspec +1 -1
  7. data/ext/byebug/breakpoint.c +22 -20
  8. data/lib/byebug/command.rb +5 -3
  9. data/lib/byebug/commands/frame.rb +2 -1
  10. data/lib/byebug/commands/kill.rb +0 -1
  11. data/lib/byebug/commands/set.rb +5 -6
  12. data/lib/byebug/commands/show.rb +11 -11
  13. data/lib/byebug/version.rb +1 -1
  14. data/logo.png +0 -0
  15. data/old_doc/byebug.texi +2 -2
  16. data/old_doc/{test-tri2.rb → test-triangle.rb} +4 -5
  17. data/old_doc/tri3.rb +3 -5
  18. data/old_doc/triangle.rb +4 -2
  19. data/test/breakpoints_test.rb +1 -2
  20. data/test/conditions_test.rb +3 -4
  21. data/test/continue_test.rb +6 -8
  22. data/test/display_test.rb +1 -2
  23. data/test/edit_test.rb +1 -2
  24. data/test/eval_test.rb +1 -2
  25. data/test/examples/stepping.rb +4 -0
  26. data/test/finish_test.rb +1 -2
  27. data/test/frame_test.rb +1 -2
  28. data/test/help_test.rb +1 -2
  29. data/test/info_test.rb +1 -2
  30. data/test/jump_test.rb +1 -2
  31. data/test/kill_test.rb +1 -2
  32. data/test/list_test.rb +1 -2
  33. data/test/method_test.rb +1 -2
  34. data/test/post_mortem_test.rb +1 -2
  35. data/test/quit_test.rb +1 -2
  36. data/test/reload_test.rb +1 -2
  37. data/test/repl_test.rb +1 -2
  38. data/test/restart_test.rb +1 -2
  39. data/test/save_test.rb +1 -2
  40. data/test/set_test.rb +6 -11
  41. data/test/show_test.rb +5 -4
  42. data/test/source_test.rb +1 -2
  43. data/test/stepping_test.rb +81 -55
  44. data/test/support/test_dsl.rb +54 -54
  45. data/test/test_helper.rb +0 -1
  46. data/test/trace_test.rb +75 -80
  47. data/test/variables_test.rb +1 -2
  48. metadata +6 -5
data/bin/byebug CHANGED
@@ -25,7 +25,8 @@
25
25
  # Show invocation help and exit.
26
26
  #
27
27
  #<tt>-I | --include</tt> <i>path</i>
28
- # Add <i>path</i> to <tt>$LOAD_PATH</tt>
28
+ # Add <i>path</i> to <tt>$LOAD_PATH</tt>. Like the <tt>ruby -I</tt> command,
29
+ # it supports multiple load paths separated by colons.
29
30
  #
30
31
  #<tt>--keep-frame-binding</tt>::
31
32
  # Keep frame bindings.
@@ -124,12 +125,14 @@ Usage: #{program} [options] <script.rb> -- <script.rb parameters>
124
125
  EOB
125
126
  opts.separator ""
126
127
  opts.separator "Options:"
128
+
127
129
  opts.on("-A", "--annotate LEVEL", Integer, "Set annotation level") {
128
130
  |annotate| Byebug.annotate = annotate }
129
131
  opts.on("-d", "--debug", "Set $DEBUG=true") {
130
132
  $DEBUG = true }
131
- opts.on('-I', '--include PATH', String, 'Add PATH to $LOAD_PATH') {
132
- |path| $LOAD_PATH.unshift(path) }
133
+ opts.on('-I', '--include PATH', String,
134
+ 'Add PATH (single or multiple:path:list) to $LOAD_PATH.') {
135
+ |path| $LOAD_PATH.unshift(*path.split(':')) }
133
136
  opts.on('--no-quit', 'Do not quit when script finishes') {
134
137
  options.quit = false }
135
138
  opts.on('--no-rewrite-program', 'Don\'t set $0 to the program debugged') {
@@ -144,7 +147,8 @@ EOB
144
147
  else
145
148
  require name
146
149
  end }
147
- opts.on('--restart-script FILE', String, 'Name of the script file to run. Erased after read') do
150
+ opts.on('--restart-script FILE', String,
151
+ 'Name of the script file to run. Erased after read') do
148
152
  |restart_script|
149
153
  options.restart_script = restart_script
150
154
  unless File.exists?(options.restart_script)
@@ -162,6 +166,7 @@ EOB
162
166
  end
163
167
  opts.on('-x', '--trace', 'Turn on line tracing') {
164
168
  options.tracing = true }
169
+
165
170
  opts.separator ''
166
171
  opts.separator 'Common options:'
167
172
  opts.on_tail('--help', 'Show this message') do
@@ -197,6 +202,7 @@ rescue
197
202
  end
198
203
 
199
204
  opts = process_options(options)
205
+
200
206
  begin
201
207
  Byebug::ARGV = ARGV.clone if not defined? Byebug::ARGV
202
208
  Byebug::BYEBUG_SCRIPT = File.expand_path(__FILE__)
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency 'rake', '~> 10.0.4'
29
29
  s.add_development_dependency 'rake-compiler', '~> 0.8.3'
30
30
  s.add_development_dependency 'mocha', '~> 0.14.0'
31
- s.add_development_dependency 'minitest', '~> 5.0.1'
31
+ s.add_development_dependency 'minitest', '~> 5.0.2'
32
32
 
33
33
  s.license = "BSD"
34
34
  end
@@ -282,8 +282,8 @@ check_breakpoint_by_hit_condition(VALUE breakpoint_object)
282
282
 
283
283
  if (breakpoint_object == Qnil)
284
284
  return 0;
285
- Data_Get_Struct(breakpoint_object, breakpoint_t, breakpoint);
286
285
 
286
+ Data_Get_Struct(breakpoint_object, breakpoint_t, breakpoint);
287
287
  breakpoint->hit_count++;
288
288
 
289
289
  if (Qtrue != breakpoint->enabled)
@@ -320,19 +320,17 @@ check_breakpoint_by_pos(VALUE breakpoint_object, char *file, int line)
320
320
  {
321
321
  breakpoint_t *breakpoint;
322
322
 
323
- if(breakpoint_object == Qnil)
324
- return 0;
323
+ if (breakpoint_object == Qnil)
324
+ return 0;
325
+
325
326
  Data_Get_Struct(breakpoint_object, breakpoint_t, breakpoint);
326
327
 
327
- if (Qtrue != breakpoint->enabled)
328
- return 0;
329
- if(breakpoint->type != BP_POS_TYPE)
330
- return 0;
331
- if(breakpoint->pos.line != line)
332
- return 0;
333
- if(filename_cmp(breakpoint->source, file))
334
- return 1;
335
- return 0;
328
+ if ( (Qtrue != breakpoint->enabled) ||
329
+ (breakpoint->type != BP_POS_TYPE) ||
330
+ (breakpoint->pos.line != line) )
331
+ return 0;
332
+
333
+ return filename_cmp(breakpoint->source, file);
336
334
  }
337
335
 
338
336
  static int
@@ -343,18 +341,18 @@ check_breakpoint_by_method(VALUE breakpoint_object, VALUE klass, ID mid,
343
341
 
344
342
  if (breakpoint_object == Qnil)
345
343
  return 0;
344
+
346
345
  Data_Get_Struct(breakpoint_object, breakpoint_t, breakpoint);
347
346
 
348
- if (!Qtrue == breakpoint->enabled)
347
+ if ( (Qfalse == breakpoint->enabled) ||
348
+ (breakpoint->type != BP_METHOD_TYPE) ||
349
+ (breakpoint->pos.mid != mid) )
349
350
  return 0;
350
- if (breakpoint->type != BP_METHOD_TYPE)
351
- return 0;
352
- if (breakpoint->pos.mid != mid)
353
- return 0;
354
- if (classname_cmp(breakpoint->source, klass))
355
- return 1;
356
- if ((rb_type(self) == T_CLASS) && classname_cmp(breakpoint->source, self))
351
+
352
+ if ( (classname_cmp(breakpoint->source, klass)) ||
353
+ ((rb_type(self) == T_CLASS) && classname_cmp(breakpoint->source, self)) )
357
354
  return 1;
355
+
358
356
  return 0;
359
357
  }
360
358
 
@@ -366,14 +364,18 @@ check_breakpoint_by_expr(VALUE breakpoint_object, VALUE binding)
366
364
 
367
365
  if (breakpoint_object == Qnil)
368
366
  return 0;
367
+
369
368
  Data_Get_Struct(breakpoint_object, breakpoint_t, breakpoint);
370
369
 
371
370
  if (Qtrue != breakpoint->enabled)
372
371
  return 0;
372
+
373
373
  if (NIL_P(breakpoint->expr))
374
374
  return 1;
375
+
375
376
  args = rb_ary_new3(2, breakpoint->expr, binding);
376
377
  expr_result = rb_protect(eval_expression, args, 0);
378
+
377
379
  return RTEST(expr_result);
378
380
  }
379
381
 
@@ -40,8 +40,10 @@ module Byebug
40
40
  "--\n" \
41
41
  "List of \"#{cmd_name}\" subcommands:\n" \
42
42
  "--\n"
43
+ width = subcmds.map(&:name).max_by(&:size).size
43
44
  for subcmd in subcmds do
44
- s += "#{cmd_name} #{subcmd.name} -- #{subcmd.short_help}\n"
45
+ s += sprintf \
46
+ "%s %-#{width}s -- %s\n", cmd_name, subcmd.name, subcmd.short_help
45
47
  end
46
48
  return s
47
49
  end
@@ -155,8 +157,8 @@ module Byebug
155
157
  register_setting_var(:listsize, 10)
156
158
  register_setting_var(:stack_trace_on_error, false)
157
159
  register_setting_var(:tracing_plus, false)
158
- register_setting_var(:width,
159
- ENV['COLUMNS'].to_i > 10 ? ENV['COLUMNS'].to_i : 80)
160
+ cols = `stty size`.scan(/\d+/)[1].to_i
161
+ register_setting_var(:width, cols > 10 ? cols : 80)
160
162
  Byebug::ARGV = ARGV.clone unless defined? Byebug::ARGV
161
163
  register_setting_var(:argv, Byebug::ARGV)
162
164
 
@@ -167,7 +167,8 @@ module Byebug
167
167
  def execute
168
168
  print_backtrace
169
169
  if truncated_callstack?(@state.context, Byebug.start_sentinal)
170
- print "Warning: saved frames may be incomplete; compare with caller(0)"
170
+ print \
171
+ "Warning: saved frames may be incomplete; compare with caller(0)\n"
171
172
  end
172
173
  end
173
174
 
@@ -13,7 +13,6 @@ module Byebug
13
13
  end
14
14
 
15
15
  def execute
16
- puts @match[1]
17
16
  if @match[1]
18
17
  signame = @match[1]
19
18
  unless Signal.list.member?(signame)
@@ -11,16 +11,16 @@ module Byebug
11
11
  Subcommands =
12
12
  [
13
13
  ['annotate', 2, false, 'Set annotation level',
14
- '0 == normal. ' \
14
+ '0 == normal; ' \
15
15
  '2 == output annotated suitably for use by programs that control ' \
16
- 'byebug.'],
16
+ 'byebug'],
17
17
  ['args', 2, false,
18
18
  'Set argument list to give program being debugged when it is started'],
19
19
  ['autoeval', 4, true, 'Evaluate every unrecognized command'],
20
20
  ['autolist', 4, true, 'Execute "list" command on every breakpoint'],
21
21
  ['autoirb', 4, true, 'Invoke IRB on every stop'],
22
22
  ['autoreload', 4, true, 'Reload source code when changed'],
23
- ['basename', 1, true, 'Set filename display style.'],
23
+ ['basename', 1, true, 'Set filename display style'],
24
24
  ['callstyle', 2, false, 'Set how you want call parameters displayed'],
25
25
  ['testing', 2, false, 'Used when testing byebug'],
26
26
  ['forcestep', 2, true,
@@ -29,8 +29,8 @@ module Byebug
29
29
  ['history', 2, false,
30
30
  'Generic command for setting command history parameters',
31
31
  'set history filename -- Set the filename in which to record the ' \
32
- 'command history. ' \
33
- 'set history save -- Set saving of the history record on exit. ' \
32
+ 'command history' \
33
+ 'set history save -- Set saving of the history record on exit' \
34
34
  'set history size -- Set the size of the command history'],
35
35
  ['linetrace+', 10, true,
36
36
  'Set line execution tracing to show different lines'],
@@ -150,7 +150,6 @@ module Byebug
150
150
  width = get_int(args[0], "Set width", 10, nil, 80)
151
151
  return unless width
152
152
  Command.settings[:width] = width
153
- ENV['COLUMNS'] = width.to_s
154
153
  else
155
154
  return print "Unknown setting #{@match[1]}.\n"
156
155
  end
@@ -148,14 +148,14 @@ module Byebug
148
148
  Subcommands =
149
149
  [
150
150
  ['annotate', 2, 'Show annotation level',
151
- '0 == normal;' \
151
+ '0 == normal; ' \
152
152
  '2 == output annotated suitably for use by programs that control ' \
153
- 'byebug.'],
153
+ 'byebug'],
154
154
  ['args', 2,
155
- 'Show argument list to give to the program being debugged when it ' \
156
- 'is started',
157
- 'Follow this command with any number of args to be passed to the ' \
158
- 'program.'],
155
+ 'Show argument list to give to the program being debugged when it is' \
156
+ ' started',
157
+ 'Follow this command with any number of args to be passed to the ' \
158
+ 'program'],
159
159
  ['autoeval', 4, 'Show whether unrecognized commands are evaluated'],
160
160
  ['autolist', 4, 'Show whether "list" command is run on stopping'],
161
161
  ['autoirb', 4, 'Show whether IRB is invoked on stopping'],
@@ -163,21 +163,21 @@ module Byebug
163
163
  ['basename', 1, 'Show whether basename is used when reporting files'],
164
164
  ['callstyle', 2, 'Show paramater style used when showing call frames'],
165
165
  ['commands', 2, 'Show the history of commands you typed',
166
- 'You can supply a command number to start with.'],
166
+ 'You can supply a command number to start with'],
167
167
  ['forcestep', 1, 'Show whether "next/step" force to move onto a new ' \
168
168
  'line'],
169
169
  ['fullpath', 2, 'Show whether full paths are displayed in frames'],
170
170
  ['history', 2, 'Generic command to show command history parameters',
171
171
  'show history filename -- Show the filename in which to record the ' \
172
- 'command history.' \
172
+ 'command history' \
173
173
  'show history save -- Show whether history record should be saved ' \
174
- 'on exit.' \
175
- 'show history size -- Show the size of the command history.'],
174
+ 'on exit' \
175
+ 'show history size -- Show the size of the command history'],
176
176
  ['keep-frame-bindings', 1, 'Save frame binding on each call'],
177
177
  ['linetrace', 3, 'Show line execution tracing'],
178
178
  ['linetrace+', 10,
179
179
  'Show whether different consecutive lines are shown in tracing'],
180
- ['listsize', 3, 'Show number of source lines to list by default.'],
180
+ ['listsize', 3, 'Show number of source lines to list by default'],
181
181
  ['port', 3, 'Show server port'],
182
182
  ['post-mortem', 3,
183
183
  'Show whether we go into post-mortem debugging on an uncaught ' \
@@ -1,3 +1,3 @@
1
1
  module Byebug
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
Binary file
@@ -2670,8 +2670,8 @@ ability to change that state inside byebug.
2670
2670
  @table @code
2671
2671
  @kindex set width @var{column-width}
2672
2672
  @item set width @var{column-width}
2673
- Set number of characters per line of byebug output. We also change OS
2674
- environment variable @code{COLUMNS}.
2673
+ Set number of characters per line of byebug output. By default it is the number
2674
+ of columns in the current terminal.
2675
2675
  @kindex show width
2676
2676
  @item show width
2677
2677
  Shows the current width setting.
@@ -1,12 +1,11 @@
1
- #!/usr/bin/env ruby
2
- require "test/unit"
3
- require "tri2.rb"
4
- require "rubygems"
5
- require "byebug"
1
+ require 'test/unit'
2
+ require_relative 'triangle.rb'
3
+ require 'byebug'
6
4
  Byebug.start
7
5
 
8
6
  class TestTri < Test::Unit::TestCase
9
7
  def test_basic
8
+ require 'byebug'
10
9
  byebug
11
10
  solutions = []
12
11
  0.upto(5) do |i|
@@ -1,8 +1,6 @@
1
- #!/usr/bin/env ruby
2
- def triangle(n)
3
- (0..n).inject do |sum, i|
4
- sum +=i
1
+ def triangle(n)
2
+ (0..n).inject do |sum, i|
3
+ sum +=i
5
4
  end
6
5
  end
7
6
  puts triangle(3)
8
-
@@ -7,5 +7,7 @@ def triangle(n)
7
7
  tri
8
8
  end
9
9
 
10
- t = triangle(3)
11
- puts t
10
+ if __FILE__ == $0
11
+ t = triangle(3)
12
+ puts t
13
+ end
@@ -1,7 +1,6 @@
1
1
  require_relative 'test_helper'
2
2
 
3
- describe 'Breakpoints' do
4
- include TestDsl
3
+ class TestBreakpoints < TestDsl::TestCase
5
4
 
6
5
  describe 'setting breakpoint in the current file' do
7
6
  before { enter 'break 10' }
@@ -1,7 +1,6 @@
1
1
  require_relative 'test_helper'
2
2
 
3
- describe 'Conditions' do
4
- include TestDsl
3
+ class TestConditions < TestDsl::TestCase
5
4
 
6
5
  describe 'setting condition' do
7
6
  before { enter 'break 3' }
@@ -24,7 +23,7 @@ describe 'Conditions' do
24
23
  end
25
24
  end
26
25
 
27
- describe 'unsucessfully' do
26
+ describe 'unsuccessfully' do
28
27
  before { enter 'break 4' }
29
28
 
30
29
  it 'must not stop at the breakpoint if condition is false' do
@@ -53,7 +52,7 @@ describe 'Conditions' do
53
52
  debug_file('conditions') { Byebug.breakpoints.first.expr.must_be_nil }
54
53
  end
55
54
 
56
- it 'must not stop on the breakpoint' do
55
+ it 'must unconditionally stop on the breakpoint' do
57
56
  debug_file('conditions') { state.line.must_equal 3 }
58
57
  end
59
58
  end
@@ -1,7 +1,6 @@
1
1
  require_relative 'test_helper'
2
2
 
3
- describe "Continue Command" do
4
- include TestDsl
3
+ class TestContinue < TestDsl::TestCase
5
4
 
6
5
  describe "successful" do
7
6
  it "must continue up to breakpoint if no line specified" do
@@ -19,12 +18,11 @@ describe "Continue Command" do
19
18
  debug_file('continue') { state.line.must_equal 4 }
20
19
  end
21
20
 
22
- # XXX: Decide whether to keep original behaviour (i don't like it but maybe
23
- # I'm wrong) or make the test below pass
24
- #it "must not keep temporal breakpoint when line specified" do
25
- # enter 'cont 4'
26
- # debug_file('continue') { Byebug.breakpoints.size.must_equal 0 }
27
- #end
21
+ it "must not keep temporal breakpoint when line specified" do
22
+ skip 'Not working yet, breakpoint is currently kept'
23
+ enter 'cont 4'
24
+ debug_file('continue') { Byebug.breakpoints.size.must_equal 0 }
25
+ end
28
26
  end
29
27
 
30
28
  describe "unsuccessful" do
@@ -1,7 +1,6 @@
1
1
  require_relative 'test_helper'
2
2
 
3
- describe 'Display Command' do
4
- include TestDsl
3
+ class TestDisplay < TestDsl::TestCase
5
4
 
6
5
  it 'must show expressions' do
7
6
  enter 'break 3', 'cont', 'display d + 1'
@@ -1,7 +1,6 @@
1
1
  require_relative 'test_helper'
2
2
 
3
- describe 'Edit Command' do
4
- include TestDsl
3
+ class TestEdit < TestDsl::TestCase
5
4
 
6
5
  describe 'open configured editor' do
7
6
  temporary_change_hash ENV, 'EDITOR', 'editr'
@@ -1,7 +1,6 @@
1
1
  require_relative 'test_helper'
2
2
 
3
- describe 'Eval Command' do
4
- include TestDsl
3
+ class TestEval < TestDsl::TestCase
5
4
 
6
5
  it 'must evaluate an expression' do
7
6
  enter 'eval 3 + 2'
@@ -18,4 +18,8 @@ class SteppingExample
18
18
  end
19
19
 
20
20
  ex = SteppingExample.new.a
21
+ 2.times do
22
+ ex += 1
23
+ end
24
+
21
25
  ex
@@ -1,7 +1,6 @@
1
1
  require_relative 'test_helper'
2
2
 
3
- describe 'Finish Command' do
4
- include TestDsl
3
+ class TestFinish < TestDsl::TestCase
5
4
 
6
5
  it 'must stop at the next frame by default' do
7
6
  enter 'break 16', 'cont', 'finish'