summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-24 14:11:25 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-24 14:11:25 +0000
commitfb29cffab05cb5446c1e6cd68035c39143b02763 (patch)
tree1419c170d120a0ba906168f66054b73dbec7ea46 /test/ruby
parent7184e03eb259b31a1e2fda200e63924ec4a041b3 (diff)
downloadruby-fb29cffab05cb5446c1e6cd68035c39143b02763.tar.gz
process.c: add :exception option to Kernel.#system
to raise error when it fails. [Feature 14386] [GH-1795] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_system.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_system.rb b/test/ruby/test_system.rb
index 60037ab044..0c0ad33fb6 100644
--- a/test/ruby/test_system.rb
+++ b/test/ruby/test_system.rb
@@ -160,4 +160,23 @@ 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)
+ system("'#{ruby}' -e 'exit 1'", exception: false)
+ end
+ assert_raise(Errno::ENOENT) do
+ system('feature_14235', exception: true)
+ end
+ assert_raise(RuntimeError) do
+ system("'#{ruby}' -e 'exit 1'", exception: true)
+ end
+ begin
+ system("'#{ruby}' -e 'exit 1'", exception: true)
+ rescue RuntimeError => e
+ assert_equal true, e.message.include?('status (1)')
+ end
+ end
end