mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
75bfc6440d
commit
1d15d5f080
4370 changed files with 0 additions and 0 deletions
50
spec/ruby/library/socket/shared/pack_sockaddr.rb
Normal file
50
spec/ruby/library/socket/shared/pack_sockaddr.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
# coding: utf-8
|
||||
describe :socket_pack_sockaddr_in, shared: true do
|
||||
it "packs and unpacks" do
|
||||
sockaddr_in = Socket.public_send(@method, 0, nil)
|
||||
port, addr = Socket.unpack_sockaddr_in(sockaddr_in)
|
||||
["127.0.0.1", "::1"].include?(addr).should == true
|
||||
port.should == 0
|
||||
|
||||
sockaddr_in = Socket.public_send(@method, 0, '')
|
||||
Socket.unpack_sockaddr_in(sockaddr_in).should == [0, '0.0.0.0']
|
||||
|
||||
sockaddr_in = Socket.public_send(@method, 80, '127.0.0.1')
|
||||
Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1']
|
||||
|
||||
sockaddr_in = Socket.public_send(@method, '80', '127.0.0.1')
|
||||
Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1']
|
||||
|
||||
sockaddr_in = Socket.public_send(@method, nil, '127.0.0.1')
|
||||
Socket.unpack_sockaddr_in(sockaddr_in).should == [0, '127.0.0.1']
|
||||
end
|
||||
end
|
||||
|
||||
describe :socket_pack_sockaddr_un, shared: true do
|
||||
platform_is_not :windows do
|
||||
it 'should be idempotent' do
|
||||
bytes = Socket.public_send(@method, '/tmp/foo').bytes
|
||||
bytes[2..9].should == [47, 116, 109, 112, 47, 102, 111, 111]
|
||||
bytes[10..-1].all?(&:zero?).should == true
|
||||
end
|
||||
|
||||
it "packs and unpacks" do
|
||||
sockaddr_un = Socket.public_send(@method, '/tmp/s')
|
||||
Socket.unpack_sockaddr_un(sockaddr_un).should == '/tmp/s'
|
||||
end
|
||||
|
||||
it "handles correctly paths with multibyte chars" do
|
||||
sockaddr_un = Socket.public_send(@method, '/home/вася/sock')
|
||||
path = Socket.unpack_sockaddr_un(sockaddr_un).encode('UTF-8', 'UTF-8')
|
||||
path.should == '/home/вася/sock'
|
||||
end
|
||||
end
|
||||
|
||||
platform_is_not :windows, :aix do
|
||||
it "raises if path length exceeds max size" do
|
||||
# AIX doesn't raise error
|
||||
long_path = Array.new(512, 0).join
|
||||
lambda { Socket.public_send(@method, long_path) }.should raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
describe "partially closable sockets", shared: true do
|
||||
it "if the write end is closed then the other side can read past EOF without blocking" do
|
||||
@s1.write("foo")
|
||||
@s1.close_write
|
||||
@s2.read("foo".size + 1).should == "foo"
|
||||
end
|
||||
|
||||
it "closing the write end ensures that the other side can read until EOF" do
|
||||
@s1.write("hello world")
|
||||
@s1.close_write
|
||||
@s2.read.should == "hello world"
|
||||
end
|
||||
end
|
54
spec/ruby/library/socket/shared/recv_nonblock.rb
Normal file
54
spec/ruby/library/socket/shared/recv_nonblock.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
describe :socket_recv_nonblock, shared: true do
|
||||
before :each do
|
||||
@s1 = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)
|
||||
@s2 = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@s1.close unless @s1.closed?
|
||||
@s2.close unless @s2.closed?
|
||||
end
|
||||
|
||||
it "raises an exception extending IO::WaitReadable if there's no data available" do
|
||||
@s1.bind(Socket.pack_sockaddr_in(0, "127.0.0.1"))
|
||||
lambda {
|
||||
@s1.recv_nonblock(5)
|
||||
}.should raise_error(IO::WaitReadable) { |e|
|
||||
platform_is_not :windows do
|
||||
e.should be_kind_of(Errno::EAGAIN)
|
||||
end
|
||||
platform_is :windows do
|
||||
e.should be_kind_of(Errno::EWOULDBLOCK)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
it "receives data after it's ready" do
|
||||
@s1.bind(Socket.pack_sockaddr_in(0, "127.0.0.1"))
|
||||
@s2.send("aaa", 0, @s1.getsockname)
|
||||
IO.select([@s1], nil, nil, 2)
|
||||
@s1.recv_nonblock(5).should == "aaa"
|
||||
end
|
||||
|
||||
ruby_version_is "2.3" do
|
||||
it "allows an output buffer as third argument" do
|
||||
@s1.bind(Socket.pack_sockaddr_in(0, "127.0.0.1"))
|
||||
@s2.send("data", 0, @s1.getsockname)
|
||||
IO.select([@s1], nil, nil, 2)
|
||||
|
||||
buf = "foo"
|
||||
@s1.recv_nonblock(5, 0, buf)
|
||||
buf.should == "data"
|
||||
end
|
||||
end
|
||||
|
||||
it "does not block if there's no data available" do
|
||||
@s1.bind(Socket.pack_sockaddr_in(0, "127.0.0.1"))
|
||||
@s2.send("a", 0, @s1.getsockname)
|
||||
IO.select([@s1], nil, nil, 2)
|
||||
@s1.recv_nonblock(1).should == "a"
|
||||
lambda {
|
||||
@s1.recv_nonblock(5)
|
||||
}.should raise_error(IO::WaitReadable)
|
||||
end
|
||||
end
|
23
spec/ruby/library/socket/shared/socketpair.rb
Normal file
23
spec/ruby/library/socket/shared/socketpair.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
describe :socket_socketpair, shared: true do
|
||||
platform_is_not :windows do
|
||||
it "ensures the returned sockets are connected" do
|
||||
s1, s2 = Socket.public_send(@method, Socket::AF_UNIX, 1, 0)
|
||||
s1.puts("test")
|
||||
s2.gets.should == "test\n"
|
||||
s1.close
|
||||
s2.close
|
||||
end
|
||||
|
||||
it "responses with array of two sockets" do
|
||||
begin
|
||||
s1, s2 = Socket.public_send(@method, :UNIX, :STREAM)
|
||||
|
||||
s1.should be_an_instance_of(Socket)
|
||||
s2.should be_an_instance_of(Socket)
|
||||
ensure
|
||||
s1.close
|
||||
s2.close
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue