diff --git a/test/console/rdbg_option_test.rb b/test/console/rdbg_option_test.rb index 177dcac25..c2770963f 100644 --- a/test/console/rdbg_option_test.rb +++ b/test/console/rdbg_option_test.rb @@ -36,6 +36,70 @@ def test_debugger_doesnt_stop end end + class StopAtLoadOptionTest < ConsoleTestCase + def program + <<~RUBY + 1| a = "foo" + 2| binding.b + RUBY + end + + def test_debugger_stops_immediately + run_rdbg(program, options: "--stop-at-load") do + # stops at the earliest possible location + assert_line_text(/\[C\] Kernel#require/) + type "c" + type "a + 'bar'" + assert_line_text(/foobar/) + type "c" + end + end + end + + class RCFileTest < ConsoleTestCase + def rc_filename + File.join(pty_home_dir, ".rdbgrc") + end + + def rc_script + "config set skip_path /foo/bar/" + end + + def program + <<~RUBY + 1| a = 1 + RUBY + end + + def with_rc_script + File.open(rc_filename, "w") { |f| f.write(rc_script) } + + yield + ensure + File.delete(rc_filename) + end + + def test_debugger_loads_the_rc_file_by_default + with_rc_script do + run_rdbg(program) do + type "config skip_path" + assert_line_text(/foo\\\/bar/) + type "c" + end + end + end + + def test_debugger_doesnt_load_the_rc_file_with_no_rc + with_rc_script do + run_rdbg(program, options: "--no-rc") do + type "config skip_path" + assert_no_line_text(/foo\\\/bar/) + type "c" + end + end + end + end + class InitScriptTest < ConsoleTestCase TEMPFILE_BASENAME = __FILE__.hash.abs.to_s(16) diff --git a/test/support/console_test_case.rb b/test/support/console_test_case.rb index 18727b38e..390e1f092 100644 --- a/test/support/console_test_case.rb +++ b/test/support/console_test_case.rb @@ -80,7 +80,7 @@ def debug_code(program, remote: true, &test_steps) end def run_test_scenario cmd, test_info - PTY.spawn(cmd) do |read, write, pid| + PTY.spawn({ "HOME" => pty_home_dir }, cmd) do |read, write, pid| test_info.backlog = [] test_info.last_backlog = [] begin diff --git a/test/support/test_case.rb b/test/support/test_case.rb index 83aa70657..da7038337 100644 --- a/test/support/test_case.rb +++ b/test/support/test_case.rb @@ -22,6 +22,18 @@ class TestCase < Test::Unit::TestCase include AssertionHelpers + class << self + attr_reader :pty_home_dir + + def startup + @pty_home_dir = Dir.mktmpdir + end + + def shutdown + FileUtils.remove_entry @pty_home_dir + end + end + def setup @temp_file = nil end @@ -30,6 +42,10 @@ def teardown remove_temp_file end + def pty_home_dir + self.class.pty_home_dir + end + def temp_file_path @temp_file.path end