Bug #272

test_chdir failed when Dir.tmpdir is symlink

Added by Kazuhiro NISHIYAMA almost 7 years ago. Updated almost 4 years ago.

[ruby-dev:35481]
Status:Closed
Priority:Normal
Assignee:-
ruby -v: Backport:

Description

=begin
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_dir20080714-13467-1l19gzu"> expected but was
<"/tmp/test_dir20080714-13467-1l19gzu">.

12 tests, 78 assertions, 1 failures, 0 errors
=end

History

#1 Updated by Kazuhiro NISHIYAMA almost 7 years ago

=begin
西山和広です。

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)

=end

#2 Updated by Anonymous almost 7 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r18153.
=end

Also available in: Atom PDF