Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Minitest instead of Test::Unit #1152

Merged
merged 31 commits into from Nov 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d344e38
Bump minitest version.
Nov 21, 2016
327de0a
Add basic test helper file.
Nov 21, 2016
4a83fd6
Use minitest for web server tests.
Nov 21, 2016
d0795d4
Use Minitest for unix socket tests.
Nov 21, 2016
1412b05
Use Minitest for ThreadPool tests.
Nov 21, 2016
4312bbe
Use Minitest for TCP-Rack tests
Nov 21, 2016
bfcae91
Use Minitest for TCPLogger tests.
Nov 21, 2016
ea6229f
Add missing helper to test helpers.
Nov 21, 2016
4a53934
Use Minitest for Rack server tests.
Nov 21, 2016
16bb48c
Use Minitest for Rack handler tests.
Nov 21, 2016
a49fdf5
Use Minitest for Puma::Server tests.
Nov 21, 2016
f0672a5
Use Minitest for Puma::Server with SSL tests.
Nov 21, 2016
1d83e89
Use Minitest for persisten connections tests.
Nov 21, 2016
a4fd729
Require puma in test_helper file.
Nov 21, 2016
706c61f
Use minitest for Puma::NullIO tests.
Nov 21, 2016
0f15a5d
Remove unnecessary requires on test files.
Nov 21, 2016
f1e37b1
Use Minitest for MiniSSL tests.
Nov 21, 2016
a6b5cbf
Use Minitest for IOBuffer tests.
Nov 21, 2016
4718ab6
Require bundler/setup in Rakefile.
Nov 21, 2016
86fd737
Use Minitest for HttpParser tests.
Nov 21, 2016
ea9cd95
Use Minitest for Puma::Configuration tests.
Nov 21, 2016
caf5f6b
Use Minitest for Puma::CLI tests.
Nov 21, 2016
a841738
Bump Minitest version for Ruby 2.1 Gemfile.
Nov 21, 2016
1b1a0d2
Use Minitest for integration tests.
Nov 21, 2016
b9cec94
Use Minitest for Puma::App::Status tests.
Nov 21, 2016
9e7a418
Remove test-unit from Gemfiles.
Nov 21, 2016
732bc11
Add timeout helper to Minitest::Test.
Nov 21, 2016
67cc768
Use Minitest for Puma::Binder tests.
Nov 21, 2016
66d55b3
Remove testhelp file.
Nov 21, 2016
bbf2a03
Add missing require to Puma::Binder tests.
Nov 21, 2016
8a9ff72
Prefer require instead of require_relative.
Nov 22, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions Gemfile
Expand Up @@ -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"
1 change: 1 addition & 0 deletions Rakefile
@@ -1,3 +1,4 @@
require "bundler/setup"
require "hoe"
require "rake/extensiontask"
require "rake/javaextensiontask"
Expand Down
3 changes: 1 addition & 2 deletions gemfiles/2.1-Gemfile
Expand Up @@ -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"
9 changes: 5 additions & 4 deletions 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
Expand Down
15 changes: 7 additions & 8 deletions test/test_binder.rb
@@ -1,27 +1,26 @@
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)
@binder = Puma::Binder.new(@events)
end

def test_localhost_addresses_dont_alter_listeners_for_tcp_addresses
omit_on_jruby
skip_on_jruby

@binder.parse(["tcp://localhost:10001"], @events)

assert_equal [], @binder.listeners
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__
Expand Down
15 changes: 5 additions & 10 deletions 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")
Expand Down Expand Up @@ -168,10 +166,7 @@ def test_state_file_callback_filtering
"--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
Expand Down
7 changes: 3 additions & 4 deletions 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"
Expand Down
29 changes: 14 additions & 15 deletions test/testhelp.rb → 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

Expand All @@ -33,19 +30,21 @@ def hit(uris)
end

module TimeoutEveryTestCase
def run(*args)
def run(*)
if !!ENV['CI']
Timeout.timeout(60) { super }
else
super
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
12 changes: 6 additions & 6 deletions 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)
Expand All @@ -17,10 +17,10 @@ def test_parse_simple
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
Expand Down
28 changes: 14 additions & 14 deletions 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)
Expand All @@ -30,7 +30,7 @@ def test_parse_simple
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)
Expand All @@ -48,7 +48,7 @@ def test_parse_escaping_in_query
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)
Expand All @@ -72,7 +72,7 @@ def test_parse_absolute_uri
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)
Expand All @@ -82,7 +82,7 @@ def test_parse_dumbfuck_headers
end

def test_parse_error
parser = HttpParser.new
parser = Puma::HttpParser.new
req = {}
bad_http = "GET / SsUTF/1.1"

Expand All @@ -99,12 +99,12 @@ def test_parse_error
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']
Expand All @@ -125,7 +125,7 @@ def rand_data(min, max, readable=true)
end

def test_max_uri_path_length
parser = HttpParser.new
parser = Puma::HttpParser.new
req = {}

# Support URI path length to a max of 2048
Expand All @@ -145,7 +145,7 @@ def test_max_uri_path_length
end

def test_horrible_queries
parser = HttpParser.new
parser = Puma::HttpParser.new

# then that large header names are caught
10.times do |c|
Expand Down
17 changes: 6 additions & 11 deletions 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"
Expand Down Expand Up @@ -116,7 +110,8 @@ def test_stop_via_pumactl
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
Expand Down
9 changes: 5 additions & 4 deletions 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
Expand All @@ -13,7 +14,7 @@ def test_initial_size
end

def test_append_op
iobuf << "abc"
iobuf << "abc"
assert_equal "abc", iobuf.to_s
iobuf << "123"
assert_equal "abc123", iobuf.to_s
Expand Down
14 changes: 7 additions & 7 deletions 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
Expand Down
7 changes: 4 additions & 3 deletions 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
Expand Down