mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
use assert_equal, assert_match, and so on.
* test/fileutils/fileasserts.rb: use assert_equal, assert_match, and so on. * test/ruby/enc/test_utf16.rb, test/ruby/enc/test_utf32.rb, test/ruby/test_io_m17n.rb (assert_str_equal): ditto. * test/rubygems/test_gem_remote_fetcher.rb (assert_data_from_{server,proxy}): ditto. * test/test_pstore.rb (test_thread_safe): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b5ba059a0b
commit
298258891d
8 changed files with 46 additions and 69 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
Mon May 7 10:23:04 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* test/fileutils/fileasserts.rb: use assert_equal, assert_match, and so on.
|
||||
|
||||
* test/ruby/enc/test_utf16.rb, test/ruby/enc/test_utf32.rb,
|
||||
test/ruby/test_io_m17n.rb (assert_str_equal): ditto.
|
||||
|
||||
* test/rubygems/test_gem_remote_fetcher.rb
|
||||
(assert_data_from_{server,proxy}): ditto.
|
||||
|
||||
* test/test_pstore.rb (test_thread_safe): ditto.
|
||||
|
||||
Mon May 7 10:16:30 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* test/rubygems/test_gem_installer.rb (TestGemInstaller#test_dir): fix
|
||||
|
|
|
@ -3,17 +3,8 @@
|
|||
module Test
|
||||
module Unit
|
||||
module FileAssertions
|
||||
|
||||
def _wrap_assertion
|
||||
yield
|
||||
end
|
||||
|
||||
def assert_same_file(from, to, message=nil)
|
||||
_wrap_assertion {
|
||||
assert_block("file #{from} != #{to}#{message&&': '}#{message||''}") {
|
||||
File.read(from) == File.read(to)
|
||||
}
|
||||
}
|
||||
assert_equal(File.read(from), File.read(to), "file #{from} != #{to}#{message&&': '}#{message||''}")
|
||||
end
|
||||
|
||||
def assert_same_entry(from, to, message=nil)
|
||||
|
@ -28,76 +19,52 @@ module Test
|
|||
end
|
||||
|
||||
def assert_file_exist(path, message=nil)
|
||||
_wrap_assertion {
|
||||
assert_block("file not exist: #{path}#{message&&': '}#{message||''}") {
|
||||
File.exist?(path)
|
||||
}
|
||||
}
|
||||
assert(File.exist?(path), "file not exist: #{path}#{message&&': '}#{message||''}")
|
||||
end
|
||||
|
||||
def assert_file_not_exist(path, message=nil)
|
||||
_wrap_assertion {
|
||||
assert_block("file not exist: #{path}#{message&&': '}#{message||''}") {
|
||||
not File.exist?(path)
|
||||
}
|
||||
}
|
||||
assert(!File.exist?(path), "file exist: #{path}#{message&&': '}#{message||''}")
|
||||
end
|
||||
|
||||
def assert_directory(path, message=nil)
|
||||
_wrap_assertion {
|
||||
assert_block("is not directory: #{path}#{message&&': '}#{message||''}") {
|
||||
File.directory?(path)
|
||||
}
|
||||
}
|
||||
assert(File.directory?(path), "is not directory: #{path}#{message&&': '}#{message||''}")
|
||||
end
|
||||
|
||||
def assert_symlink(path, message=nil)
|
||||
_wrap_assertion {
|
||||
assert_block("is not a symlink: #{path}#{message&&': '}#{message||''}") {
|
||||
File.symlink?(path)
|
||||
}
|
||||
}
|
||||
assert(File.symlink?(path), "is not a symlink: #{path}#{message&&': '}#{message||''}")
|
||||
end
|
||||
|
||||
def assert_not_symlink(path)
|
||||
_wrap_assertion {
|
||||
assert_block("is a symlink: #{path}#{message&&': '}#{message||''}") {
|
||||
not File.symlink?(path)
|
||||
}
|
||||
}
|
||||
assert(!File.symlink?(path), "is a symlink: #{path}#{message&&': '}#{message||''}")
|
||||
end
|
||||
|
||||
def assert_equal_time(expected, actual, message=nil)
|
||||
_wrap_assertion {
|
||||
expected_str = expected.to_s
|
||||
actual_str = actual.to_s
|
||||
if expected_str == actual_str
|
||||
expected_str << " (nsec=#{expected.nsec})"
|
||||
actual_str << " (nsec=#{actual.nsec})"
|
||||
end
|
||||
full_message = build_message(message, <<EOT)
|
||||
expected_str = expected.to_s
|
||||
actual_str = actual.to_s
|
||||
if expected_str == actual_str
|
||||
expected_str << " (nsec=#{expected.nsec})"
|
||||
actual_str << " (nsec=#{actual.nsec})"
|
||||
end
|
||||
full_message = build_message(message, <<EOT)
|
||||
<#{expected_str}> expected but was
|
||||
<#{actual_str}>.
|
||||
EOT
|
||||
assert_block(full_message) { expected == actual }
|
||||
}
|
||||
assert_equal(expected, actual, full_message)
|
||||
end
|
||||
|
||||
def assert_equal_timestamp(expected, actual, message=nil)
|
||||
_wrap_assertion {
|
||||
expected_str = expected.to_s
|
||||
actual_str = actual.to_s
|
||||
if expected_str == actual_str
|
||||
expected_str << " (nsec=#{expected.nsec})"
|
||||
actual_str << " (nsec=#{actual.nsec})"
|
||||
end
|
||||
full_message = build_message(message, <<EOT)
|
||||
expected_str = expected.to_s
|
||||
actual_str = actual.to_s
|
||||
if expected_str == actual_str
|
||||
expected_str << " (nsec=#{expected.nsec})"
|
||||
actual_str << " (nsec=#{actual.nsec})"
|
||||
end
|
||||
full_message = build_message(message, <<EOT)
|
||||
<#{expected_str}> expected but was
|
||||
<#{actual_str}>.
|
||||
EOT
|
||||
# subsecond timestamp is not portable.
|
||||
assert_block(full_message) { expected.tv_sec == actual.tv_sec }
|
||||
}
|
||||
# subsecond timestamp is not portable.
|
||||
assert_equal(expected.tv_sec, actual.tv_sec, full_message)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -49,7 +49,7 @@ class TestUTF16 < Test::Unit::TestCase
|
|||
#{encdump expected} expected but not equal to
|
||||
#{encdump actual}.
|
||||
EOT
|
||||
assert_block(full_message) { expected == actual }
|
||||
assert_equal(expected, actual, full_message)
|
||||
end
|
||||
|
||||
# tests start
|
||||
|
|
|
@ -15,7 +15,7 @@ class TestUTF32 < Test::Unit::TestCase
|
|||
#{encdump expected} expected but not equal to
|
||||
#{encdump actual}.
|
||||
EOT
|
||||
assert_block(full_message) { expected == actual }
|
||||
assert_equal(expected, actual, full_message)
|
||||
end
|
||||
|
||||
def test_substr
|
||||
|
|
|
@ -140,8 +140,7 @@ class TestEnv < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_keys
|
||||
a = nil
|
||||
assert_block { a = ENV.keys }
|
||||
a = ENV.keys
|
||||
assert_kind_of(Array, a)
|
||||
a.each {|k| assert_kind_of(String, k) }
|
||||
end
|
||||
|
@ -151,8 +150,7 @@ class TestEnv < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_values
|
||||
a = nil
|
||||
assert_block { a = ENV.values }
|
||||
a = ENV.values
|
||||
assert_kind_of(Array, a)
|
||||
a.each {|k| assert_kind_of(String, k) }
|
||||
end
|
||||
|
|
|
@ -71,7 +71,7 @@ class TestIO_M17N < Test::Unit::TestCase
|
|||
#{encdump expected} expected but not equal to
|
||||
#{encdump actual}.
|
||||
EOT
|
||||
assert_block(full_message) { expected == actual }
|
||||
assert_equal(expected, actual, full_message)
|
||||
end
|
||||
|
||||
def test_open_r
|
||||
|
|
|
@ -818,11 +818,11 @@ gems:
|
|||
end
|
||||
|
||||
def assert_data_from_server(data)
|
||||
assert_block("Data is not from server") { data =~ /0\.4\.11/ }
|
||||
assert_match(/0\.4\.11/, data, "Data is not from server")
|
||||
end
|
||||
|
||||
def assert_data_from_proxy(data)
|
||||
assert_block("Data is not from proxy") { data =~ /0\.4\.2/ }
|
||||
assert_match(/0\.4\.2/, data, "Data is not from proxy")
|
||||
end
|
||||
|
||||
class Conn
|
||||
|
|
|
@ -84,10 +84,10 @@ class PStoreTest < Test::Unit::TestCase
|
|||
sleep 1
|
||||
end
|
||||
end
|
||||
until flag; end
|
||||
sleep 0.1 until flag
|
||||
@pstore.transaction {}
|
||||
end
|
||||
assert_block do
|
||||
begin
|
||||
pstore = PStore.new(second_file, true)
|
||||
flag = false
|
||||
Thread.new do
|
||||
|
@ -97,8 +97,8 @@ class PStoreTest < Test::Unit::TestCase
|
|||
sleep 1
|
||||
end
|
||||
end
|
||||
until flag; end
|
||||
pstore.transaction { pstore[:foo] == "bar" }
|
||||
sleep 0.1 until flag
|
||||
assert_equal("bar", pstore.transaction { pstore[:foo] })
|
||||
end
|
||||
ensure
|
||||
File.unlink(second_file) rescue nil
|
||||
|
|
Loading…
Add table
Reference in a new issue