[前][次][番号順一覧][スレッド一覧]

ruby-changes:13973

From: akr <ko1@a...>
Date: Mon, 16 Nov 2009 01:24:55 +0900 (JST)
Subject: [ruby-changes:13973] Ruby:r25780 (trunk): add tests.

akr	2009-11-16 01:24:45 +0900 (Mon, 16 Nov 2009)

  New Revision: 25780

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25780

  Log:
    add tests.

  Added files:
    trunk/test/ruby/test_dir_m17n.rb
  Modified files:
    trunk/test/ruby/envutil.rb

Index: test/ruby/test_dir_m17n.rb
===================================================================
--- test/ruby/test_dir_m17n.rb	(revision 0)
+++ test/ruby/test_dir_m17n.rb	(revision 25780)
@@ -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
+
Index: test/ruby/envutil.rb
===================================================================
--- test/ruby/envutil.rb	(revision 25779)
+++ test/ruby/envutil.rb	(revision 25780)
@@ -127,42 +127,50 @@
       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 @@
         (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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]