diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-15 16:24:45 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-15 16:24:45 +0000 |
commit | 43bd807c43d25b31b29c6225b7d0f8ca6e67e40d (patch) | |
tree | b16ffaef11ff4b996c06bc0c21b8960e9c313066 /test | |
parent | f5936bc8351bda72ee852456c4565384969fe688 (diff) | |
download | ruby-43bd807c43d25b31b29c6225b7d0f8ca6e67e40d.tar.gz |
add tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/envutil.rb | 56 | ||||
-rw-r--r-- | test/ruby/test_dir_m17n.rb | 49 |
2 files changed, 83 insertions, 22 deletions
diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb index f0d5c2f8f6..dfc75bb0e1 100644 --- a/test/ruby/envutil.rb +++ b/test/ruby/envutil.rb @@ -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 diff --git a/test/ruby/test_dir_m17n.rb b/test/ruby/test_dir_m17n.rb new file mode 100644 index 0000000000..852f093006 --- /dev/null +++ b/test/ruby/test_dir_m17n.rb @@ -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 + |