summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2023-12-18 14:36:55 +0000
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-12-20 19:11:01 +0900
commit2793a30b69177e7c7bbf124ccfca7b4f4216ca84 (patch)
treee3482667fc4e646e69b1b9ca698249dee9825bdd /test
parent7c2d8198625ca2e38835ad06ab47b4ea3afbc34b (diff)
[ruby/irb] Warn users about errors in loading RC files
(https://github.com/ruby/irb/pull/817) 1. Because `IRB.rc_file` always generates an rc file name, even if the file doesn't exist, we should check the file exists before trying to load it. 2. If any type of errors occur while loading the rc file, we should warn the user about it. https://github.com/ruby/irb/commit/37ffdc6b19
Diffstat (limited to 'test')
-rw-r--r--test/irb/test_init.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb
index b6a8f5529b..7d11b5b507 100644
--- a/test/irb/test_init.rb
+++ b/test/irb/test_init.rb
@@ -218,4 +218,44 @@ module TestIRB
ARGV.replace(orig)
end
end
+
+ class InitIntegrationTest < IntegrationTestCase
+ def test_load_error_in_rc_file_is_warned
+ write_rc <<~'IRBRC'
+ require "file_that_does_not_exist"
+ IRBRC
+
+ write_ruby <<~'RUBY'
+ binding.irb
+ RUBY
+
+ output = run_ruby_file do
+ type "'foobar'"
+ type "exit"
+ end
+
+ # IRB session should still be started
+ assert_includes output, "foobar"
+ assert_includes output, 'cannot load such file -- file_that_does_not_exist (LoadError)'
+ end
+
+ def test_normal_errors_in_rc_file_is_warned
+ write_rc <<~'IRBRC'
+ raise "I'm an error"
+ IRBRC
+
+ write_ruby <<~'RUBY'
+ binding.irb
+ RUBY
+
+ output = run_ruby_file do
+ type "'foobar'"
+ type "exit"
+ end
+
+ # IRB session should still be started
+ assert_includes output, "foobar"
+ assert_includes output, 'I\'m an error (RuntimeError)'
+ end
+ end
end