Skip to content

Commit

Permalink
use assert_raise
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jun 2, 2015
1 parent 21f2c19 commit ae042f2
Show file tree
Hide file tree
Showing 30 changed files with 100 additions and 100 deletions.
2 changes: 1 addition & 1 deletion test/digest/test_digest_extend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def digest_length
end

def test_block_length
assert_raises(RuntimeError) do
assert_raise(RuntimeError) do
@MyDigest.new.block_length
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/io/wait/test_io_wait.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_wait_writable_EPIPE

def test_wait_writable_closed
@w.close
assert_raises(IOError) { @w.wait_writable }
assert_raise(IOError) { @w.wait_writable }
end

private
Expand Down
2 changes: 1 addition & 1 deletion test/logger/test_logdevice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_initialize
logdev = d(STDERR)
assert_equal(STDERR, logdev.dev)
assert_nil(logdev.filename)
assert_raises(TypeError) do
assert_raise(TypeError) do
d(nil)
end
#
Expand Down
2 changes: 1 addition & 1 deletion test/net/http/test_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ def @server.run(sock)
end

start {|http|
assert_raises(EOFError, Errno::ECONNRESET, IOError) {
assert_raise(EOFError, Errno::ECONNRESET, IOError) {
http.get('/')
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/net/http/test_httpresponse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def test_ensure_zero_space_does_not_regress
hello
EOS

assert_raises Net::HTTPBadResponse do
assert_raise Net::HTTPBadResponse do
Net::HTTPResponse.read_new(io)
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/net/smtp/test_smtp.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'net/smtp'
require 'stringio'
require 'minitest/autorun'
require 'test/unit'

module Net
class TestSMTP < MiniTest::Unit::TestCase
class TestSMTP < Test::Unit::TestCase
class FakeSocket
def initialize out = "250 OK\n"
@write_io = StringIO.new
Expand All @@ -24,7 +24,7 @@ def readline
def test_critical
smtp = Net::SMTP.new 'localhost', 25

assert_raises RuntimeError do
assert_raise RuntimeError do
smtp.send :critical do
raise 'fail on purpose'
end
Expand Down
6 changes: 3 additions & 3 deletions test/net/smtp/test_ssl_socket.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'net/smtp'
require 'minitest/autorun'
require 'test/unit'

module Net
class TestSSLSocket < MiniTest::Unit::TestCase
class TestSSLSocket < Test::Unit::TestCase
class MySMTP < SMTP
attr_accessor :fake_tcp, :fake_ssl

Expand Down Expand Up @@ -52,7 +52,7 @@ def post_connection_check omg
connection.fake_tcp = tcp_socket
connection.fake_ssl = ssl_socket

assert_raises(OpenSSL::SSL::SSLError) do
assert_raise(OpenSSL::SSL::SSLError) do
connection.start
end
assert_equal true, ssl_socket.closed
Expand Down
2 changes: 1 addition & 1 deletion test/open-uri/test_open-uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_read_timeout
end

def test_open_timeout
assert_raises(Net::OpenTimeout) do
assert_raise(Net::OpenTimeout) do
URI("http://example.com/").read(open_timeout: 0.000001)
end if false # avoid external resources in tests

Expand Down
2 changes: 1 addition & 1 deletion test/openssl/test_asn1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def test_bit_string_infinite_length
end

def test_primitive_inf_length
assert_raises(OpenSSL::ASN1::ASN1Error) do
assert_raise(OpenSSL::ASN1::ASN1Error) do
spec = %w{ 02 80 02 01 01 00 00 }
raw = [spec.join('')].pack('H*')
OpenSSL::ASN1.decode(raw)
Expand Down
2 changes: 1 addition & 1 deletion test/openssl/test_buffering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def @io.syswrite *a
raise SystemCallError, 'fail'
end

assert_raises SystemCallError do
assert_raise SystemCallError do
@io.flush
end

Expand Down
2 changes: 1 addition & 1 deletion test/openssl/test_digest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_digest_by_oid_and_name_sha2
def test_openssl_digest
assert_equal OpenSSL::Digest::MD5, OpenSSL::Digest("MD5")

assert_raises NameError do
assert_raise NameError do
OpenSSL::Digest("no such digest")
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/openssl/test_pkcs12.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_create_with_chain_decode
end

def test_create_with_bad_nid
assert_raises(ArgumentError) do
assert_raise(ArgumentError) do
OpenSSL::PKCS12.create(
"omg",
"hello",
Expand All @@ -137,7 +137,7 @@ def test_create_with_itr
2048
)

assert_raises(TypeError) do
assert_raise(TypeError) do
OpenSSL::PKCS12.create(
"omg",
"hello",
Expand All @@ -164,7 +164,7 @@ def test_create_with_mac_itr
2048
)

assert_raises(TypeError) do
assert_raise(TypeError) do
OpenSSL::PKCS12.create(
"omg",
"hello",
Expand Down
2 changes: 1 addition & 1 deletion test/openssl/test_pkey_dh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_new

def test_new_break
assert_nil(OpenSSL::PKey::DH.new(NEW_KEYLEN) { break })
assert_raises(RuntimeError) do
assert_raise(RuntimeError) do
OpenSSL::PKey::DH.new(NEW_KEYLEN) { raise }
end
end
Expand Down
42 changes: 21 additions & 21 deletions test/optparse/test_acceptable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ def test_integer
assert_equal(%w"", no_error {@opt.parse!(%w"--integer 0x3")})
assert_equal(3, @integer)

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--integer 0b")
end

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--integer 09")
end

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--integer 0x")
end

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--integer 1234xyz")
end
end
Expand All @@ -65,11 +65,11 @@ def test_float
assert_equal(%w"", no_error {@opt.parse!(%w"--float 1E-2")})
assert_in_epsilon(0.01, @float)

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--float 0e")
end

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--float 1.234xyz")
end
end
Expand All @@ -87,15 +87,15 @@ def test_numeric
assert_equal(%w"", no_error {@opt.parse!(%w"--numeric 1.2/2.3")})
assert_equal(Rational(12, 23), @numeric)

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--numeric 1/")
end

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--numeric 12/34xyz")
end

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--numeric 12x/34yz")
end
end
Expand All @@ -107,21 +107,21 @@ def test_decimal_integer
assert_equal(%w"", no_error {@opt.parse!(%w"--decimal-integer 10")})
assert_equal(10, @decimal_integer)

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--decimal-integer 0b1")
end

e = assert_raises(OptionParser::InvalidArgument) do
e = assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--decimal-integer 09")
end

assert_equal("invalid argument: --decimal-integer 09", e.message)

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--decimal-integer x")
end

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--decimal-integer 1234xyz")
end
end
Expand All @@ -142,19 +142,19 @@ def test_octal_integer
assert_equal(%w"", no_error {@opt.parse!(%w"--octal-integer 011")})
assert_equal(9, @octal_integer)

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--octal-integer 09")
end

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--octal-integer 0b1")
end

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--octal-integer x")
end

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--octal-integer 01234xyz")
end
end
Expand All @@ -172,21 +172,21 @@ def test_decimal_numeric
assert_equal(%w"", no_error {@opt.parse!(%w"--decimal-numeric 1E2")})
assert_in_delta(100.0, @decimal_numeric)

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--decimal-numeric 0b1")
end

e = assert_raises(OptionParser::InvalidArgument) do
e = assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--decimal-numeric 09")
end

assert_equal("invalid argument: --decimal-numeric 09", e.message)

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--decimal-integer 1234xyz")
end

assert_raises(OptionParser::InvalidArgument) do
assert_raise(OptionParser::InvalidArgument) do
@opt.parse!(%w"--decimal-integer 12.34xyz")
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/rexml/test_changing_encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_0_euc
@f.encoding = 'EUC-JP'
assert_equal( @u, @f.decode(@e) )
# This doesn't happen anymore, for some reason
#assert_raises( Iconv::IllegalSequence, "Decoding unicode should fail" ) {
#assert_raise( Iconv::IllegalSequence, "Decoding unicode should fail" ) {
# @f.decode(@u) == @u
#}
end
Expand All @@ -36,7 +36,7 @@ def test_2_euc
@f.encoding = 'EUC-JP'
assert_equal( @u, @f.decode(@e) )
# This doesn't happen anymore, for some reason
#assert_raises( Iconv::IllegalSequence, "Decoding unicode should fail" ) {
#assert_raise( Iconv::IllegalSequence, "Decoding unicode should fail" ) {
# @f.decode(@u) == @u
#}
end
Expand Down
4 changes: 2 additions & 2 deletions test/rexml/test_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_entity_string_limit
# above 10k explodes
entities = '&a;' * 3 # 5k entity * 2 = 15k
xmldoc = REXML::Document.new(template.sub(/\$/, entities))
assert_raises(RuntimeError) do
assert_raise(RuntimeError) do
xmldoc.root.text
end
end
Expand All @@ -134,7 +134,7 @@ def test_entity_string_limit_for_parameter_entity

# above 10k explodes
entities = '%a;' * 3 # 5k entity * 2 = 15k
assert_raises(REXML::ParseException) do
assert_raise(REXML::ParseException) do
REXML::Document.new(template.sub(/\$/, entities))
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/ruby/test_gc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_latest_gc_info_argument

assert_not_empty info
assert_equal info[:gc_by], GC.latest_gc_info(:gc_by)
assert_raises(ArgumentError){ GC.latest_gc_info(:invalid) }
assert_raise(ArgumentError){ GC.latest_gc_info(:invalid) }
assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) {GC.latest_gc_info(:"\u{30eb 30d3 30fc}")}
end

Expand Down
2 changes: 1 addition & 1 deletion test/socket/test_nonblock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def test_sendmsg_nonblock_error
def test_sendmsg_nonblock_seqpacket
buf = '*' * 10000
UNIXSocket.pair(:SEQPACKET) do |s1, s2|
assert_raises(IO::WaitWritable) do
assert_raise(IO::WaitWritable) do
loop { s1.sendmsg_nonblock(buf) }
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/socket/test_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_bind
port, = Socket.unpack_sockaddr_in(addr)

Socket.open(Socket::AF_INET, Socket::SOCK_STREAM, 0) {|s|
e = assert_raises(Errno::EADDRINUSE) do
e = assert_raise(Errno::EADDRINUSE) do
s.bind(Socket.sockaddr_in(port, "127.0.0.1"))
end

Expand Down Expand Up @@ -556,7 +556,7 @@ def test_connect_timeout
# some platforms may not timeout when the listener queue overflows,
# but we know Linux does with the default listen backlog of SOMAXCONN for
# TCPServer.
assert_raises(Errno::ETIMEDOUT) do
assert_raise(Errno::ETIMEDOUT) do
(Socket::SOMAXCONN*2).times do |i|
sock = Socket.tcp(host, port, :connect_timeout => 0)
assert_equal sock, IO.select(nil, [ sock ])[1][0],
Expand Down
4 changes: 2 additions & 2 deletions test/socket/test_tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def test_encoding

def test_accept_nonblock
TCPServer.open("localhost", 0) {|svr|
assert_raises(IO::WaitReadable) { svr.accept_nonblock }
assert_raise(IO::WaitReadable) { svr.accept_nonblock }
assert_equal :wait_readable, svr.accept_nonblock(exception: false)
assert_raises(IO::WaitReadable) { svr.accept_nonblock(exception: true) }
assert_raise(IO::WaitReadable) { svr.accept_nonblock(exception: true) }
}
end
end if defined?(TCPSocket)
4 changes: 2 additions & 2 deletions test/socket/test_udp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_bind_addrinuse

s = UDPSocket.new

e = assert_raises(Errno::EADDRINUSE) do
e = assert_raise(Errno::EADDRINUSE) do
s.bind(host, port)
end

Expand All @@ -61,7 +61,7 @@ def test_bind_addrinuse
def test_send_too_long
u = UDPSocket.new

e = assert_raises Errno::EMSGSIZE do
e = assert_raise(Errno::EMSGSIZE) do
u.send "\0" * 100_000, 0, "127.0.0.1", 7 # echo
end

Expand Down
Loading

0 comments on commit ae042f2

Please sign in to comment.