mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
add tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f5936bc835
commit
43bd807c43
2 changed files with 83 additions and 22 deletions
|
@ -127,42 +127,50 @@ module Test
|
||||||
end
|
end
|
||||||
|
|
||||||
LANG_ENVS = %w"LANG LC_ALL LC_CTYPE"
|
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
|
in_c, in_p = IO.pipe
|
||||||
out_p, out_c = IO.pipe
|
out_p, out_c = IO.pipe if test_stdout
|
||||||
err_p, err_c = IO.pipe
|
err_p, err_c = IO.pipe if test_stderr
|
||||||
c = "C"
|
c = "C"
|
||||||
env = {}
|
env = {}
|
||||||
LANG_ENVS.each {|lc| env[lc], ENV[lc] = ENV[lc], c}
|
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
|
in_c.close
|
||||||
out_c.close
|
out_c.close if test_stdout
|
||||||
err_c.close
|
err_c.close if test_stderr
|
||||||
in_p.write test_stdin
|
in_p.write test_stdin
|
||||||
in_p.close
|
in_p.close
|
||||||
th_stdout = Thread.new { out_p.read }
|
th_stdout = Thread.new { out_p.read } if test_stdout
|
||||||
th_stderr = Thread.new { err_p.read }
|
th_stderr = Thread.new { err_p.read } if test_stderr
|
||||||
if th_stdout.join(10) && th_stderr.join(10)
|
if (!test_stdout || th_stdout.join(10)) && (!test_stderr || th_stderr.join(10))
|
||||||
stdout = th_stdout.value
|
stdout = th_stdout.value if test_stdout
|
||||||
stderr = th_stderr.value
|
stderr = th_stderr.value if test_stderr
|
||||||
else
|
else
|
||||||
flunk("timeout")
|
flunk("timeout")
|
||||||
end
|
end
|
||||||
out_p.close
|
out_p.close if test_stdout
|
||||||
err_p.close
|
err_p.close if test_stderr
|
||||||
Process.wait pid
|
Process.wait pid
|
||||||
if block_given?
|
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
|
else
|
||||||
if test_stdout.is_a?(Regexp)
|
if test_stdout
|
||||||
assert_match(test_stdout, stdout, message)
|
if test_stdout.is_a?(Regexp)
|
||||||
else
|
assert_match(test_stdout, stdout, message)
|
||||||
assert_equal(test_stdout, stdout.lines.map {|l| l.chomp }, message)
|
else
|
||||||
|
assert_equal(test_stdout, stdout.lines.map {|l| l.chomp }, message)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if test_stderr.is_a?(Regexp)
|
if test_stderr
|
||||||
assert_match(test_stderr, stderr, message)
|
if test_stderr.is_a?(Regexp)
|
||||||
else
|
assert_match(test_stderr, stderr, message)
|
||||||
assert_equal(test_stderr, stderr.lines.map {|l| l.chomp }, message)
|
else
|
||||||
|
assert_equal(test_stderr, stderr.lines.map {|l| l.chomp }, message)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
|
@ -182,6 +190,10 @@ module Test
|
||||||
(th_stdout.kill; th_stdout.join) if th_stdout
|
(th_stdout.kill; th_stdout.join) if th_stdout
|
||||||
(th_stderr.kill; th_stderr.join) if th_stderr
|
(th_stderr.kill; th_stderr.join) if th_stderr
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
49
test/ruby/test_dir_m17n.rb
Normal file
49
test/ruby/test_dir_m17n.rb
Normal file
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue