From 423107e4d588d1404fe20f6c7a055e8c32ada444 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sat, 10 Dec 2022 10:58:36 +0000 Subject: [PATCH 1/2] Add tests for prelude.rb --- test/console/debugger_method_test.rb | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/console/debugger_method_test.rb b/test/console/debugger_method_test.rb index 8cc32198f..1a7ce5406 100644 --- a/test/console/debugger_method_test.rb +++ b/test/console/debugger_method_test.rb @@ -177,4 +177,36 @@ def test_step_in_stops_the_program end end end + + class PreludeTest < ConsoleTestCase + def program + <<~RUBY + 1| require "debug/prelude" + 2| debugger_source = Kernel.method(:debugger).source_location + 3| a = 100 + 4| b = 20 + 5| debugger + 6| + 7| __END__ + RUBY + end + + def test_prelude_defines_debugger_statements + run_ruby(program, options: "-Ilib") do + assert_line_num(5) + type "a + b" + assert_line_text(/120/) + type "c" + end + end + + def test_prelude_doesnt_override_debugger + run_ruby(program, options: "-Ilib -rdebug") do + assert_line_num(5) + type "debugger_source" + assert_line_text(/debug\/session\.rb/) + type "c" + end + end + end end From 5f65d915b864b5412517fa4ded81813e9cd9b9b3 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sat, 10 Dec 2022 11:03:58 +0000 Subject: [PATCH 2/2] Use stricter check to skip prelude loading Fixes #865 --- lib/debug/prelude.rb | 2 +- test/console/debugger_method_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/debug/prelude.rb b/lib/debug/prelude.rb index 67ba18ca2..0f6611963 100644 --- a/lib/debug/prelude.rb +++ b/lib/debug/prelude.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true return if ENV['RUBY_DEBUG_ENABLE'] == '0' -return if defined?(::DEBUGGER__) +return if defined?(::DEBUGGER__::Session) # Put the following line in your login script (e.g. ~/.bash_profile) with modified path: # diff --git a/test/console/debugger_method_test.rb b/test/console/debugger_method_test.rb index 1a7ce5406..458870818 100644 --- a/test/console/debugger_method_test.rb +++ b/test/console/debugger_method_test.rb @@ -208,5 +208,14 @@ def test_prelude_doesnt_override_debugger type "c" end end + + def test_require_config_doesnt_cancel_prelude + run_ruby(program, options: "-Ilib -rdebug/config") do + assert_line_num(5) + type "a + b" + assert_line_text(/120/) + type "c" + end + end end end