Bug #272

test_chdir failed when Dir.tmpdir is symlink

Added by znz (Kazuhiro NISHIYAMA) almost 4 years ago. Updated about 1 year ago.

[ruby-dev:35481]
Status:Closed Start date:07/14/2008
Priority:Normal Due date:
Assignee:- % Done:

100%

Category:-
Target version:-
ruby -v:

Description

Dir.tmpdirが返すディレクトリがsymlinkのときにtest_chdirが失敗します。

% ln -s /tmp $HOME/symlink-tmpdir
% env TMPDIR=$HOME/symlink-tmpdir ruby-trunk -v test/ruby/test_dir.rb
ruby 1.9.0 (2008-07-14 revision 18060) [i686-linux]
Loaded suite test/ruby/test_dir
Started
.test/ruby/test_dir.rb:111: warning: conflicting chdir during another chdir block
F..........
Finished in 0.0631458779999999 seconds.

  1) Failure:
test_chdir(TestDir)
    [test/ruby/test_dir.rb:112:in `block in test_chdir'
     test/ruby/test_dir.rb:109:in `chdir'
     test/ruby/test_dir.rb:109:in `test_chdir']:
<"/home/kazu/symlink-tmpdir/__test_dir__20080714-13467-1l19gzu"> expected but was
<"/tmp/__test_dir__20080714-13467-1l19gzu">.

12 tests, 78 assertions, 1 failures, 0 errors

Associated revisions

Revision 18153
Added by znz (Kazuhiro NISHIYAMA) almost 4 years ago

* test/ruby/test_dir.rb: use realpath of tmpdir. [ruby-dev:35481] * test/ruby/test_process.rb: ditto.

History

Updated by znz (Kazuhiro NISHIYAMA) almost 4 years ago

西山和広です。

At Mon, 14 Jul 2008 17:54:40 +0900,
Kazuhiro NISHIYAMA wrote:
> 
> Dir.tmpdirが返すディレクトリがsymlinkのときにtest_chdirが失敗します。

test_execopts_chdir(TestProcess)も同様に失敗します。

Pathname#realpathを使えば解決するようですが、
こういう解決方法で良いのでしょうか?


Index: test/ruby/test_dir.rb
===================================================================
--- test/ruby/test_dir.rb	(revision 18104)
+++ test/ruby/test_dir.rb	(working copy)
@@ -2,11 +2,12 @@ require 'test/unit'

 require 'tmpdir'
 require 'fileutils'
+require 'pathname'

 class TestDir < Test::Unit::TestCase

   def setup
-    @root = Dir.mktmpdir('__test_dir__')
+    @root = Pathname.new(Dir.mktmpdir('__test_dir__')).realpath.to_s
     @nodir = File.join(@root, "dummy")
     for i in ?a..?z
       if i.ord % 2 == 0
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 18104)
+++ test/ruby/test_process.rb	(working copy)
@@ -1,5 +1,6 @@
 require 'test/unit'
 require 'tmpdir'
+require 'pathname'
 require_relative 'envutil'

 class TestProcess < Test::Unit::TestCase
@@ -21,6 +22,7 @@ class TestProcess < Test::Unit::TestCase

   def with_tmpchdir
     Dir.mktmpdir {|d|
+      d = Pathname.new(d).realpath.to_s
       Dir.chdir(d) {
         yield d
       }


-- 
|ZnZ(ゼット エヌ ゼット)
|西山和広(Kazuhiro NISHIYAMA)

Updated by Anonymous almost 4 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
Applied in changeset r18153.

Also available in: Atom PDF