Skip to content

Commit

Permalink
Remove init option to Byebug.start
Browse files Browse the repository at this point in the history
This option was used to enable/disable saving information about program
path and arguments to make restarts possible. This feature has been
removed and this information is always saved now. This also fixes some
order dependent failures in the `restart` command tests.
  • Loading branch information
David Rodríguez de Dios committed Apr 12, 2014
1 parent 39f8763 commit d8a2e36
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 53 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ behaves like shell's `history` command.
[50e6ad8](https://github.com/deivid-rodriguez/byebug/commit/50e6ad8)
* Changes in `finish` semantics and in the C extension API: see
[61f9b4d](https://github.com/deivid-rodriguez/byebug/commit/61f9b4d)
* The `init` option for Byebug.start has been removed. Information to make the
`restart` command work is always saved now.

- Features
* Allow disabling post_mortem mode
Expand Down
41 changes: 21 additions & 20 deletions lib/byebug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ module Byebug
IGNORED_FILES = Dir.glob(File.expand_path('../**/*.rb', __FILE__))

# Default options to Byebug.start
DEFAULT_START_SETTINGS = {
init: true, # Set $0 and save ARGV?
post_mortem: false, # post-mortem debugging on uncaught exception?
tracing: nil, # Byebug.tracing? value. true/false resets
save_history: true # Save history of byebug commands?
} unless defined?(DEFAULT_START_SETTINGS)
unless defined?(DEFAULT_START_SETTINGS)
DEFAULT_START_SETTINGS = { post_mortem: false,
tracing: false,
save_history: true }
end

# Configuration file used for startup commands. Default value is .byebugrc
INITFILE = '.byebugrc' unless defined?(INITFILE)

# Original ARGV, command line and initial directory to make restarts possible
ARGV = ARGV.clone unless defined?(ARGV)
PROG_SCRIPT = $0 unless defined?(PROG_SCRIPT)
INITIAL_DIR = Dir.pwd unless defined?(INITIAL_DIR)

class << self

# processor modules provide +handler+ object
Expand Down Expand Up @@ -99,26 +103,23 @@ def interface=(value)
# many times as you called Byebug.start method.</i>
#
# +options+ is a hash used to set various debugging options.
# :init - true if you want to save ARGV and some other variables to
# make a byebug restart possible. Only the first time :init
# is set to true the values will get set. Since ARGV is
# saved, you should make sure it hasn't been changed before
# the (first) call.
# :post_mortem - true if you want to enter post-mortem debugging on an
# uncaught exception. Once post-mortem debugging is set, it
# can't be unset.
# :post_mortem - true if you want to enter post-mortem debugging on an
# uncaught exception, false otherwise. Default: false.
# :tracing - true if line tracing should be enabled, false otherwise.
# Default: false.
# :save_history - true if byebug's command history should be saved to a
# file on program termination so that it can be reloaded
# later.
#
def start(options={}, &block)
options = Byebug::DEFAULT_START_SETTINGS.merge(options)
if options[:init]
Byebug.const_set('ARGV', ARGV.clone) unless defined? Byebug::ARGV
Byebug.const_set('PROG_SCRIPT', $0) unless defined? Byebug::PROG_SCRIPT
Byebug.const_set('INITIAL_DIR', Dir.pwd) unless defined? Byebug::INITIAL_DIR
end
Byebug.tracing = options[:tracing] unless options[:tracing].nil?
Byebug.tracing = options[:tracing]

retval = Byebug._start(&block)

post_mortem if options[:post_mortem]
at_exit { Byebug::History.save } if options[:save_history]

return retval
end

Expand Down
45 changes: 12 additions & 33 deletions test/restart_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,47 +60,26 @@ class TestRestart < TestDsl::TestCase
describe 'no script specified' do
temporary_change_const Byebug, 'PROG_SCRIPT', :__undefined__

describe 'and no $0 used' do
temporary_change_const Byebug, 'DEFAULT_START_SETTINGS',
{ init: false, post_mortem: false, tracing: nil }

it 'must not restart and show error messages instead' do
must_restart.never
debug_file 'restart'
check_output_includes 'Don\'t know name of debugged program',
interface.error_queue
end
end

describe 'but initialized from $0' do
it 'must use prog_script from $0' do
old_prog_name = $0
$0 = 'prog-0'
debug_file 'restart'
check_output_includes 'Ruby program prog-0 doesn\'t exist',
it 'must not restart and show error messages instead' do
must_restart.never
debug_file 'restart'
check_output_includes 'Don\'t know name of debugged program',
interface.error_queue
$0 = old_prog_name
end
end
end

describe 'no script at the specified path' do
temporary_change_const Byebug, 'PROG_SCRIPT', 'blabla'

describe 'and no restart params set' do
temporary_change_const Byebug, 'DEFAULT_START_SETTINGS',
init: false, post_mortem: false, tracing: nil

it 'must not restart' do
must_restart.never
debug_file 'restart'
end
it 'must not restart' do
must_restart.never
debug_file 'restart'
end

it 'must show an error message' do
debug_file 'restart'
check_output_includes 'Ruby program blabla doesn\'t exist',
interface.error_queue
end
it 'must show an error message' do
debug_file 'restart'
check_output_includes 'Ruby program blabla doesn\'t exist',
interface.error_queue
end
end

Expand Down

0 comments on commit d8a2e36

Please sign in to comment.