[前][次][番号順一覧][スレッド一覧]

ruby-changes:52247

From: eregon <ko1@a...>
Date: Sun, 19 Aug 2018 04:45:13 +0900 (JST)
Subject: [ruby-changes:52247] eregon:r64462 (trunk): Be more flexible in the protocol value returned by getaddrinfo()

eregon	2018-08-19 04:37:29 +0900 (Sun, 19 Aug 2018)

  New Revision: 64462

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64462

  Log:
    Be more flexible in the protocol value returned by getaddrinfo()
    
    * Only Solaris 2.10 i386 and Windows seem to return 0 it and other
      Solaris seem to fill the value.

  Modified files:
    trunk/spec/ruby/library/socket/socket/getaddrinfo_spec.rb
Index: spec/ruby/library/socket/socket/getaddrinfo_spec.rb
===================================================================
--- spec/ruby/library/socket/socket/getaddrinfo_spec.rb	(revision 64461)
+++ spec/ruby/library/socket/socket/getaddrinfo_spec.rb	(revision 64462)
@@ -219,45 +219,43 @@ describe 'Socket.getaddrinfo' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/socket/socket/getaddrinfo_spec.rb#L219
       array[6].should be_an_instance_of(Fixnum)
     end
 
-    ipproto_tcp = Socket::IPPROTO_TCP
-    platform_is :windows do
-      ipproto_tcp = 0
-    end
-
     it 'accepts a Fixnum as the socket type' do
-      Socket.getaddrinfo(nil, 'ftp', :INET, Socket::SOCK_STREAM)[0].should == [
+      *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, Socket::SOCK_STREAM)[0]
+      array.should == [
         'AF_INET',
         21,
         '127.0.0.1',
         '127.0.0.1',
         Socket::AF_INET,
         Socket::SOCK_STREAM,
-        ipproto_tcp
       ]
+      [0, Socket::IPPROTO_TCP].should include(proto)
     end
 
     it 'accepts a Symbol as the socket type' do
-      Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM)[0].should == [
+      *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM)[0]
+      array.should == [
         'AF_INET',
         21,
         '127.0.0.1',
         '127.0.0.1',
         Socket::AF_INET,
         Socket::SOCK_STREAM,
-        ipproto_tcp
       ]
+      [0, Socket::IPPROTO_TCP].should include(proto)
     end
 
     it 'accepts a String as the socket type' do
-      Socket.getaddrinfo(nil, 'ftp', :INET, 'STREAM')[0].should == [
+      *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, 'STREAM')[0]
+      array.should == [
         'AF_INET',
         21,
         '127.0.0.1',
         '127.0.0.1',
         Socket::AF_INET,
         Socket::SOCK_STREAM,
-        ipproto_tcp
       ]
+      [0, Socket::IPPROTO_TCP].should include(proto)
     end
 
     it 'accepts an object responding to #to_str as the socket type' do
@@ -265,46 +263,45 @@ describe 'Socket.getaddrinfo' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/socket/socket/getaddrinfo_spec.rb#L263
 
       dummy.stub!(:to_str).and_return('STREAM')
 
-      Socket.getaddrinfo(nil, 'ftp', :INET, dummy)[0].should == [
+      *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, dummy)[0]
+      array.should == [
         'AF_INET',
         21,
         '127.0.0.1',
         '127.0.0.1',
         Socket::AF_INET,
         Socket::SOCK_STREAM,
-        ipproto_tcp
       ]
+      [0, Socket::IPPROTO_TCP].should include(proto)
     end
 
     platform_is_not :windows do
       it 'accepts a Fixnum as the protocol family' do
-        addr = Socket.getaddrinfo(nil, 'discard', :INET, :DGRAM, Socket::IPPROTO_UDP)
-
-        addr[0].should == [
+        *array, proto = Socket.getaddrinfo(nil, 'discard', :INET, :DGRAM, Socket::IPPROTO_UDP)[0]
+        array.should == [
           'AF_INET',
           9,
           '127.0.0.1',
           '127.0.0.1',
           Socket::AF_INET,
           Socket::SOCK_DGRAM,
-          Socket::IPPROTO_UDP
         ]
+        [0, Socket::IPPROTO_UDP].should include(proto)
       end
     end
 
     it 'accepts a Fixnum as the flags' do
-      addr = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
-                                Socket::IPPROTO_TCP, Socket::AI_PASSIVE)
-
-      addr[0].should == [
+      *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
+                                Socket::IPPROTO_TCP, Socket::AI_PASSIVE)[0]
+      array.should == [
         'AF_INET',
         21,
         '0.0.0.0',
         '0.0.0.0',
         Socket::AF_INET,
         Socket::SOCK_STREAM,
-        Socket::IPPROTO_TCP
       ]
+      [0, Socket::IPPROTO_TCP].should include(proto)
     end
 
     it 'performs a reverse lookup when the reverse_lookup argument is true' do
@@ -334,18 +331,17 @@ describe 'Socket.getaddrinfo' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/socket/socket/getaddrinfo_spec.rb#L331
     end
 
     it 'performs a reverse lookup when the reverse_lookup argument is :numeric' do
-      addr = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
+      *array, proto = Socket.getaddrinfo(nil, 'ftp', :INET, :STREAM,
                                 Socket::IPPROTO_TCP, 0, :numeric)[0]
-
-      addr.should == [
+      array.should == [
         'AF_INET',
         21,
         '127.0.0.1',
         '127.0.0.1',
         Socket::AF_INET,
         Socket::SOCK_STREAM,
-        Socket::IPPROTO_TCP
       ]
+      [0, Socket::IPPROTO_TCP].should include(proto)
     end
   end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]