Skip to content

Commit

Permalink
updates UnitTest to CRuby 1.9.2 p290
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jul 19, 2011
1 parent 2d83e71 commit 36a6887
Show file tree
Hide file tree
Showing 54 changed files with 1,292 additions and 155 deletions.
21 changes: 21 additions & 0 deletions test-mri/test/date/test_date.rb
Expand Up @@ -113,6 +113,27 @@ def test_eql_p
assert_equal(d2, dt2)
end

def test_coerce
bug4375 = '[ruby-core:35127]'
d = Date.jd(0)
d2 = Date.jd(1)
others = [1, d2, Date::Infinity.new, nil, Object.new]
assert_nothing_raised(bug4375) {
others.each do |o|
case o
when d
flunk("expected not to match")
end
end
}
assert_nothing_raised(bug4375) {
case d
when *others
flunk("expected not to match")
end
}
end

def test_hash
h = {}
h[Date.new(1999,5,23)] = 0
Expand Down
2 changes: 1 addition & 1 deletion test-mri/test/dl/test_base.rb
Expand Up @@ -25,7 +25,7 @@
libm_so = File.join(libdir, "libm.so.6")
when /mingw/, /mswin/
require "rbconfig"
libc_so = libm_so = RbConfig::CONFIG["RUBY_SO_NAME"].split(/-/, 2)[0] + ".dll"
libc_so = libm_so = RbConfig::CONFIG["RUBY_SO_NAME"].split(/-/).find{|e| /^msvc/ =~ e} + ".dll"
when /darwin/
libc_so = "/usr/lib/libc.dylib"
libm_so = "/usr/lib/libm.dylib"
Expand Down
1 change: 1 addition & 0 deletions test-mri/test/dl/test_dl2.rb
Expand Up @@ -95,6 +95,7 @@ def test_call_double()
end

def test_sin
return if /x86_64/ =~ RUBY_PLATFORM
pi_2 = Math::PI/2
cfunc = Function.new(CFunc.new(@libm['sin'], TYPE_DOUBLE, 'sin'),
[TYPE_DOUBLE])
Expand Down
2 changes: 2 additions & 0 deletions test-mri/test/dl/test_func.rb
Expand Up @@ -22,6 +22,7 @@ def test_random
end

def test_sinf
return if /x86_64/ =~ RUBY_PLATFORM
begin
f = Function.new(CFunc.new(@libm['sinf'], TYPE_FLOAT, 'sinf'),
[TYPE_FLOAT])
Expand All @@ -32,6 +33,7 @@ def test_sinf
end

def test_sin
return if /x86_64/ =~ RUBY_PLATFORM
f = Function.new(CFunc.new(@libm['sin'], TYPE_DOUBLE, 'sin'),
[TYPE_DOUBLE])
assert_in_delta 1.0, f.call(90 * Math::PI / 180), 0.0001
Expand Down
2 changes: 1 addition & 1 deletion test-mri/test/drb/ut_array.rb
Expand Up @@ -8,7 +8,7 @@ def ARGV.shift
it
end

DRb.start_service(nil, [1, 2, 'III', 4, "five", 6])
DRb.start_service("druby://localhost:0", [1, 2, 'III', 4, "five", 6])
es = DRb::ExtServ.new(ARGV.shift, ARGV.shift)
DRb.thread.join
end
Expand Down
2 changes: 1 addition & 1 deletion test-mri/test/drb/ut_array_drbssl.rb
Expand Up @@ -17,7 +17,7 @@ def ARGV.shift
config[:SSLCertName] =
[ ["C","JP"], ["O","Foo.DRuby.Org"], ["CN", "Sample"] ]

DRb.start_service('drbssl://:0', [1, 2, 'III', 4, "five", 6], config)
DRb.start_service('drbssl://localhost:0', [1, 2, 'III', 4, "five", 6], config)
es = DRb::ExtServ.new(ARGV.shift, ARGV.shift)
DRb.thread.join
end
Expand Down
89 changes: 89 additions & 0 deletions test-mri/test/fileutils/clobber.rb
@@ -0,0 +1,89 @@
require 'fileutils'
require 'test/unit'
require 'tmpdir'
require_relative 'fileasserts'

