Skip to content
This repository was archived by the owner on Mar 15, 2022. It is now read-only.

Commit 3ed52e0

Browse files
committed
tests: switch to minitest
Ruby 1.9+ uses Minitest as the backend for Test::Unit. As of Minitest 5, the shim no longer supports Test::Unit::TestCase. Adjust the thread_safe test suite to support Minitest 5's syntax. Minitest versions 4 and below do not support the newer Minitest::Test class that arrived in version 5. For that case, use the MiniTest::Unit::TestCase class as a fallback. Also add a backwards-compatible function to Minitest::Test for assert_nothing_raised, since Minitest doesn't support that assertion. Eventually the use of assert_nothing_raised in thread_safe ought to be removed in favor of something better (such as more specific asserts).
1 parent 33114e7 commit 3ed52e0

File tree

7 files changed

+33
-16
lines changed

7 files changed

+33
-16
lines changed

test/test_array.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
require 'test/unit'
21
require 'thread_safe'
2+
require File.join(File.dirname(__FILE__), "test_helper")
33

4-
class TestArray < Test::Unit::TestCase
4+
class TestArray < Minitest::Test
55
def test_concurrency
66
ary = ThreadSafe::Array.new
77
assert_nothing_raised do

test/test_cache.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
require 'test/unit'
21
require 'thread_safe'
32
require 'thread'
43
require File.join(File.dirname(__FILE__), "test_helper")
54

65
Thread.abort_on_exception = true
76

8-
class TestCache < Test::Unit::TestCase
7+
class TestCache < Minitest::Test
98
def setup
109
@cache = ThreadSafe::Cache.new
1110
end
@@ -470,7 +469,7 @@ def test_fetch
470469
assert_equal(1, (@cache.fetch(:a) {flunk}))
471470
end
472471

473-
assert_raise(ThreadSafe::Cache::KEY_ERROR) do
472+
assert_raises(ThreadSafe::Cache::KEY_ERROR) do
474473
@cache.fetch(:b)
475474
end
476475
end
@@ -704,7 +703,7 @@ def test_dup_clone
704703
end
705704

706705
def test_is_unfreezable
707-
assert_raise(NoMethodError) { @cache.freeze }
706+
assert_raises(NoMethodError) { @cache.freeze }
708707
end
709708

710709
def test_marshal_dump_load
@@ -719,7 +718,7 @@ def test_marshal_dump_load
719718
end
720719

721720
def test_marshal_dump_doesnt_work_with_default_proc
722-
assert_raise(TypeError) do
721+
assert_raises(TypeError) do
723722
Marshal.dump(ThreadSafe::Cache.new {})
724723
end
725724
end
@@ -748,7 +747,7 @@ def assert_invalid_option(option_name, value)
748747
end
749748

750749
def assert_invalid_options(options)
751-
assert_raise(ArgumentError) { ThreadSafe::Cache.new(options) }
750+
assert_raises(ArgumentError) { ThreadSafe::Cache.new(options) }
752751
end
753752

754753
def assert_size_change(change, cache = @cache)
@@ -782,7 +781,7 @@ def assert_handles_exception(method, key, *args)
782781
before_had_value = before_had_key ? @cache[key] : nil
783782

784783
assert_no_size_change do
785-
assert_raise(TestException) do
784+
assert_raises(TestException) do
786785
@cache.send(method, key, *args) { raise TestException, '' }
787786
end
788787
assert_equal before_had_key, @cache.key?(key)

test/test_cache_loops.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
require 'thread'
2-
require 'test/unit'
32
require 'thread_safe'
43
require File.join(File.dirname(__FILE__), "test_helper")
54

65
Thread.abort_on_exception = true
76

8-
class TestCacheTorture < Test::Unit::TestCase # this is not run unless RUBY_VERSION =~ /1\.8/ || ENV['TRAVIS'] (see the end of the file)
7+
class TestCacheTorture < Minitest::Test # this is not run unless RUBY_VERSION =~ /1\.8/ || ENV['TRAVIS'] (see the end of the file)
98
THREAD_COUNT = 40
109
KEY_COUNT = (((2**13) - 2) * 0.75).to_i # get close to the doubling cliff
1110
LOW_KEY_COUNT = (((2**8 ) - 2) * 0.75).to_i # get close to the doubling cliff

test/test_hash.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
require 'test/unit'
21
require 'thread_safe'
2+
require File.join(File.dirname(__FILE__), "test_helper")
33

4-
class TestHash < Test::Unit::TestCase
4+
class TestHash < Minitest::Test
55
def test_concurrency
66
hsh = ThreadSafe::Hash.new
77
assert_nothing_raised do

test/test_helper.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
require 'thread'
2+
require 'minitest/autorun'
3+
4+
if Minitest.const_defined?('Test')
5+
# We're on Minitest 5+. Nothing to do here.
6+
else
7+
# Minitest 4 doesn't have Minitest::Test yet.
8+
Minitest::Test = MiniTest::Unit::TestCase
9+
end
10+
11+
# Minitest does not support assert_nothing_raised.
12+
# Eventually we should remove our use of this assert_nothing_raised function
13+
# for more specific asserts. In the mean time, add a backwards-compatible
14+
# implementation of assert_nothing_raised.
15+
class MiniTest::Test
16+
def assert_nothing_raised(&block)
17+
block.call
18+
end
19+
end
220

321
if defined?(JRUBY_VERSION) && ENV['TEST_NO_UNSAFE']
422
# to be used like this: rake test TEST_NO_UNSAFE=true
@@ -10,7 +28,7 @@
1028
manager.deny java.lang.RuntimePermission.new("accessClassInPackage.sun.misc")
1129
java.lang.System.setSecurityManager manager
1230

13-
class TestNoUnsafe < Test::Unit::TestCase
31+
class TestNoUnsafe < Minitest::Test
1432
def test_security_manager_is_used
1533
begin
1634
java_import 'sun.misc.Unsafe'

test/test_synchronized_delegator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
require 'test/unit'
21
require 'thread_safe/synchronized_delegator.rb'
2+
require File.join(File.dirname(__FILE__), "test_helper")
33

4-
class TestSynchronizedDelegator < Test::Unit::TestCase
4+
class TestSynchronizedDelegator < Minitest::Test
55

66
def test_wraps_array
77
sync_array = SynchronizedDelegator.new(array = [])

thread_safe.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ Gem::Specification.new do |gem|
2121

2222
gem.add_development_dependency 'atomic', ['>= 1.1.7', '< 2']
2323
gem.add_development_dependency 'rake'
24+
gem.add_development_dependency 'minitest'
2425
end

0 commit comments

Comments
 (0)