From 298258891d2f8a80f8d1eac193c6609a256a3cf0 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 7 May 2012 01:23:07 +0000 Subject: 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 --- ChangeLog | 12 +++++ test/fileutils/fileasserts.rb | 79 ++++++++++---------------------- test/ruby/enc/test_utf16.rb | 2 +- test/ruby/enc/test_utf32.rb | 2 +- test/ruby/test_env.rb | 6 +-- test/ruby/test_io_m17n.rb | 2 +- test/rubygems/test_gem_remote_fetcher.rb | 4 +- test/test_pstore.rb | 8 ++-- 8 files changed, 46 insertions(+), 69 deletions(-) diff --git a/ChangeLog b/ChangeLog index caa7a81a8f..b60ed8630c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Mon May 7 10:23:04 2012 Nobuyoshi Nakada + + * 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 * test/rubygems/test_gem_installer.rb (TestGemInstaller#test_dir): fix diff --git a/test/fileutils/fileasserts.rb b/test/fileutils/fileasserts.rb index e8c5fa4369..0aa139fe16 100644 --- a/test/fileutils/fileasserts.rb +++ b/test/fileutils/fileasserts.rb @@ -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, < 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, < 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 diff --git a/test/ruby/enc/test_utf16.rb b/test/ruby/enc/test_utf16.rb index 90a8314067..7d2197da98 100644 --- a/test/ruby/enc/test_utf16.rb +++ b/test/ruby/enc/test_utf16.rb @@ -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 diff --git a/test/ruby/enc/test_utf32.rb b/test/ruby/enc/test_utf32.rb index 3d4a458512..29a2240598 100644 --- a/test/ruby/enc/test_utf32.rb +++ b/test/ruby/enc/test_utf32.rb @@ -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 diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb index 8baf762472..ced00c30cc 100644 --- a/test/ruby/test_env.rb +++ b/test/ruby/test_env.rb @@ -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 diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index fcbe6e0519..719214d491 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -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 diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index 2c8769c1c1..495c28727c 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -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 diff --git a/test/test_pstore.rb b/test/test_pstore.rb index 8bb44e8a51..1b93925b0b 100644 --- a/test/test_pstore.rb +++ b/test/test_pstore.rb @@ -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 -- cgit v1.2.3