class TestFileUtils < Test::Unit::TestCase
end

module TestFileUtils::Clobber
def my_rm_rf(path)
if File.exist?('/bin/rm')
system %Q[/bin/rm -rf "#{path}"]
else
FileUtils.rm_rf path
end
end

SRC = 'data/src'
COPY = 'data/copy'

def setup
@prevdir = Dir.pwd
class << (@fileutils_output = "")
alias puts <<
end
tmproot = "#{Dir.tmpdir}/fileutils.rb.#{$$}"
Dir.mkdir tmproot unless File.directory?(tmproot)
Dir.chdir tmproot
my_rm_rf 'data'; Dir.mkdir 'data'
my_rm_rf 'tmp'; Dir.mkdir 'tmp'
File.open(SRC, 'w') {|f| f.puts 'dummy' }
File.open(COPY, 'w') {|f| f.puts 'dummy' }
end

def teardown
tmproot = Dir.pwd
Dir.chdir @prevdir
my_rm_rf tmproot
end

def test_cp
cp SRC, 'tmp/cp'
check 'tmp/cp'
end

def test_mv
mv SRC, 'tmp/mv'
check 'tmp/mv'
end

def check(dest, message=nil)
assert_file_not_exist dest, message
assert_file_exist SRC, message
assert_same_file SRC, COPY, message
end

def test_rm
rm SRC
assert_file_exist SRC
assert_same_file SRC, COPY
end

def test_rm_f
rm_f SRC
assert_file_exist SRC
assert_same_file SRC, COPY
end

def test_rm_rf
rm_rf SRC
assert_file_exist SRC
assert_same_file SRC, COPY
end

def test_mkdir
mkdir 'dir'
assert_file_not_exist 'dir'
end

def test_mkdir_p
mkdir 'dir/dir/dir'
assert_file_not_exist 'dir'
end

def test_copy_entry
copy_entry SRC, 'tmp/copy_entry'
check 'tmp/copy_entry', bug4331 = '[ruby-dev:43129]'
end
end
39 changes: 22 additions & 17 deletions test-mri/test/fileutils/fileasserts.rb
@@ -1,4 +1,4 @@
# $Id: fileasserts.rb 25189 2009-10-02 12:04:37Z akr $
# $Id: fileasserts.rb 31404 2011-05-01 09:37:17Z yugui $

module Test
module Unit
Expand All @@ -8,59 +8,64 @@ def _wrap_assertion
yield
end

def assert_same_file(from, to)
def assert_block(*msgs)
assert yield, *msgs.compact
end

