summaryrefslogtreecommitdiff
path: root/test/irb/command
diff options
context:
space:
mode:
Diffstat (limited to 'test/irb/command')
-rw-r--r--test/irb/command/test_cd.rb84
-rw-r--r--test/irb/command/test_command_aliasing.rb50
-rw-r--r--test/irb/command/test_copy.rb70
-rw-r--r--test/irb/command/test_custom_command.rb194
-rw-r--r--test/irb/command/test_disable_irb.rb28
-rw-r--r--test/irb/command/test_force_exit.rb51
-rw-r--r--test/irb/command/test_help.rb75
-rw-r--r--test/irb/command/test_multi_irb_commands.rb50
-rw-r--r--test/irb/command/test_show_source.rb410
9 files changed, 0 insertions, 1012 deletions
diff --git a/test/irb/command/test_cd.rb b/test/irb/command/test_cd.rb
deleted file mode 100644
index 10f77f6691..0000000000
--- a/test/irb/command/test_cd.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-require "tempfile"
-require_relative "../helper"
-
-module TestIRB
- class CDTest < IntegrationTestCase
- def setup
- super
-
- write_ruby <<~'RUBY'
- class Foo
- class Bar
- def bar
- "this is bar"
- end
- end
-
- def foo
- "this is foo"
- end
- end
-
- class BO < BasicObject
- def baz
- "this is baz"
- end
- end
-
- binding.irb
- RUBY
- end
-
- def test_cd
- out = run_ruby_file do
- type "cd Foo"
- type "ls"
- type "cd Bar"
- type "ls"
- type "cd .."
- type "exit"
- end
-
- assert_match(/irb\(Foo\):002>/, out)
- assert_match(/Foo#methods: foo/, out)
- assert_match(/irb\(Foo::Bar\):004>/, out)
- assert_match(/Bar#methods: bar/, out)
- assert_match(/irb\(Foo\):006>/, out)
- end
-
- def test_cd_basic_object_or_frozen
- out = run_ruby_file do
- type "cd BO.new"
- type "cd 1"
- type "cd Object.new.freeze"
- type "exit"
- end
-
- assert_match(/irb\(#<BO:.+\):002>/, out)
- assert_match(/irb\(1\):003>/, out)
- assert_match(/irb\(#<Object:.+\):004>/, out)
- end
-
- def test_cd_moves_top_level_with_no_args
- out = run_ruby_file do
- type "cd Foo"
- type "cd Bar"
- type "cd"
- type "exit"
- end
-
- assert_match(/irb\(Foo::Bar\):003>/, out)
- assert_match(/irb\(main\):004>/, out)
- end
-
- def test_cd_with_error
- out = run_ruby_file do
- type "cd Baz"
- type "exit"
- end
-
- assert_match(/Error: uninitialized constant Baz/, out)
- assert_match(/irb\(main\):002>/, out) # the context should not change
- end
- end
-end
diff --git a/test/irb/command/test_command_aliasing.rb b/test/irb/command/test_command_aliasing.rb
deleted file mode 100644
index 4ecc88c0aa..0000000000
--- a/test/irb/command/test_command_aliasing.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-# frozen_string_literal: true
-
-require "tempfile"
-require_relative "../helper"
-
-module TestIRB
- class CommandAliasingTest < IntegrationTestCase
- def setup
- super
- write_rc <<~RUBY
- IRB.conf[:COMMAND_ALIASES] = {
- :c => :conf, # alias to helper method
- :f => :foo
- }
- RUBY
-
- write_ruby <<~'RUBY'
- binding.irb
- RUBY
- end
-
- def test_aliasing_to_helper_method_triggers_warning
- out = run_ruby_file do
- type "c"
- type "exit"
- end
- assert_include(out, "Using command alias `c` for helper method `conf` is not supported.")
- assert_not_include(out, "Maybe IRB bug!")
- end
-
- def test_alias_to_non_existent_command_triggers_warning
- message = "You're trying to use command alias `f` for command `foo`, but `foo` does not exist."
- out = run_ruby_file do
- type "f"
- type "exit"
- end
- assert_include(out, message)
- assert_not_include(out, "Maybe IRB bug!")
-
- # Local variables take precedence over command aliases
- out = run_ruby_file do
- type "f = 123"
- type "f"
- type "exit"
- end
- assert_not_include(out, message)
- assert_not_include(out, "Maybe IRB bug!")
- end
- end
-end
diff --git a/test/irb/command/test_copy.rb b/test/irb/command/test_copy.rb
deleted file mode 100644
index 505812a1de..0000000000
--- a/test/irb/command/test_copy.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-# frozen_string_literal: true
-
-require 'irb'
-
-require_relative "../helper"
-
-module TestIRB
- class CopyTest < IntegrationTestCase
- def setup
- super
- @envs['IRB_COPY_COMMAND'] = "#{EnvUtil.rubybin} -e \"puts 'foo' + STDIN.read\""
- end
-
- def test_copy_with_pbcopy
- write_ruby <<~'ruby'
- class Answer
- def initialize(answer)
- @answer = answer
- end
- end
-
- binding.irb
- ruby
-
- output = run_ruby_file do
- type "copy Answer.new(42)"
- type "exit"
- end
-
- assert_match(/foo#<Answer:0x[0-9a-f]+ @answer=42/, output)
- assert_match(/Copied to system clipboard/, output)
- end
-
- # copy puts 5 should:
- # - Print value to the console
- # - Copy nil to clipboard, since that is what the puts call evaluates to
- def test_copy_when_expression_has_side_effects
- write_ruby <<~'ruby'
- binding.irb
- ruby
-
- output = run_ruby_file do
- type "copy puts 42"
- type "exit"
- end
-
- assert_match(/^42\r\n/, output)
- assert_match(/foonil/, output)
- assert_match(/Copied to system clipboard/, output)
- refute_match(/foo42/, output)
- end
-
- def test_copy_when_copy_command_is_invalid
- @envs['IRB_COPY_COMMAND'] = "lulz"
-
- write_ruby <<~'ruby'
- binding.irb
- ruby
-
- output = run_ruby_file do
- type "copy 42"
- type "exit"
- end
-
- assert_match(/No such file or directory - lulz/, output)
- assert_match(/Is IRB\.conf\[:COPY_COMMAND\] set to a bad value/, output)
- refute_match(/Copied to system clipboard/, output)
- end
- end
-end
diff --git a/test/irb/command/test_custom_command.rb b/test/irb/command/test_custom_command.rb
deleted file mode 100644
index 13f412c210..0000000000
--- a/test/irb/command/test_custom_command.rb
+++ /dev/null
@@ -1,194 +0,0 @@
-# frozen_string_literal: true
-require "irb"
-
-require_relative "../helper"
-
-module TestIRB
- class CustomCommandIntegrationTest < TestIRB::IntegrationTestCase
- def test_command_registration_can_happen_after_irb_require
- write_ruby <<~RUBY
- require "irb"
- require "irb/command"
-
- class PrintCommand < IRB::Command::Base
- category 'CommandTest'
- description 'print_command'
- def execute(*)
- puts "Hello from PrintCommand"
- end
- end
-
- IRB::Command.register(:print!, PrintCommand)
-
- binding.irb
- RUBY
-
- output = run_ruby_file do
- type "print!"
- type "exit"
- end
-
- assert_include(output, "Hello from PrintCommand")
- end
-
- def test_command_registration_accepts_string_too
- write_ruby <<~RUBY
- require "irb/command"
-
- class PrintCommand < IRB::Command::Base
- category 'CommandTest'
- description 'print_command'
- def execute(*)
- puts "Hello from PrintCommand"
- end
- end
-
- IRB::Command.register("print!", PrintCommand)
-
- binding.irb
- RUBY
-
- output = run_ruby_file do
- type "print!"
- type "exit"
- end
-
- assert_include(output, "Hello from PrintCommand")
- end
-
- def test_arguments_propagation
- write_ruby <<~RUBY
- require "irb/command"
-
- class PrintArgCommand < IRB::Command::Base
- category 'CommandTest'
- description 'print_command_arg'
- def execute(arg)
- $nth_execution ||= 0
- puts "\#{$nth_execution} arg=\#{arg.inspect}"
- $nth_execution += 1
- end
- end
-
- IRB::Command.register(:print_arg, PrintArgCommand)
-
- binding.irb
- RUBY
-
- output = run_ruby_file do
- type "print_arg"
- type "print_arg \n"
- type "print_arg a r g"
- type "print_arg a r g \n"
- type "exit"
- end
-
- assert_include(output, "0 arg=\"\"")
- assert_include(output, "1 arg=\"\"")
- assert_include(output, "2 arg=\"a r g\"")
- assert_include(output, "3 arg=\"a r g\"")
- end
-
- def test_def_extend_command_still_works
- write_ruby <<~RUBY
- require "irb"
-
- class FooBarCommand < IRB::Command::Base
- category 'FooBarCategory'
- description 'foobar_description'
- def execute(*)
- $nth_execution ||= 1
- puts "\#{$nth_execution} FooBar executed"
- $nth_execution += 1
- end
- end
-
- IRB::ExtendCommandBundle.def_extend_command(:foobar, FooBarCommand, nil, [:fbalias, IRB::Command::OVERRIDE_ALL])
-
- binding.irb
- RUBY
-
- output = run_ruby_file do
- type "foobar"
- type "fbalias"
- type "help foobar"
- type "exit"
- end
-
- assert_include(output, "1 FooBar executed")
- assert_include(output, "2 FooBar executed")
- assert_include(output, "foobar_description")
- end
-
- def test_no_meta_command_also_works
- write_ruby <<~RUBY
- require "irb/command"
-
- class NoMetaCommand < IRB::Command::Base
- def execute(*)
- puts "This command does not override meta attributes"
- end
- end
-
- IRB::Command.register(:no_meta, NoMetaCommand)
-
- binding.irb
- RUBY
-
- output = run_ruby_file do
- type "no_meta"
- type "help no_meta"
- type "exit"
- end
-
- assert_include(output, "This command does not override meta attributes")
- assert_include(output, "No description provided.")
- assert_not_include(output, "Maybe IRB bug")
- end
-
- def test_command_name_local_variable
- write_ruby <<~RUBY
- require "irb/command"
-
- class FooBarCommand < IRB::Command::Base
- category 'CommandTest'
- description 'test'
- def execute(arg)
- puts "arg=\#{arg.inspect}"
- end
- end
-
- IRB::Command.register(:foo_bar, FooBarCommand)
-
- binding.irb
- RUBY
-
- output = run_ruby_file do
- type "binding.irb"
- type "foo_bar == 1 || 1"
- type "foo_bar =~ /2/ || 2"
- type "exit"
- type "binding.irb"
- type "foo_bar = '3'; foo_bar"
- type "foo_bar == 4 || '4'"
- type "foo_bar =~ /5/ || '5'"
- type "exit"
- type "binding.irb"
- type "foo_bar ||= '6'; foo_bar"
- type "foo_bar == 7 || '7'"
- type "foo_bar =~ /8/ || '8'"
- type "exit"
- type "exit"
- end
-
- assert_include(output, 'arg="== 1 || 1"')
- assert_include(output, 'arg="=~ /2/ || 2"')
- assert_include(output, '=> "3"')
- assert_include(output, '=> "4"')
- assert_include(output, '=> "5"')
- assert_include(output, '=> "6"')
- assert_include(output, '=> "7"')
- assert_include(output, '=> "8"')
- end
- end
-end
diff --git a/test/irb/command/test_disable_irb.rb b/test/irb/command/test_disable_irb.rb
deleted file mode 100644
index 14a20043d5..0000000000
--- a/test/irb/command/test_disable_irb.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: false
-require 'irb'
-
-require_relative "../helper"
-
-module TestIRB
- class DisableIRBTest < IntegrationTestCase
- def test_disable_irb_disable_further_irb_breakpoints
- write_ruby <<~'ruby'
- puts "First line"
- puts "Second line"
- binding.irb
- puts "Third line"
- binding.irb
- puts "Fourth line"
- ruby
-
- output = run_ruby_file do
- type "disable_irb"
- end
-
- assert_match(/First line\r\n/, output)
- assert_match(/Second line\r\n/, output)
- assert_match(/Third line\r\n/, output)
- assert_match(/Fourth line\r\n/, output)
- end
- end
-end
diff --git a/test/irb/command/test_force_exit.rb b/test/irb/command/test_force_exit.rb
deleted file mode 100644
index 191a786872..0000000000
--- a/test/irb/command/test_force_exit.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-# frozen_string_literal: false
-require 'irb'
-
-require_relative "../helper"
-
-module TestIRB
- class ForceExitTest < IntegrationTestCase
- def test_forced_exit_finishes_process_immediately
- write_ruby <<~'ruby'
- puts "First line"
- puts "Second line"
- binding.irb
- puts "Third line"
- binding.irb
- puts "Fourth line"
- ruby
-
- output = run_ruby_file do
- type "123"
- type "456"
- type "exit!"
- end
-
- assert_match(/First line\r\n/, output)
- assert_match(/Second line\r\n/, output)
- assert_match(/irb\(main\):001> 123/, output)
- assert_match(/irb\(main\):002> 456/, output)
- refute_match(/Third line\r\n/, output)
- refute_match(/Fourth line\r\n/, output)
- end
-
- def test_forced_exit_in_nested_sessions
- write_ruby <<~'ruby'
- def foo
- binding.irb
- end
-
- binding.irb
- binding.irb
- ruby
-
- output = run_ruby_file do
- type "123"
- type "foo"
- type "exit!"
- end
-
- assert_match(/irb\(main\):001> 123/, output)
- end
- end
-end
diff --git a/test/irb/command/test_help.rb b/test/irb/command/test_help.rb
deleted file mode 100644
index b34832b022..0000000000
--- a/test/irb/command/test_help.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-require "tempfile"
-require_relative "../helper"
-
-module TestIRB
- class HelpTest < IntegrationTestCase
- def setup
- super
-
- write_rc <<~'RUBY'
- IRB.conf[:USE_PAGER] = false
- RUBY
-
- write_ruby <<~'RUBY'
- binding.irb
- RUBY
- end
-
- def test_help
- out = run_ruby_file do
- type "help"
- type "exit"
- end
-
- assert_match(/List all available commands/, out)
- assert_match(/Start the debugger of debug\.gem/, out)
- end
-
- def test_command_help
- out = run_ruby_file do
- type "help ls"
- type "exit"
- end
-
- assert_match(/Usage: ls \[obj\]/, out)
- end
-
- def test_command_help_not_found
- out = run_ruby_file do
- type "help foo"
- type "exit"
- end
-
- assert_match(/Can't find command `foo`\. Please check the command name and try again\./, out)
- end
-
- def test_show_cmds
- out = run_ruby_file do
- type "help"
- type "exit"
- end
-
- assert_match(/List all available commands/, out)
- assert_match(/Start the debugger of debug\.gem/, out)
- end
-
- def test_help_lists_user_aliases
- out = run_ruby_file do
- type "help"
- type "exit"
- end
-
- assert_match(/\$\s+Alias for `show_source`/, out)
- assert_match(/@\s+Alias for `whereami`/, out)
- end
-
- def test_help_lists_helper_methods
- out = run_ruby_file do
- type "help"
- type "exit"
- end
-
- assert_match(/Helper methods\s+conf\s+Returns the current IRB context/, out)
- end
- end
-end
diff --git a/test/irb/command/test_multi_irb_commands.rb b/test/irb/command/test_multi_irb_commands.rb
deleted file mode 100644
index e313c0c5d2..0000000000
--- a/test/irb/command/test_multi_irb_commands.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require "tempfile"
-require_relative "../helper"
-
-module TestIRB
- class MultiIRBTest < IntegrationTestCase
- def setup
- super
-
- write_ruby <<~'RUBY'
- binding.irb
- RUBY
- end
-
- def test_jobs_command_with_print_deprecated_warning
- out = run_ruby_file do
- type "jobs"
- type "exit"
- end
-
- assert_match(/Multi-irb commands are deprecated and will be removed in IRB 2\.0\.0\. Please use workspace commands instead\./, out)
- assert_match(%r|If you have any use case for multi-irb, please leave a comment at https://github.com/ruby/irb/issues/653|, out)
- assert_match(/#0->irb on main \(#<Thread:0x.+ run>: running\)/, out)
- end
-
- def test_irb_jobs_and_kill_commands
- out = run_ruby_file do
- type "irb"
- type "jobs"
- type "kill 1"
- type "exit"
- end
-
- assert_match(/#0->irb on main \(#<Thread:0x.+ sleep_forever>: stop\)/, out)
- assert_match(/#1->irb#1 on main \(#<Thread:0x.+ run>: running\)/, out)
- end
-
- def test_irb_fg_jobs_and_kill_commands
- out = run_ruby_file do
- type "irb"
- type "fg 0"
- type "jobs"
- type "kill 1"
- type "exit"
- end
-
- assert_match(/#0->irb on main \(#<Thread:0x.+ run>: running\)/, out)
- assert_match(/#1->irb#1 on main \(#<Thread:0x.+ sleep_forever>: stop\)/, out)
- end
- end
-end
diff --git a/test/irb/command/test_show_source.rb b/test/irb/command/test_show_source.rb
deleted file mode 100644
index a4227231e4..0000000000
--- a/test/irb/command/test_show_source.rb
+++ /dev/null
@@ -1,410 +0,0 @@
-# frozen_string_literal: false
-require 'irb'
-
-require_relative "../helper"
-
-module TestIRB
- class ShowSourceTest < IntegrationTestCase
- def setup
- super
-
- write_rc <<~'RUBY'
- IRB.conf[:USE_PAGER] = false
- RUBY
- end
-
- def test_show_source
- write_ruby <<~'RUBY'
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "show_source IRB.conf"
- type "exit"
- end
-
- assert_match(%r[/irb\/init\.rb], out)
- end
-
- def test_show_source_alias
- write_ruby <<~'RUBY'
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "$ IRB.conf"
- type "exit"
- end
-
- assert_match(%r[/irb\/init\.rb], out)
- end
-
- def test_show_source_with_missing_signature
- write_ruby <<~'RUBY'
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "show_source foo"
- type "exit"
- end
-
- assert_match(%r[Couldn't locate a definition for foo], out)
- end
-
- def test_show_source_with_missing_constant
- write_ruby <<~'RUBY'
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "show_source Foo"
- type "exit"
- end
-
- assert_match(%r[Couldn't locate a definition for Foo], out)
- end
-
- def test_show_source_with_eval_error
- write_ruby <<~'RUBY'
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "show_source raise(Exception).itself"
- type "exit"
- end
-
- assert_match(%r[Couldn't locate a definition for raise\(Exception\)\.itself], out)
- end
-
- def test_show_source_string
- write_ruby <<~'RUBY'
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "show_source 'IRB.conf'"
- type "exit"
- end
-
- assert_match(%r[/irb\/init\.rb], out)
- end
-
- def test_show_source_method_s
- write_ruby <<~RUBY
- class Baz
- def foo
- end
- end
-
- class Bar < Baz
- def foo
- super
- end
- end
-
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "show_source Bar#foo -s"
- type "exit"
- end
-
- assert_match(%r[#{@ruby_file.to_path}:2\s+def foo\r\n end\r\n], out)
- end
-
- def test_show_source_method_s_with_incorrect_signature
- write_ruby <<~RUBY
- class Baz
- def foo
- end
- end
-
- class Bar < Baz
- def foo
- super
- end
- end
-
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "show_source Bar#fooo -s"
- type "exit"
- end
-
- assert_match(%r[Error: Couldn't locate a super definition for Bar#fooo], out)
- end
-
- def test_show_source_private_method
- write_ruby <<~RUBY
- class Bar
- private def foo
- end
- end
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "show_source Bar#foo"
- type "exit"
- end
-
- assert_match(%r[#{@ruby_file.to_path}:2\s+private def foo\r\n end\r\n], out)
- end
-
- def test_show_source_private_singleton_method
- write_ruby <<~RUBY
- class Bar
- private def foo
- end
- end
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "bar = Bar.new"
- type "show_source bar.foo"
- type "exit"
- end
-
- assert_match(%r[#{@ruby_file.to_path}:2\s+private def foo\r\n end\r\n], out)
- end
-
- def test_show_source_method_multiple_s
- write_ruby <<~RUBY
- class Baz
- def foo
- end
- end
-
- class Bar < Baz
- def foo
- super
- end
- end
-
- class Bob < Bar
- def foo
- super
- end
- end
-
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "show_source Bob#foo -ss"
- type "exit"
- end
-
- assert_match(%r[#{@ruby_file.to_path}:2\s+def foo\r\n end\r\n], out)
- end
-
- def test_show_source_method_no_instance_method
- write_ruby <<~RUBY
- class Baz
- end
-
- class Bar < Baz
- def foo
- super
- end
- end
-
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "show_source Bar#foo -s"
- type "exit"
- end
-
- assert_match(%r[Error: Couldn't locate a super definition for Bar#foo], out)
- end
-
- def test_show_source_method_exceeds_super_chain
- write_ruby <<~RUBY
- class Baz
- def foo
- end
- end
-
- class Bar < Baz
- def foo
- super
- end
- end
-
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "show_source Bar#foo -ss"
- type "exit"
- end
-
- assert_match(%r[Error: Couldn't locate a super definition for Bar#foo], out)
- end
-
- def test_show_source_method_accidental_characters
- write_ruby <<~'RUBY'
- class Baz
- def foo
- end
- end
-
- class Bar < Baz
- def foo
- super
- end
- end
-
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "show_source Bar#foo -sddddd"
- type "exit"
- end
-
- assert_match(%r[#{@ruby_file.to_path}:2\s+def foo\r\n end], out)
- end
-
- def test_show_source_receiver_super
- write_ruby <<~RUBY
- class Baz
- def foo
- end
- end
-
- class Bar < Baz
- def foo
- super
- end
- end
-
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "bar = Bar.new"
- type "show_source bar.foo -s"
- type "exit"
- end
-
- assert_match(%r[#{@ruby_file.to_path}:2\s+def foo\r\n end], out)
- end
-
- def test_show_source_with_double_colons
- write_ruby <<~RUBY
- class Foo
- end
-
- class Foo
- class Bar
- end
- end
-
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "show_source ::Foo"
- type "exit"
- end
-
- assert_match(%r[#{@ruby_file.to_path}:1\s+class Foo\r\nend], out)
-
- out = run_ruby_file do
- type "show_source ::Foo::Bar"
- type "exit"
- end
-
- assert_match(%r[#{@ruby_file.to_path}:5\s+class Bar\r\n end], out)
- end
-
- def test_show_source_keep_script_lines
- pend unless defined?(RubyVM.keep_script_lines)
-
- write_ruby <<~RUBY
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "def foo; end"
- type "show_source foo"
- type "exit"
- end
-
- assert_match(%r[#{@ruby_file.to_path}\(irb\):1\s+def foo; end], out)
- end
-
- def test_show_source_unavailable_source
- write_ruby <<~RUBY
- binding.irb
- RUBY
-
- out = run_ruby_file do
- type "RubyVM.keep_script_lines = false if defined?(RubyVM.keep_script_lines)"
- type "def foo; end"
- type "show_source foo"
- type "exit"
- end
- assert_match(%r[#{@ruby_file.to_path}\(irb\):2\s+Source not available], out)
- end
-
- def test_show_source_shows_binary_source
- write_ruby <<~RUBY
- # io-console is an indirect dependency of irb
- require "io/console"
-
- binding.irb
- RUBY
-
- out = run_ruby_file do
- # IO::ConsoleMode is defined in io-console gem's C extension
- type "show_source IO::ConsoleMode"
- type "exit"
- end
-
- # A safeguard to make sure the test subject is actually defined
- refute_match(/NameError/, out)
- assert_match(%r[Defined in binary file:.+io/console], out)
- end
-
- def test_show_source_with_constant_lookup
- write_ruby <<~RUBY
- X = 1
- module M
- Y = 1
- Z = 2
- end
- class A
- Z = 1
- Array = 1
- class B
- include M
- Object.new.instance_eval { binding.irb }
- end
- end
- RUBY
-
- out = run_ruby_file do
- type "show_source X"
- type "show_source Y"
- type "show_source Z"
- type "show_source Array"
- type "exit"
- end
-
- assert_match(%r[#{@ruby_file.to_path}:1\s+X = 1], out)
- assert_match(%r[#{@ruby_file.to_path}:3\s+Y = 1], out)
- assert_match(%r[#{@ruby_file.to_path}:7\s+Z = 1], out)
- assert_match(%r[#{@ruby_file.to_path}:8\s+Array = 1], out)
- end
- end
-end