From c9fbc779a680f3e1fd884ec80722cd32a990e0e9 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Mon, 21 Nov 2022 00:46:22 -0800 Subject: [ruby/irb] Add commands to start and use the debugger (https://github.com/ruby/irb/pull/449) * Seamlessly integrate a few debug commands * Improve the break command support * Utilize skip_src option if available * Add step and delete commands * Write end-to-end tests for each debugger command * Add documentation * Add backtrace, info, catch commands https://github.com/ruby/irb/commit/976100c1c2 --- test/irb/yamatanooroti/test_rendering.rb | 227 ++++++++++++++++++++++++++++++- 1 file changed, 226 insertions(+), 1 deletion(-) (limited to 'test/irb/yamatanooroti/test_rendering.rb') diff --git a/test/irb/yamatanooroti/test_rendering.rb b/test/irb/yamatanooroti/test_rendering.rb index f9a130b7d4..485fa47c25 100644 --- a/test/irb/yamatanooroti/test_rendering.rb +++ b/test/irb/yamatanooroti/test_rendering.rb @@ -17,6 +17,8 @@ begin @irbrc_backup = ENV['IRBRC'] @irbrc_file = ENV['IRBRC'] = File.join(@tmpdir, 'temporaty_irbrc') File.unlink(@irbrc_file) if File.exist?(@irbrc_file) + @ruby_file = File.join(@tmpdir, 'ruby_file.rb') + File.unlink(@ruby_file) if File.exist?(@ruby_file) end def teardown @@ -235,11 +237,234 @@ begin EOC end - private def write_irbrc(content) + def test_debug + write_ruby <<~'RUBY' + puts "start IRB" + binding.irb + puts "Hello" + RUBY + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@ruby_file}}, startup_message: 'start IRB') + write("debug\n") + write("next\n") + close + assert_include_screen(<<~EOC) + (rdbg) next # command + [1, 3] in #{@ruby_file} + 1| puts "start IRB" + 2| binding.irb + => 3| puts "Hello" + EOC + end + + def test_break + write_ruby <<~'RUBY' + puts "start IRB" + binding.irb + puts "Hello" + puts "World" + RUBY + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@ruby_file}}, startup_message: 'start IRB') + write("break 3\n") + write("continue\n") + close + assert_include_screen(<<~EOC) + (rdbg:irb) break 3 + #0 BP - Line #{@ruby_file}:3 (line) + EOC + assert_include_screen(<<~EOC) + (rdbg) continue # command + [1, 4] in #{@ruby_file} + 1| puts "start IRB" + 2| binding.irb + => 3| puts "Hello" + 4| puts "World" + =>#0
at #{@ruby_file}:3 + + Stop by #0 BP - Line #{@ruby_file}:3 (line) + EOC + end + + def test_delete + write_ruby <<~'RUBY' + puts "start IRB" + binding.irb + puts "Hello" + binding.irb + puts "World" + RUBY + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@ruby_file}}, startup_message: 'start IRB') + write("break 5\n") + write("continue\n") + write("delete 0\n") + close + assert_include_screen(<<~EOC) + (rdbg:irb) delete 0 + deleted: #0 BP - Line #{@ruby_file}:5 (line) + EOC + end + + def test_next + write_ruby <<~'RUBY' + puts "start IRB" + binding.irb + puts "Hello" + puts "World" + RUBY + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@ruby_file}}, startup_message: 'start IRB') + write("next\n") + close + assert_include_screen(<<~EOC) + (rdbg:irb) next + [1, 4] in #{@ruby_file} + 1| puts "start IRB" + 2| binding.irb + => 3| puts "Hello" + 4| puts "World" + =>#0
at #{@ruby_file}:3 + EOC + end + + def test_step + write_ruby <<~'RUBY' + puts "start IRB" + def foo + puts "Hello" + end + binding.irb + foo + puts "World" + RUBY + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@ruby_file}}, startup_message: 'start IRB') + write("step\n") + close + assert_include_screen(<<~EOC) + (rdbg:irb) step + [1, 7] in #{@ruby_file} + 1| puts "start IRB" + 2| def foo + => 3| puts "Hello" + 4| end + 5| binding.irb + EOC + end + + def test_continue + write_ruby <<~'RUBY' + puts "start IRB" + binding.irb + puts "Hello" + binding.irb + puts "World" + RUBY + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@ruby_file}}, startup_message: 'start IRB') + write("continue\n") + close + assert_include_screen(<<~EOC) + (rdbg:irb) continue + Hello + + From: #{@ruby_file} @ line 4 : + + 1: puts "start IRB" + 2: binding.irb + 3: puts "Hello" + => 4: binding.irb + 5: puts "World" + EOC + end + + def test_finish + write_ruby <<~'RUBY' + puts "start IRB" + def foo + binding.irb + puts "Hello" + end + foo + puts "World" + RUBY + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@ruby_file}}, startup_message: 'start IRB') + write("finish\n") + close + assert_include_screen(<<~EOC) + (rdbg:irb) finish + Hello + [1, 7] in #{@ruby_file} + 1| puts "start IRB" + 2| def foo + 3| binding.irb + 4| puts "Hello" + => 5| end + 6| foo + EOC + end + + def test_backtrace + write_ruby <<~'RUBY' + puts "start IRB" + def foo + binding.irb + end + foo + RUBY + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@ruby_file}}, startup_message: 'start IRB') + write("backtrace\n") + close + assert_include_screen(<<~EOC) + (rdbg:irb) backtrace + =>#0 Object#foo at #{@ruby_file}:3 + #1
at #{@ruby_file}:5 + EOC + end + + def test_info + write_ruby <<~'RUBY' + puts "start IRB" + a = 1 + binding.irb + RUBY + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@ruby_file}}, startup_message: 'start IRB') + write("info\n") + close + assert_include_screen(<<~EOC) + (rdbg:irb) info + %self = main + a = 1 + EOC + end + + def test_catch + write_ruby <<~'RUBY' + puts "start IRB" + binding.irb + raise NotImplementedError + RUBY + start_terminal(25, 80, %W{ruby -I#{@pwd}/lib #{@ruby_file}}, startup_message: 'start IRB') + write("catch NotImplementedError\n") + write("continue\n") + close + assert_include_screen(<<~EOC) + Stop by #0 BP - Catch "NotImplementedError" + EOC + end + + private + + def assert_include_screen(expected) + assert_include(result.join("\n"), expected) + end + + def write_irbrc(content) File.open(@irbrc_file, 'w') do |f| f.write content end end + + def write_ruby(content) + File.open(@ruby_file, 'w') do |f| + f.write content + end + end end rescue LoadError, NameError # On Ruby repository, this test suit doesn't run because Ruby repo doesn't -- cgit v1.2.3