From fb29cffab05cb5446c1e6cd68035c39143b02763 Mon Sep 17 00:00:00 2001 From: k0kubun Date: Wed, 24 Jan 2018 14:11:25 +0000 Subject: 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 --- test/ruby/test_system.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/ruby') 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 -- cgit v1.2.3