2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2014-08-12 22:19:48 -04:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
module TestIRB
|
|
|
|
class TestRaiseNoBacktraceException < Test::Unit::TestCase
|
|
|
|
def test_raise_exception
|
2021-05-31 01:56:50 -04:00
|
|
|
pend if RUBY_ENGINE == 'truffleruby'
|
2019-06-12 11:29:45 -04:00
|
|
|
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
|
|
|
|
assert_in_out_err(bundle_exec + %w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<-IRB, /Exception: foo/, [])
|
2014-08-12 22:19:48 -04:00
|
|
|
e = Exception.new("foo")
|
2019-03-20 14:50:05 -04:00
|
|
|
puts e.inspect
|
2014-08-12 22:19:48 -04:00
|
|
|
def e.backtrace; nil; end
|
|
|
|
raise e
|
|
|
|
IRB
|
|
|
|
end
|
2020-12-27 20:45:17 -05:00
|
|
|
|
|
|
|
def test_raise_exception_with_invalid_byte_sequence
|
2021-05-31 01:56:50 -04:00
|
|
|
pend if RUBY_ENGINE == 'truffleruby' || /mswin|mingw/ =~ RUBY_PLATFORM
|
2020-12-27 20:45:17 -05:00
|
|
|
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
|
2021-05-11 01:45:29 -04:00
|
|
|
assert_in_out_err(bundle_exec + %w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<~IRB, /A\\xF3B \(StandardError\)/, [])
|
2020-12-27 20:45:17 -05:00
|
|
|
raise StandardError, "A\\xf3B"
|
|
|
|
IRB
|
|
|
|
end
|
2021-05-08 23:12:42 -04:00
|
|
|
|
|
|
|
def test_raise_exception_with_different_encoding_containing_invalid_byte_sequence
|
2021-05-31 01:56:50 -04:00
|
|
|
pend if RUBY_ENGINE == 'truffleruby'
|
2021-05-08 23:12:42 -04:00
|
|
|
backup_home = ENV["HOME"]
|
|
|
|
Dir.mktmpdir("test_irb_raise_no_backtrace_exception_#{$$}") do |tmpdir|
|
|
|
|
ENV["HOME"] = tmpdir
|
|
|
|
|
|
|
|
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
|
2021-05-18 03:02:56 -04:00
|
|
|
File.open("#{tmpdir}/euc.rb", 'w') do |f|
|
2021-05-08 23:12:42 -04:00
|
|
|
f.write(<<~EOF)
|
|
|
|
# encoding: euc-jp
|
|
|
|
|
|
|
|
def raise_euc_with_invalid_byte_sequence
|
|
|
|
raise "\xA4\xA2\\xFF"
|
|
|
|
end
|
|
|
|
EOF
|
|
|
|
end
|
2021-05-11 06:37:31 -04:00
|
|
|
env = {}
|
|
|
|
%w(LC_MESSAGES LC_ALL LC_CTYPE LANG).each {|n| env[n] = "ja_JP.UTF-8" }
|
2021-05-18 03:02:56 -04:00
|
|
|
args = [env] + bundle_exec + %W[-rirb -C #{tmpdir} -W0 -e IRB.start(__FILE__) -- -f --]
|
|
|
|
error = /`raise_euc_with_invalid_byte_sequence': あ\\xFF \(RuntimeError\)/
|
|
|
|
assert_in_out_err(args, <<~IRB, error, [], encoding: "UTF-8")
|
2021-05-08 23:12:42 -04:00
|
|
|
require_relative 'euc'
|
|
|
|
raise_euc_with_invalid_byte_sequence
|
|
|
|
IRB
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
ENV["HOME"] = backup_home
|
|
|
|
end
|
2014-08-12 22:19:48 -04:00
|
|
|
end
|
|
|
|
end
|