Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
  • Loading branch information
nobu committed May 7, 2012
commit 6331df4026098d67ce55def62b801aa801b3771b
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Mon May 7 10:23:04 2012 Nobuyoshi Nakada <[email protected]>

* 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 <[email protected]>

* test/rubygems/test_gem_installer.rb (TestGemInstaller#test_dir): fix
Expand Down
79 changes: 23 additions & 56 deletions test/fileutils/fileasserts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -28,76 +19,52 @@ def assert_same_entry(from, to, message=nil)
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
Expand Down
2 changes: 1 addition & 1 deletion test/ruby/enc/test_utf16.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def assert_str_equal(expected, actual, message=nil)
#{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
Expand Down
2 changes: 1 addition & 1 deletion test/ruby/enc/test_utf32.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def assert_str_equal(expected, actual, message=nil)
#{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
Expand Down
6 changes: 2 additions & 4 deletions test/ruby/test_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ def test_aset
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
Expand All @@ -151,8 +150,7 @@ def test_each_key
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
Expand Down
2 changes: 1 addition & 1 deletion test/ruby/test_io_m17n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def assert_str_equal(expected, actual, message=nil)
#{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
Expand Down
4 changes: 2 additions & 2 deletions test/rubygems/test_gem_remote_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,11 @@ def assert_error(exception_class=Exception)
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
Expand Down
8 changes: 4 additions & 4 deletions test/test_pstore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def test_thread_safe
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
Expand All @@ -97,8 +97,8 @@ def test_thread_safe
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
Expand Down