diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-13 05:18:49 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-13 05:18:49 +0000 |
commit | 54ad3167e8b34af03c3382174ec21e00124d6b4d (patch) | |
tree | ecc753002cf6dc817b5b241b11b1c164bbcc222b | |
parent | d7c806c079bbc3f62476f751ba932732092b8f46 (diff) |
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
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | spec/ruby/library/socket/basicsocket/setsockopt_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/library/socket/fixtures/classes.rb | 2 | ||||
-rw-r--r-- | spec/ruby/library/socket/socket/ipv6only_bang_spec.rb | 22 | ||||
-rw-r--r-- | test/socket/test_udp.rb | 10 |
4 files changed, 29 insertions, 21 deletions
diff --git a/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb b/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb index cafcfc202a..1471b03798 100644 --- a/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb +++ b/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb @@ -237,13 +237,15 @@ describe 'BasicSocket#setsockopt' do @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 diff --git a/spec/ruby/library/socket/fixtures/classes.rb b/spec/ruby/library/socket/fixtures/classes.rb index 8167b879fd..b73fd0fa4c 100644 --- a/spec/ruby/library/socket/fixtures/classes.rb +++ b/spec/ruby/library/socket/fixtures/classes.rb @@ -50,7 +50,7 @@ module SocketSpecs 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 diff --git a/spec/ruby/library/socket/socket/ipv6only_bang_spec.rb b/spec/ruby/library/socket/socket/ipv6only_bang_spec.rb index 73f3ce1642..5f7db7bf7e 100644 --- a/spec/ruby/library/socket/socket/ipv6only_bang_spec.rb +++ b/spec/ruby/library/socket/socket/ipv6only_bang_spec.rb @@ -1,17 +1,19 @@ 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 diff --git a/test/socket/test_udp.rb b/test/socket/test_udp.rb index bec2181918..f060b65f2c 100644 --- a/test/socket/test_udp.rb +++ b/test/socket/test_udp.rb @@ -20,9 +20,13 @@ class TestSocket_UDPSocket < Test::Unit::TestCase 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 |