summaryrefslogtreecommitdiff
path: root/test/ruby/test_system.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_system.rb')
-rw-r--r--test/ruby/test_system.rb58
1 files changed, 56 insertions, 2 deletions
diff --git a/test/ruby/test_system.rb b/test/ruby/test_system.rb
index db19a3c2cd..3fcdaa6aad 100644
--- a/test/ruby/test_system.rb
+++ b/test/ruby/test_system.rb
@@ -1,6 +1,6 @@
+# frozen_string_literal: false
require 'test/unit'
require 'tmpdir'
-require_relative 'envutil'
class TestSystem < Test::Unit::TestCase
def test_system
@@ -86,7 +86,7 @@ class TestSystem < Test::Unit::TestCase
File.unlink tmpfilename
testname = '[ruby-core:44505]'
- assert_match /Windows/, `ver`, testname
+ assert_match(/Windows/, `ver`, testname)
assert_equal 0, $?.to_i, testname
end
}
@@ -146,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
@@ -160,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