diff options
Diffstat (limited to 'test/ruby/test_system.rb')
| -rw-r--r-- | test/ruby/test_system.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/ruby/test_system.rb b/test/ruby/test_system.rb index b328cbcc1d..3fcdaa6aad 100644 --- a/test/ruby/test_system.rb +++ b/test/ruby/test_system.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require 'test/unit' require 'tmpdir' @@ -145,6 +146,19 @@ class TestSystem < Test::Unit::TestCase end end + def test_system_closed + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + ios = [] + ObjectSpace.each_object(IO) {|io| ios << io} + `echo` + ObjectSpace.each_object(IO) do |io| + next if ios.include?(io) + assert_nothing_raised {io.close} + end + end; + end + def test_empty_evstr assert_equal("", eval('"#{}"', nil, __FILE__, __LINE__), "[ruby-dev:25113]") end @@ -159,4 +173,45 @@ class TestSystem < Test::Unit::TestCase assert_equal(true, system(tmpfilename), '[ruby-core:32745]') } end if File.executable?("/bin/sh") + + def test_system_exception + ruby = EnvUtil.rubybin + assert_nothing_raised do + system('feature_14235', exception: false) + end + assert_nothing_raised do + system(ruby, "-e", "abort", exception: false) + end + assert_nothing_raised do + system("'#{ruby}' -e abort", exception: false) + end + assert_raise(Errno::ENOENT) do + system('feature_14235', exception: true) + end + assert_raise_with_message(RuntimeError, /\ACommand failed with exit /) do + system(ruby, "-e", "abort", exception: true) + end + assert_raise_with_message(RuntimeError, /\ACommand failed with exit /) do + system("'#{ruby}' -e abort", exception: true) + end + end + + def test_system_exception_nonascii + Dir.mktmpdir("ruby_script_tmp") do |tmpdir| + name = "\u{30c6 30b9 30c8}" + tmpfilename = "#{tmpdir}/#{name}.cmd" + message = /#{name}\.cmd/ + assert_raise_with_message(Errno::ENOENT, message) do + system(tmpfilename, exception: true) + end + open(tmpfilename, "w") {|f| + f.print "@" if /mingw|mswin/ =~ RUBY_PLATFORM + f.puts "exit 127" + f.chmod(0755) + } + assert_raise_with_message(RuntimeError, message) do + system(tmpfilename, exception: true) + end + end + end end |