def assert_same_file(from, to, message=nil)
_wrap_assertion {
assert_block("file #{from} != #{to}") {
assert_block("file #{from} != #{to}#{message&&': '}#{message||''}") {
File.read(from) == File.read(to)
}
}
end

def assert_same_entry(from, to)
def assert_same_entry(from, to, message=nil)
a = File.stat(from)
b = File.stat(to)
assert_equal a.mode, b.mode, "mode #{a.mode} != #{b.mode}"
msg = "#{message&&': '}#{message||''}"
assert_equal a.mode, b.mode, "mode #{a.mode} != #{b.mode}#{msg}"
#assert_equal a.atime, b.atime
assert_equal_timestamp a.mtime, b.mtime, "mtime #{a.mtime} != #{b.mtime}"
assert_equal a.uid, b.uid, "uid #{a.uid} != #{b.uid}"
assert_equal a.gid, b.gid, "gid #{a.gid} != #{b.gid}"
assert_equal_timestamp a.mtime, b.mtime, "mtime #{a.mtime} != #{b.mtime}#{msg}"
assert_equal a.uid, b.uid, "uid #{a.uid} != #{b.uid}#{msg}"
assert_equal a.gid, b.gid, "gid #{a.gid} != #{b.gid}#{msg}"
end

def assert_file_exist(path)
def assert_file_exist(path, message=nil)
_wrap_assertion {
assert_block("file not exist: #{path}") {
assert_block("file not exist: #{path}#{message&&': '}#{message||''}") {
File.exist?(path)
}
}
end

def assert_file_not_exist(path)
def assert_file_not_exist(path, message=nil)
_wrap_assertion {
assert_block("file not exist: #{path}") {
assert_block("file not exist: #{path}#{message&&': '}#{message||''}") {
not File.exist?(path)
}
}
end

def assert_directory(path)
def assert_directory(path, message=nil)
_wrap_assertion {
assert_block("is not directory: #{path}") {
assert_block("is not directory: #{path}#{message&&': '}#{message||''}") {
File.directory?(path)
}
}
end

def assert_symlink(path)
def assert_symlink(path, message=nil)
_wrap_assertion {
assert_block("is not a symlink: #{path}") {
assert_block("is not a symlink: #{path}#{message&&': '}#{message||''}") {
File.symlink?(path)
}
}
end

def assert_not_symlink(path)
_wrap_assertion {
assert_block("is a symlink: #{path}") {
assert_block("is a symlink: #{path}#{message&&': '}#{message||''}") {
not File.symlink?(path)
}
}
Expand Down
6 changes: 4 additions & 2 deletions test-mri/test/fileutils/test_dryrun.rb
@@ -1,11 +1,13 @@
# $Id: test_dryrun.rb 26417 2010-01-25 22:08:29Z akr $
# $Id: test_dryrun.rb 31404 2011-05-01 09:37:17Z yugui $

require 'test/unit'
require 'fileutils'
require 'test/unit'
require_relative 'clobber'

class TestFileUtilsDryRun < Test::Unit::TestCase

include FileUtils::DryRun
include TestFileUtils::Clobber

def test_visibility
FileUtils::METHODS.each do |m|
Expand Down
79 changes: 3 additions & 76 deletions test-mri/test/fileutils/test_nowrite.rb
@@ -1,13 +1,13 @@
# $Id: test_nowrite.rb 25189 2009-10-02 12:04:37Z akr $
# $Id: test_nowrite.rb 31404 2011-05-01 09:37:17Z yugui $

require 'fileutils'
require_relative 'fileasserts'
require 'tmpdir'
require 'test/unit'
require_relative 'clobber'

class TestFileUtilsNoWrite < Test::Unit::TestCase

include FileUtils::NoWrite
include TestFileUtils::Clobber

def test_visibility
FileUtils::METHODS.each do |m|
Expand All @@ -23,77 +23,4 @@ def test_visibility
"FileUtils::NoWrite\##{m} is not private"
end
end

def my_rm_rf(path)
if File.exist?('/bin/rm')
system %Q[/bin/rm -rf "#{path}"]
else
FileUtils.rm_rf path
end
end

SRC = 'data/src'
COPY = 'data/copy'

def setup
@prevdir = Dir.pwd
tmproot = "#{Dir.tmpdir}/fileutils.rb.#{$$}"
Dir.mkdir tmproot unless File.directory?(tmproot)
Dir.chdir tmproot
my_rm_rf 'data'; Dir.mkdir 'data'
my_rm_rf 'tmp'; Dir.mkdir 'tmp'
File.open(SRC, 'w') {|f| f.puts 'dummy' }
File.open(COPY, 'w') {|f| f.puts 'dummy' }
end

def teardown
tmproot = Dir.pwd
Dir.chdir @prevdir
my_rm_rf tmproot
end

def test_cp
cp SRC, 'tmp/cp'
check 'tmp/cp'
end

def test_mv
mv SRC, 'tmp/mv'
check 'tmp/mv'
end

def check(dest)
assert_file_not_exist dest
assert_file_exist SRC
assert_same_file SRC, COPY
end

def test_rm
rm SRC
assert_file_exist SRC
assert_same_file SRC, COPY
end

def test_rm_f
rm_f SRC
assert_file_exist SRC
assert_same_file SRC, COPY
end

def test_rm_rf
rm_rf SRC
assert_file_exist SRC
assert_same_file SRC, COPY
end

def test_mkdir
mkdir 'dir'
assert_file_not_exist 'dir'
end

def test_mkdir_p
mkdir 'dir/dir/dir'
assert_file_not_exist 'dir'
end

end

0 comments on commit 36a6887

Please sign in to comment.