diff options
author | tomoya ishida <tomoyapenguin@gmail.com> | 2024-02-13 03:38:27 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2024-02-12 18:38:30 +0000 |
commit | 7af97dc71fd6790a3f4ffe47dcc5720b675f6b6b (patch) | |
tree | 746868021ac678da2ab27261d88794a1daf9e2d2 /test | |
parent | e878bbd641f255b5d8f9e99b84ff8082a5b7fdaf (diff) |
[ruby/irb] Powerup show_source by enabling RubyVM.keep_script_lines
(https://github.com/ruby/irb/pull/862)
* Powerup show_source by enabling RubyVM.keep_script_lines
* Add file_content field to avoid reading file twice while show_source
* Change path passed to eval, don't change irb_path.
* Encapsulate source coloring logic and binary file check insode class Source
* Add edit command testcase when irb_path does not exist
* Memoize irb_path existence to reduce file existence check calculating eval_path
https://github.com/ruby/irb/commit/239683a937
Diffstat (limited to 'test')
-rw-r--r-- | test/irb/cmd/test_show_source.rb | 34 | ||||
-rw-r--r-- | test/irb/test_cmd.rb | 10 | ||||
-rw-r--r-- | test/irb/test_context.rb | 9 |
3 files changed, 51 insertions, 2 deletions
diff --git a/test/irb/cmd/test_show_source.rb b/test/irb/cmd/test_show_source.rb index c2608926e8..062ab327d7 100644 --- a/test/irb/cmd/test_show_source.rb +++ b/test/irb/cmd/test_show_source.rb @@ -301,7 +301,37 @@ module TestIRB assert_match(%r[#{@ruby_file.to_path}:5\s+class Bar\r\n end], out) end - def test_show_source_ignores_binary_source_file + 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" @@ -317,7 +347,7 @@ module TestIRB # A safeguard to make sure the test subject is actually defined refute_match(/NameError/, out) - assert_match(%r[Error: Couldn't locate a definition for IO::ConsoleMode], out) + assert_match(%r[Defined in binary file:.+io/console], out) end end end diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb index 349d2c0457..bc63587330 100644 --- a/test/irb/test_cmd.rb +++ b/test/irb/test_cmd.rb @@ -848,6 +848,16 @@ module TestIRB assert_match("command: ': code'", out) end + def test_edit_without_arg_and_non_existing_irb_path + out, err = execute_lines( + "edit", + irb_path: '/path/to/file.rb(irb)' + ) + + assert_empty err + assert_match(/Can not find file: \/path\/to\/file\.rb\(irb\)/, out) + end + def test_edit_with_path out, err = execute_lines( "edit #{__FILE__}" diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb index a761521691..0fdd847a65 100644 --- a/test/irb/test_context.rb +++ b/test/irb/test_context.rb @@ -666,6 +666,15 @@ module TestIRB ], out) end + def test_eval_path + @context.irb_path = __FILE__ + assert_equal("#{__FILE__}(irb)", @context.send(:eval_path)) + @context.irb_path = 'file/does/not/exist' + assert_equal('file/does/not/exist', @context.send(:eval_path)) + @context.irb_path = "#{__FILE__}(irb)" + assert_equal("#{__FILE__}(irb)", @context.send(:eval_path)) + end + def test_build_completor verbose, $VERBOSE = $VERBOSE, nil original_completor = IRB.conf[:COMPLETOR] |