diff --git a/Gemfile b/Gemfile index 539f7f95..62c5a654 100644 --- a/Gemfile +++ b/Gemfile @@ -5,9 +5,8 @@ gem "hoe-git" gem "hoe-ignore" gem "rdoc" gem "rake-compiler" -gem "test-unit", "~> 3.0" gem "rack", "< 3.0" -gem 'minitest', '~> 5.8' +gem "minitest", "~> 5.9" gem "jruby-openssl", :platform => "jruby" diff --git a/Rakefile b/Rakefile index 5f7d0b6a..fba46f34 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,4 @@ +require "bundler/setup" require "hoe" require "rake/extensiontask" require "rake/javaextensiontask" diff --git a/gemfiles/2.1-Gemfile b/gemfiles/2.1-Gemfile index db6e644f..a929221a 100644 --- a/gemfiles/2.1-Gemfile +++ b/gemfiles/2.1-Gemfile @@ -5,9 +5,8 @@ gem "hoe-git" gem "hoe-ignore" gem "rdoc" gem "rake-compiler" -gem "test-unit", "~> 3.0" gem "rack", "~> 1.6" -gem 'minitest', '~> 5.8' +gem "minitest", '~> 5.9' gem "jruby-openssl", :platform => "jruby" diff --git a/test/test_app_status.rb b/test/test_app_status.rb index 28dae324..c98ae6ce 100644 --- a/test/test_app_status.rb +++ b/test/test_app_status.rb @@ -1,8 +1,9 @@ -require 'test/unit' -require 'rack' -require 'puma/app/status' +require "test_helper" -class TestAppStatus < Test::Unit::TestCase +require "puma/app/status" +require "rack" + +class TestAppStatus < Minitest::Test class FakeServer def initialize @status = :running diff --git a/test/test_binder.rb b/test/test_binder.rb index 83548cb1..a9734d4c 100644 --- a/test/test_binder.rb +++ b/test/test_binder.rb @@ -1,11 +1,10 @@ -require "rbconfig" -require 'test/unit' -require 'testhelp' +require "test_helper" -require 'puma/binder' -require 'puma/events' +require "puma/binder" +require "puma/events" +require "puma/puma_http11" -class TestBinder < Test::Unit::TestCase +class TestBinder < Minitest::Test def setup @events = Puma::Events.new(STDOUT, STDERR) @@ -13,7 +12,7 @@ class TestBinder < Test::Unit::TestCase end def test_localhost_addresses_dont_alter_listeners_for_tcp_addresses - omit_on_jruby + skip_on_jruby @binder.parse(["tcp://localhost:10001"], @events) @@ -21,7 +20,7 @@ class TestBinder < Test::Unit::TestCase end def test_localhost_addresses_dont_alter_listeners_for_ssl_addresses - omit_on_jruby + skip_on_jruby key = File.expand_path "../../examples/puma/puma_keypair.pem", __FILE__ cert = File.expand_path "../../examples/puma/cert_puma.pem", __FILE__ diff --git a/test/test_cli.rb b/test/test_cli.rb index 603f85d3..94c21705 100644 --- a/test/test_cli.rb +++ b/test/test_cli.rb @@ -1,10 +1,8 @@ -require "rbconfig" -require 'test/unit' -require 'puma/cli' -require 'tempfile' -require 'yaml' +require "test_helper" -class TestCLI < Test::Unit::TestCase +require "puma/cli" + +class TestCLI < Minitest::Test def setup @environment = 'production' @tmp_file = Tempfile.new("puma-test") @@ -168,10 +166,7 @@ class TestCLI < Test::Unit::TestCase "--state", @tmp_path ] cli.launcher.write_state - data = nil - assert_nothing_raised do - data = YAML.load_file( @tmp_path ) - end + data = YAML.load_file(@tmp_path) keys_not_stripped = data.keys & Puma::CLI::KEYS_NOT_TO_PERSIST_IN_STATE assert_empty keys_not_stripped diff --git a/test/test_config.rb b/test/test_config.rb index bff985b4..2290ebb4 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -1,9 +1,8 @@ -require 'test/unit' +require "test_helper" -require 'puma' -require 'puma/configuration' +require "puma/configuration" -class TestConfigFile < Test::Unit::TestCase +class TestConfigFile < Minitest::Test def test_app_from_rackup conf = Puma::Configuration.new do |c| c.rackup "test/hello-bind.ru" diff --git a/test/testhelp.rb b/test/test_helper.rb similarity index 65% rename from test/testhelp.rb rename to test/test_helper.rb index 862c507e..e5835374 100644 --- a/test/testhelp.rb +++ b/test/test_helper.rb @@ -1,20 +1,17 @@ # Copyright (c) 2011 Evan Phoenix # Copyright (c) 2005 Zed A. Shaw -require 'rubygems' -require 'test/unit' -require 'net/http' -require 'digest/sha1' -require 'uri' -require 'stringio' - -require 'puma' -require 'puma/detect' +require "bundler/setup" +require "minitest/autorun" +require "minitest/pride" +require "puma" +require "puma/detect" # Either takes a string to do a get request against, or a tuple of [URI, HTTP] where # HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.) def hit(uris) results = [] + uris.each do |u| res = nil @@ -33,7 +30,7 @@ def hit(uris) end module TimeoutEveryTestCase - def run(*args) + def run(*) if !!ENV['CI'] Timeout.timeout(60) { super } else @@ -41,11 +38,13 @@ module TimeoutEveryTestCase end end end -Test::Unit::TestCase.prepend TimeoutEveryTestCase -module OmitTestsBasedOnRubyEngine - def omit_on_jruby - omit "Omitted on JRuby" if Puma.jruby? +Minitest::Test.prepend TimeoutEveryTestCase + +module SkipTestsBasedOnRubyEngine + def skip_on_jruby + skip "Skipped on JRuby" if Puma.jruby? end end -Test::Unit::TestCase.prepend OmitTestsBasedOnRubyEngine + +Minitest::Test.include SkipTestsBasedOnRubyEngine diff --git a/test/test_http10.rb b/test/test_http10.rb index d8ffa668..6b13f18c 100644 --- a/test/test_http10.rb +++ b/test/test_http10.rb @@ -1,10 +1,10 @@ -require 'testhelp' +require "test_helper" -class Http10ParserTest < Test::Unit::TestCase - include Puma +require "puma/puma_http11" +class Http10ParserTest < Minitest::Test def test_parse_simple - parser = HttpParser.new + parser = Puma::HttpParser.new req = {} http = "GET / HTTP/1.0\r\n\r\n" nread = parser.execute(req, http, 0) @@ -17,10 +17,10 @@ class Http10ParserTest < Test::Unit::TestCase assert_equal '/', req['REQUEST_PATH'] assert_equal 'HTTP/1.0', req['HTTP_VERSION'] assert_equal '/', req['REQUEST_URI'] - assert_equal 'GET', req['REQUEST_METHOD'] + assert_equal 'GET', req['REQUEST_METHOD'] assert_nil req['FRAGMENT'] assert_nil req['QUERY_STRING'] - + parser.reset assert parser.nread == 0, "Number read after reset should be 0" end diff --git a/test/test_http11.rb b/test/test_http11.rb index bd203f0c..a5bf56b8 100644 --- a/test/test_http11.rb +++ b/test/test_http11.rb @@ -1,14 +1,14 @@ # Copyright (c) 2011 Evan Phoenix # Copyright (c) 2005 Zed A. Shaw -require 'testhelp' +require "test_helper" -include Puma +require "puma/puma_http11" -class Http11ParserTest < Test::Unit::TestCase +class Http11ParserTest < Minitest::Test def test_parse_simple - parser = HttpParser.new + parser = Puma::HttpParser.new req = {} http = "GET /?a=1 HTTP/1.1\r\n\r\n" nread = parser.execute(req, http, 0) @@ -30,7 +30,7 @@ class Http11ParserTest < Test::Unit::TestCase end def test_parse_escaping_in_query - parser = HttpParser.new + parser = Puma::HttpParser.new req = {} http = "GET /admin/users?search=%27%%27 HTTP/1.1\r\n\r\n" nread = parser.execute(req, http, 0) @@ -48,7 +48,7 @@ class Http11ParserTest < Test::Unit::TestCase end def test_parse_absolute_uri - parser = HttpParser.new + parser = Puma::HttpParser.new req = {} http = "GET http://192.168.1.96:3000/api/v1/matches/test?1=1 HTTP/1.1\r\n\r\n" nread = parser.execute(req, http, 0) @@ -72,7 +72,7 @@ class Http11ParserTest < Test::Unit::TestCase end def test_parse_dumbfuck_headers - parser = HttpParser.new + parser = Puma::HttpParser.new req = {} should_be_good = "GET / HTTP/1.1\r\naaaaaaaaaaaaa:++++++++++\r\n\r\n" nread = parser.execute(req, should_be_good, 0) @@ -82,7 +82,7 @@ class Http11ParserTest < Test::Unit::TestCase end def test_parse_error - parser = HttpParser.new + parser = Puma::HttpParser.new req = {} bad_http = "GET / SsUTF/1.1" @@ -99,12 +99,12 @@ class Http11ParserTest < Test::Unit::TestCase end def test_fragment_in_uri - parser = HttpParser.new + parser = Puma::HttpParser.new req = {} get = "GET /forums/1/topics/2375?page=1#posts-17408 HTTP/1.1\r\n\r\n" - assert_nothing_raised do - parser.execute(req, get, 0) - end + + parser.execute(req, get, 0) + assert parser.finished? assert_equal '/forums/1/topics/2375?page=1', req['REQUEST_URI'] assert_equal 'posts-17408', req['FRAGMENT'] @@ -125,7 +125,7 @@ class Http11ParserTest < Test::Unit::TestCase end def test_max_uri_path_length - parser = HttpParser.new + parser = Puma::HttpParser.new req = {} # Support URI path length to a max of 2048 @@ -145,7 +145,7 @@ class Http11ParserTest < Test::Unit::TestCase end def test_horrible_queries - parser = HttpParser.new + parser = Puma::HttpParser.new # then that large header names are caught 10.times do |c| diff --git a/test/test_integration.rb b/test/test_integration.rb index 14d5cc65..ec062069 100644 --- a/test/test_integration.rb +++ b/test/test_integration.rb @@ -1,17 +1,11 @@ -require "rbconfig" -require 'test/unit' -require 'socket' -require 'timeout' -require 'net/http' -require 'tempfile' +require "test_helper" -require 'puma/cli' -require 'puma/control_cli' -require 'puma/detect' +require "puma/cli" +require "puma/control_cli" # These don't run on travis because they're too fragile -class TestIntegration < Test::Unit::TestCase +class TestIntegration < Minitest::Test def setup @state_path = "test/test_puma.state" @bind_path = "test/test_server.sock" @@ -116,7 +110,8 @@ class TestIntegration < Test::Unit::TestCase end def test_phased_restart_via_pumactl - omit("Too finicky, fails 50% of the time on CI.") + skip("Too finicky, fails 50% of the time on CI.") + if Puma.jruby? || Puma.windows? assert true return diff --git a/test/test_iobuffer.rb b/test/test_iobuffer.rb index 6e3e29c9..95d39ac2 100644 --- a/test/test_iobuffer.rb +++ b/test/test_iobuffer.rb @@ -1,7 +1,8 @@ -require 'puma/io_buffer' -require 'test/unit' +require "test_helper" -class TestIOBuffer < Test::Unit::TestCase +require "puma/io_buffer" + +class TestIOBuffer < Minitest::Test attr_accessor :iobuf def setup self.iobuf = Puma::IOBuffer.new @@ -13,7 +14,7 @@ class TestIOBuffer < Test::Unit::TestCase end def test_append_op - iobuf << "abc" + iobuf << "abc" assert_equal "abc", iobuf.to_s iobuf << "123" assert_equal "abc123", iobuf.to_s diff --git a/test/test_minissl.rb b/test/test_minissl.rb index aeba9317..80acb401 100644 --- a/test/test_minissl.rb +++ b/test/test_minissl.rb @@ -1,28 +1,28 @@ -require 'test/unit' -require 'puma' -require 'puma/minissl' +require "test_helper" -class TestMiniSSL < Test::Unit::TestCase +require "puma/minissl" + +class TestMiniSSL < Minitest::Test if defined?(JRUBY_VERSION) def test_raises_with_invalid_keystore_file ctx = Puma::MiniSSL::Context.new - exception = assert_raise(ArgumentError) { ctx.keystore = "/no/such/keystore" } + exception = assert_raises(ArgumentError) { ctx.keystore = "/no/such/keystore" } assert_equal("No such keystore file '/no/such/keystore'", exception.message) end else def test_raises_with_invalid_key_file ctx = Puma::MiniSSL::Context.new - exception = assert_raise(ArgumentError) { ctx.key = "/no/such/key" } + exception = assert_raises(ArgumentError) { ctx.key = "/no/such/key" } assert_equal("No such key file '/no/such/key'", exception.message) end def test_raises_with_invalid_cert_file ctx = Puma::MiniSSL::Context.new - exception = assert_raise(ArgumentError) { ctx.cert = "/no/such/cert" } + exception = assert_raises(ArgumentError) { ctx.cert = "/no/such/cert" } assert_equal("No such cert file '/no/such/cert'", exception.message) end end diff --git a/test/test_null_io.rb b/test/test_null_io.rb index 69f046be..c554dfbf 100644 --- a/test/test_null_io.rb +++ b/test/test_null_io.rb @@ -1,7 +1,8 @@ -require 'puma/null_io' -require 'test/unit' +require "test_helper" -class TestNullIO < Test::Unit::TestCase +require "puma/null_io" + +class TestNullIO < Minitest::Test attr_accessor :nio def setup self.nio = Puma::NullIO.new diff --git a/test/test_persistent.rb b/test/test_persistent.rb index 4aadd10b..2924106b 100644 --- a/test/test_persistent.rb +++ b/test/test_persistent.rb @@ -1,8 +1,6 @@ -require 'puma' -require 'test/unit' -require 'timeout' +require "test_helper" -class TestPersistent < Test::Unit::TestCase +class TestPersistent < Minitest::Test def setup @valid_request = "GET / HTTP/1.1\r\nHost: test.com\r\nContent-Type: text/plain\r\n\r\n" @close_request = "GET / HTTP/1.1\r\nHost: test.com\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\n" diff --git a/test/test_puma_server.rb b/test/test_puma_server.rb index b69b1bbd..af5375d6 100644 --- a/test/test_puma_server.rb +++ b/test/test_puma_server.rb @@ -1,14 +1,6 @@ -require "rbconfig" -require 'test/unit' -require 'socket' -require 'openssl' +require "test_helper" -require 'puma/minissl' -require 'puma/server' - -require 'net/https' - -class TestPumaServer < Test::Unit::TestCase +class TestPumaServer < Minitest::Test def setup @port = 0 @@ -195,7 +187,7 @@ class TestPumaServer < Test::Unit::TestCase data = sock.read - assert_not_match(/don't leak me bro/, data) + refute_match(/don't leak me bro/, data) assert_match(/HTTP\/1.0 500 Internal Server Error/, data) end @@ -304,7 +296,8 @@ class TestPumaServer < Test::Unit::TestCase end def test_timeout_in_data_phase - omit("Hangs too often, TODO: fix") + skip("Hangs too often, TODO: fix") + @server.first_data_timeout = 2 @server.add_tcp_listener @host, @port @server.run diff --git a/test/test_puma_server_ssl.rb b/test/test_puma_server_ssl.rb index 768aab2c..ad32cfe6 100644 --- a/test/test_puma_server_ssl.rb +++ b/test/test_puma_server_ssl.rb @@ -1,12 +1,6 @@ -require "rbconfig" -require 'test/unit' -require 'socket' -require 'openssl' +require "test_helper" -require 'puma/minissl' -require 'puma/server' - -require 'net/https' +require "puma/events" class SSLEventsHelper < ::Puma::Events attr_accessor :addr, :cert, :error @@ -26,7 +20,7 @@ DISABLE_SSL = begin false end -class TestPumaServerSSL < Test::Unit::TestCase +class TestPumaServerSSL < Minitest::Test def setup return if DISABLE_SSL @@ -130,7 +124,7 @@ class TestPumaServerSSL < Test::Unit::TestCase end # client-side TLS authentication tests -class TestPumaServerSSLClient < Test::Unit::TestCase +class TestPumaServerSSLClient < Minitest::Test def assert_ssl_client_error_match(error, subject=nil, &blk) @port = 3212 diff --git a/test/test_rack_handler.rb b/test/test_rack_handler.rb index bf6c21f7..dd51111d 100644 --- a/test/test_rack_handler.rb +++ b/test/test_rack_handler.rb @@ -1,9 +1,8 @@ -require 'test/unit' -require 'testhelp' -require 'puma' -require 'rack/handler/puma' +require "test_helper" -class TestPumaUnixSocket < Test::Unit::TestCase +require "rack/handler/puma" + +class TestPumaUnixSocket < Minitest::Test def test_handler handler = Rack::Handler.get(:puma) assert_equal Rack::Handler::Puma, handler @@ -12,7 +11,7 @@ class TestPumaUnixSocket < Test::Unit::TestCase end end -class TestPathHandler < Test::Unit::TestCase +class TestPathHandler < Minitest::Test def app Proc.new {|env| @input = env; [200, {}, ["hello world"]]} end diff --git a/test/test_rack_server.rb b/test/test_rack_server.rb index a1a66166..53a0c989 100644 --- a/test/test_rack_server.rb +++ b/test/test_rack_server.rb @@ -1,10 +1,8 @@ -require 'test/unit' -require 'puma' -require 'rack/lint' -require 'testhelp' -require 'puma/commonlogger' +require "test_helper" -class TestRackServer < Test::Unit::TestCase +require "rack" + +class TestRackServer < Minitest::Test class ErrorChecker def initialize(app) diff --git a/test/test_tcp_logger.rb b/test/test_tcp_logger.rb index eeb2d116..560d1b6a 100644 --- a/test/test_tcp_logger.rb +++ b/test/test_tcp_logger.rb @@ -1,10 +1,7 @@ -require 'minitest/autorun' -require 'minitest/assertions' +require "test_helper" -require 'puma/tcp_logger' -require 'socket' -require 'puma/server' -require 'puma/events' +require "puma/events" +require "puma/tcp_logger" class TestTCPLogger < Minitest::Test diff --git a/test/test_tcp_rack.rb b/test/test_tcp_rack.rb index 02724f3d..1aa10f9c 100644 --- a/test/test_tcp_rack.rb +++ b/test/test_tcp_rack.rb @@ -1,14 +1,8 @@ -require "rbconfig" -require 'test/unit' -require 'socket' -require 'openssl' +require "test_helper" -require 'puma/minissl' -require 'puma/server' +require "puma/events" -require 'net/https' - -class TestTCPRack < Test::Unit::TestCase +class TestTCPRack < Minitest::Test def setup @port = 3212 diff --git a/test/test_thread_pool.rb b/test/test_thread_pool.rb index 6dfe854a..e8ea7bbf 100644 --- a/test/test_thread_pool.rb +++ b/test/test_thread_pool.rb @@ -1,8 +1,8 @@ -require 'test/unit' +require "test_helper" -require 'puma/thread_pool' +require "puma/thread_pool" -class TestThreadPool < Test::Unit::TestCase +class TestThreadPool < Minitest::Test def teardown @pool.shutdown if @pool diff --git a/test/test_unix_socket.rb b/test/test_unix_socket.rb index 3c64e60c..e9de3608 100644 --- a/test/test_unix_socket.rb +++ b/test/test_unix_socket.rb @@ -1,13 +1,9 @@ -require "rbconfig" -require 'test/unit' -require 'puma/server' - -require 'socket' +require "test_helper" # UNIX sockets are not recommended on JRuby # (or Windows) unless defined?(JRUBY_VERSION) || RbConfig::CONFIG["host_os"] =~ /mingw|mswin/ - class TestPumaUnixSocket < Test::Unit::TestCase + class TestPumaUnixSocket < Minitest::Test App = lambda { |env| [200, {}, ["Works"]] } diff --git a/test/test_ws.rb b/test/test_web_server.rb similarity index 93% rename from test/test_ws.rb rename to test/test_web_server.rb index 1b0820de..8e98deb7 100644 --- a/test/test_ws.rb +++ b/test/test_web_server.rb @@ -1,9 +1,9 @@ # Copyright (c) 2011 Evan Phoenix # Copyright (c) 2005 Zed A. Shaw -require 'testhelp' +require "test_helper" -include Puma +require "puma/server" class TestHandler attr_reader :ran_test @@ -15,14 +15,14 @@ class TestHandler end end -class WebServerTest < Test::Unit::TestCase +class WebServerTest < Minitest::Test def setup @valid_request = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\n\r\n" @tester = TestHandler.new - @server = Server.new @tester, Events.strings + @server = Puma::Server.new @tester, Puma::Events.strings @server.add_tcp_listener "127.0.0.1", 0 @server.run @@ -86,4 +86,3 @@ class WebServerTest < Test::Unit::TestCase end end -