git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-11-15 16:24:45 +00:00
Родитель f5936bc835
Коммит 43bd807c43
2 изменённых файлов: 83 добавлений и 22 удалений

Просмотреть файл

@ -127,42 +127,50 @@ module Test
end
LANG_ENVS = %w"LANG LC_ALL LC_CTYPE"
def assert_in_out_err(args, test_stdin = "", test_stdout = [], test_stderr = [], message = nil)
def assert_in_out_err(args, test_stdin = "", test_stdout = [], test_stderr = [], message = nil, opt={})
in_c, in_p = IO.pipe
out_p, out_c = IO.pipe
err_p, err_c = IO.pipe
out_p, out_c = IO.pipe if test_stdout
err_p, err_c = IO.pipe if test_stderr
c = "C"
env = {}
LANG_ENVS.each {|lc| env[lc], ENV[lc] = ENV[lc], c}
pid = spawn(EnvUtil.rubybin, *args, STDIN=>in_c, STDOUT=>out_c, STDERR=>err_c)
opt = opt.dup
opt[:in] = in_c
opt[:out] = out_c if test_stdout
opt[:err] = err_c if test_stderr
pid = spawn(EnvUtil.rubybin, *args, opt)
in_c.close
out_c.close
err_c.close
out_c.close if test_stdout
err_c.close if test_stderr
in_p.write test_stdin
in_p.close
th_stdout = Thread.new { out_p.read }
th_stderr = Thread.new { err_p.read }
if th_stdout.join(10) && th_stderr.join(10)
stdout = th_stdout.value
stderr = th_stderr.value
th_stdout = Thread.new { out_p.read } if test_stdout
th_stderr = Thread.new { err_p.read } if test_stderr
if (!test_stdout || th_stdout.join(10)) && (!test_stderr || th_stderr.join(10))
stdout = th_stdout.value if test_stdout
stderr = th_stderr.value if test_stderr
else
flunk("timeout")
end
out_p.close
err_p.close
out_p.close if test_stdout
err_p.close if test_stderr
Process.wait pid
if block_given?
yield(stdout.lines.map {|l| l.chomp }, stderr.lines.map {|l| l.chomp })
yield(test_stdout ? stdout.lines.map {|l| l.chomp } : nil, test_stderr ? stderr.lines.map {|l| l.chomp } : nil)
else
if test_stdout.is_a?(Regexp)
assert_match(test_stdout, stdout, message)
else
assert_equal(test_stdout, stdout.lines.map {|l| l.chomp }, message)
if test_stdout
if test_stdout.is_a?(Regexp)
assert_match(test_stdout, stdout, message)
else
assert_equal(test_stdout, stdout.lines.map {|l| l.chomp }, message)
end
end
if test_stderr.is_a?(Regexp)
assert_match(test_stderr, stderr, message)
else
assert_equal(test_stderr, stderr.lines.map {|l| l.chomp }, message)
if test_stderr
if test_stderr.is_a?(Regexp)
assert_match(test_stderr, stderr, message)
else
assert_equal(test_stderr, stderr.lines.map {|l| l.chomp }, message)
end
end
end
ensure
@ -182,6 +190,10 @@ module Test
(th_stdout.kill; th_stdout.join) if th_stdout
(th_stderr.kill; th_stderr.join) if th_stderr
end
def assert_in_out(args, test_stdin = "", test_stdout = [], message = nil, opt={})
assert_in_out_err(args, test_stdin, test_stdout, nil, message, opt)
end
end
end
end

Просмотреть файл

@ -0,0 +1,49 @@
require 'test/unit'
require 'tmpdir'
require_relative 'envutil'
class TestDir_M17N < Test::Unit::TestCase
def with_tmpdir
Dir.mktmpdir {|dir|
Dir.chdir(dir) {
yield dir
}
}
end
def test_filename_bytes_euc_jp
with_tmpdir {|d|
assert_in_out(%w[-EEUC-JP], <<-'EOS', %w[true], nil, :chdir=>d)
filename = "\xA4\xA2".force_encoding("euc-jp")
File.open(filename, "w") {}
ents = Dir.entries(".")
ents.each {|e| e.force_encoding("ASCII-8BIT") }
p ents.include?(filename.force_encoding("ASCII-8BIT"))
EOS
}
end
def test_filename_euc_jp
with_tmpdir {|d|
assert_in_out(%w[-EEUC-JP], <<-'EOS', %w[true], nil, :chdir=>d)
filename = "\xA4\xA2".force_encoding("euc-jp")
File.open(filename, "w") {}
ents = Dir.entries(".")
p ents.include?(filename)
EOS
}
end
def test_filename_utf_8
with_tmpdir {|d|
assert_in_out(%w[-EUTF-8], <<-'EOS', %w[true], nil, :chdir=>d)
filename = "\u3042".force_encoding("utf-8")
File.open(filename, "w") {}
ents = Dir.entries(".")
p ents.include?(filename)
EOS
}
end
end