From 9238b2f6b77f38065ba0b63427163753dc273631 Mon Sep 17 00:00:00 2001 From: st0012 Date: Mon, 8 Nov 2021 10:30:36 +0000 Subject: [PATCH 1/4] Add stop-at-load test --- test/console/rdbg_option_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/console/rdbg_option_test.rb b/test/console/rdbg_option_test.rb index 177dcac25..38468d5b1 100644 --- a/test/console/rdbg_option_test.rb +++ b/test/console/rdbg_option_test.rb @@ -36,6 +36,26 @@ 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 InitScriptTest < ConsoleTestCase TEMPFILE_BASENAME = __FILE__.hash.abs.to_s(16) From 538f90ad548ab6c3e3dac2ada8843ee6d1101e77 Mon Sep 17 00:00:00 2001 From: st0012 Date: Mon, 8 Nov 2021 11:00:54 +0000 Subject: [PATCH 2/4] Add rdbgrc file test --- test/console/rdbg_option_test.rb | 43 ++++++++++++++++++++++++++++++++ test/support/test_case.rb | 1 + 2 files changed, 44 insertions(+) diff --git a/test/console/rdbg_option_test.rb b/test/console/rdbg_option_test.rb index 38468d5b1..e2803eeac 100644 --- a/test/console/rdbg_option_test.rb +++ b/test/console/rdbg_option_test.rb @@ -56,6 +56,49 @@ def test_debugger_stops_immediately end end + class RCFileTest < ConsoleTestCase + def rc_script + "config set skip_path /foo/bar/" + end + + def program + <<~RUBY + 1| a = 1 + RUBY + end + + def with_rc_script + rc_filename = "~/.rdbgrc" + renamed_rc_filename = "~/.rdbgrc.original" + File.rename(rc_filename, renamed_rc_filename) if File.exist?(rc_filename) + File.open(File.join(Dir.home, ".rdbgrc"), "w") { |f| f.write(rc_script) } + + yield + ensure + File.rename(renamed_rc_filename, rc_filename) if File.exist?(renamed_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/test_case.rb b/test/support/test_case.rb index 83aa70657..cf4264563 100644 --- a/test/support/test_case.rb +++ b/test/support/test_case.rb @@ -27,6 +27,7 @@ def setup end def teardown + FileUtils.remove_entry @pty_home_dir remove_temp_file end From db703f4548de5819c353384b83024b2dd63f9de0 Mon Sep 17 00:00:00 2001 From: st0012 Date: Mon, 8 Nov 2021 11:18:51 +0000 Subject: [PATCH 3/4] Ignore user's rdbgrc script in tests --- test/console/rdbg_option_test.rb | 11 ++++++----- test/support/console_test_case.rb | 2 +- test/support/test_case.rb | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/test/console/rdbg_option_test.rb b/test/console/rdbg_option_test.rb index e2803eeac..1524ff68e 100644 --- a/test/console/rdbg_option_test.rb +++ b/test/console/rdbg_option_test.rb @@ -57,6 +57,10 @@ def test_debugger_stops_immediately end class RCFileTest < ConsoleTestCase + def rc_filename + File.join(@pty_home_dir, ".rdbgrc") + end + def rc_script "config set skip_path /foo/bar/" end @@ -68,14 +72,11 @@ def program end def with_rc_script - rc_filename = "~/.rdbgrc" - renamed_rc_filename = "~/.rdbgrc.original" - File.rename(rc_filename, renamed_rc_filename) if File.exist?(rc_filename) - File.open(File.join(Dir.home, ".rdbgrc"), "w") { |f| f.write(rc_script) } + File.open(rc_filename, "w") { |f| f.write(rc_script) } yield ensure - File.rename(renamed_rc_filename, rc_filename) if File.exist?(renamed_rc_filename) + File.delete(rc_filename) end def test_debugger_loads_the_rc_file_by_default diff --git a/test/support/console_test_case.rb b/test/support/console_test_case.rb index 18727b38e..fc18d4819 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 cf4264563..d436f9b56 100644 --- a/test/support/test_case.rb +++ b/test/support/test_case.rb @@ -24,6 +24,7 @@ class TestCase < Test::Unit::TestCase def setup @temp_file = nil + @pty_home_dir = Dir.mktmpdir end def teardown From f029421e44dc4380b54d987e0e2e59b02b664dcc Mon Sep 17 00:00:00 2001 From: st0012 Date: Sun, 17 Apr 2022 22:14:10 +0100 Subject: [PATCH 4/4] Use startup/shutdown callback for pty_home_dir setup --- test/console/rdbg_option_test.rb | 2 +- test/support/console_test_case.rb | 2 +- test/support/test_case.rb | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/test/console/rdbg_option_test.rb b/test/console/rdbg_option_test.rb index 1524ff68e..c2770963f 100644 --- a/test/console/rdbg_option_test.rb +++ b/test/console/rdbg_option_test.rb @@ -58,7 +58,7 @@ def test_debugger_stops_immediately class RCFileTest < ConsoleTestCase def rc_filename - File.join(@pty_home_dir, ".rdbgrc") + File.join(pty_home_dir, ".rdbgrc") end def rc_script diff --git a/test/support/console_test_case.rb b/test/support/console_test_case.rb index fc18d4819..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({ "HOME" => @pty_home_dir }, 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 d436f9b56..da7038337 100644 --- a/test/support/test_case.rb +++ b/test/support/test_case.rb @@ -22,16 +22,30 @@ 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 - @pty_home_dir = Dir.mktmpdir end def teardown - FileUtils.remove_entry @pty_home_dir remove_temp_file end + def pty_home_dir + self.class.pty_home_dir + end + def temp_file_path @temp_file.path end