ruby-changes:52843
From: normal <ko1@a...>
Date: Sat, 13 Oct 2018 14:18:55 +0900 (JST)
Subject: [ruby-changes:52843] normal:r65055 (trunk): tests: support Linux kernels with CONFIG_IPV6=n
normal 2018-10-13 14:18:49 +0900 (Sat, 13 Oct 2018) New Revision: 65055 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65055 Log: tests: support Linux kernels with CONFIG_IPV6=n Detecting the presence of constants in C headers is insufficient, as a Linux kernel can be built with CONFIG_IPV6=n Modified files: trunk/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb trunk/spec/ruby/library/socket/fixtures/classes.rb trunk/spec/ruby/library/socket/socket/ipv6only_bang_spec.rb trunk/test/socket/test_udp.rb Index: spec/ruby/library/socket/socket/ipv6only_bang_spec.rb =================================================================== --- spec/ruby/library/socket/socket/ipv6only_bang_spec.rb (revision 65054) +++ spec/ruby/library/socket/socket/ipv6only_bang_spec.rb (revision 65055) @@ -1,17 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/socket/socket/ipv6only_bang_spec.rb#L1 require_relative '../spec_helper' -describe 'Socket#ipv6only!' do - before do - @socket = Socket.new(:INET6, :DGRAM) - end +guard -> { SocketSpecs.ipv6_available? } do + describe 'Socket#ipv6only!' do + before do + @socket = Socket.new(:INET6, :DGRAM) + end - after do - @socket.close - end + after do + @socket.close + end - it 'enables IPv6 only mode' do - @socket.ipv6only! + it 'enables IPv6 only mode' do + @socket.ipv6only! - @socket.getsockopt(:IPV6, :V6ONLY).bool.should == true + @socket.getsockopt(:IPV6, :V6ONLY).bool.should == true + end end end Index: spec/ruby/library/socket/fixtures/classes.rb =================================================================== --- spec/ruby/library/socket/fixtures/classes.rb (revision 65054) +++ spec/ruby/library/socket/fixtures/classes.rb (revision 65055) @@ -50,7 +50,7 @@ module SocketSpecs https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/socket/fixtures/classes.rb#L50 def self.ipv6_available? @ipv6_available ||= begin server = TCPServer.new('::1', 0) - rescue Errno::EADDRNOTAVAIL, SocketError + rescue Errno::EAFNOSUPPORT, Errno::EADDRNOTAVAIL, SocketError :no else server.close Index: spec/ruby/library/socket/basicsocket/setsockopt_spec.rb =================================================================== --- spec/ruby/library/socket/basicsocket/setsockopt_spec.rb (revision 65054) +++ spec/ruby/library/socket/basicsocket/setsockopt_spec.rb (revision 65055) @@ -237,13 +237,15 @@ describe 'BasicSocket#setsockopt' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb#L237 @socket.getsockopt(:IP, :TTL).int.should == 255 end - it 'sets an IPv6 boolean option' do - socket = Socket.new(:INET6, :STREAM) - begin - socket.setsockopt(:IPV6, :V6ONLY, true).should == 0 - socket.getsockopt(:IPV6, :V6ONLY).bool.should == true - ensure - socket.close + guard -> { SocketSpecs.ipv6_available? } do + it 'sets an IPv6 boolean option' do + socket = Socket.new(:INET6, :STREAM) + begin + socket.setsockopt(:IPV6, :V6ONLY, true).should == 0 + socket.getsockopt(:IPV6, :V6ONLY).bool.should == true + ensure + socket.close + end end end Index: test/socket/test_udp.rb =================================================================== --- test/socket/test_udp.rb (revision 65054) +++ test/socket/test_udp.rb (revision 65055) @@ -20,9 +20,13 @@ class TestSocket_UDPSocket < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/socket/test_udp.rb#L20 assert_match(/AF_INET\b/, sock.inspect) } if Socket.const_defined?(:AF_INET6) - UDPSocket.open(Socket::AF_INET6) {|sock| - assert_match(/AF_INET6\b/, sock.inspect) - } + begin + UDPSocket.open(Socket::AF_INET6) {|sock| + assert_match(/AF_INET6\b/, sock.inspect) + } + rescue Errno::EAFNOSUPPORT + skip 'AF_INET6 not supported by kernel' + end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/