From 55efe20df7f2cf594786e16e890382208a114f65 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 1 Mar 2011 16:36:44 -0800 Subject: tests: cleaner skipping for missing components --- test/ipv6_enabled.rb | 10 ++++++++++ test/rack_unicorn.rb | 12 ++++++++++++ test/test_linux_ipv6.rb | 12 ++---------- test/test_middleware_unicorn.rb | 11 +---------- test/test_middleware_unicorn_ipv6.rb | 24 +++--------------------- 5 files changed, 28 insertions(+), 41 deletions(-) create mode 100644 test/ipv6_enabled.rb create mode 100644 test/rack_unicorn.rb diff --git a/test/ipv6_enabled.rb b/test/ipv6_enabled.rb new file mode 100644 index 0000000..319fbef --- /dev/null +++ b/test/ipv6_enabled.rb @@ -0,0 +1,10 @@ +def ipv6_enabled? + tmp = TCPServer.new(ENV["TEST_HOST6"] || '::1', 0) + tmp.close + true + rescue => e + warn "skipping IPv6 tests, host does not seem to be IPv6 enabled:" + warn " #{e.class}: #{e}" + return false + ipv6_enabled = false +end diff --git a/test/rack_unicorn.rb b/test/rack_unicorn.rb new file mode 100644 index 0000000..779e8bf --- /dev/null +++ b/test/rack_unicorn.rb @@ -0,0 +1,12 @@ +# -*- encoding: binary -*- +require "test/unit" +require "raindrops" +require "rack" +require "rack/lobster" +require "open-uri" +begin + require "unicorn" + require "rack/lobster" +rescue LoadError => e + warn "W: #{e} skipping test since Rack or Unicorn was not found" +end diff --git a/test/test_linux_ipv6.rb b/test/test_linux_ipv6.rb index e2886ac..bd24cab 100644 --- a/test/test_linux_ipv6.rb +++ b/test/test_linux_ipv6.rb @@ -4,17 +4,9 @@ require 'tempfile' require 'raindrops' require 'socket' require 'pp' +require "./test/ipv6_enabled" $stderr.sync = $stdout.sync = true -begin - tmp = TCPServer.new(ENV["TEST_HOST6"] || '::1', 0) - ipv6_enabled = true -rescue => e - warn "skipping IPv6 tests, host does not seem to be IPv6 enabled:" - warn " #{e.class}: #{e}" - ipv6_enabled = false -end - class TestLinuxIPv6 < Test::Unit::TestCase include Raindrops::Linux @@ -158,4 +150,4 @@ class TestLinuxIPv6 < Test::Unit::TestCase statuses = Process.waitall statuses.each { |(pid,status)| assert status.success?, status.inspect } end if ENV["STRESS"].to_i != 0 -end if RUBY_PLATFORM =~ /linux/ && ipv6_enabled +end if RUBY_PLATFORM =~ /linux/ && ipv6_enabled? diff --git a/test/test_middleware_unicorn.rb b/test/test_middleware_unicorn.rb index cb73d3d..7949f78 100644 --- a/test/test_middleware_unicorn.rb +++ b/test/test_middleware_unicorn.rb @@ -1,14 +1,5 @@ # -*- encoding: binary -*- -require "test/unit" -require "raindrops" -require "rack" -require "rack/lobster" -require "open-uri" -begin - require "unicorn" -rescue => e - warn "W: #{e} skipping test since Unicorn was not found" -end +require "./test/rack_unicorn" $stderr.sync = $stdout.sync = true class TestMiddlewareUnicorn < Test::Unit::TestCase diff --git a/test/test_middleware_unicorn_ipv6.rb b/test/test_middleware_unicorn_ipv6.rb index 6f00cb1..edc9d85 100644 --- a/test/test_middleware_unicorn_ipv6.rb +++ b/test/test_middleware_unicorn_ipv6.rb @@ -1,23 +1,6 @@ # -*- encoding: binary -*- -require "test/unit" -require "raindrops" -require "rack" -require "rack/lobster" -require "open-uri" -begin - require "unicorn" -rescue => e - warn "W: #{e} skipping test since Unicorn was not found" -end - -begin - tmp = TCPServer.new(ENV["TEST_HOST6"] || '::1', 0) - ipv6_enabled = true -rescue => e - warn "skipping IPv6 tests, host does not seem to be IPv6 enabled:" - warn " #{e.class}: #{e}" - ipv6_enabled = false -end +require "./test/rack_unicorn" +require "./test/ipv6_enabled" $stderr.sync = $stdout.sync = true class TestMiddlewareUnicornIPv6 < Test::Unit::TestCase @@ -51,5 +34,4 @@ class TestMiddlewareUnicornIPv6 < Test::Unit::TestCase _, status = Process.waitpid2 @srv assert status.success? end -end if defined?(Unicorn) && RUBY_PLATFORM =~ /linux/ && ipv6_enabled - +end if defined?(Unicorn) && RUBY_PLATFORM =~ /linux/ && ipv6_enabled? -- cgit v1.2.3-24-ge0c7