Backport #1976
closedErrors in test/fileutils/test_fileutils.rb
Description
=begin
環境によっては test_fileutils.rb でエラーになることがあるようです。
-
Error:
test_rm_f(TestFileUtils):
TypeError: can't convert Array into String
/home/kazu/wc/ruby/trunk/test/fileutils/test_fileutils.rb:420:in `test_rm_f' -
Error:
test_rm_f(TestFileUtilsNoWrite):
TypeError: can't convert Hash into String
/home/kazu/wc/ruby/trunk/test/fileutils/test_nowrite.rb:78:in `test_rm_f' -
Error:
test_rm_rf(TestFileUtilsNoWrite):
TypeError: can't convert Hash into String
/home/kazu/wc/ruby/trunk/test/fileutils/test_nowrite.rb:84:in `test_rm_rf'
状況を調べてみると FileUtils::NoWrite の rm_rf の super で mkmf.rb の rm_rf が呼ばれていました。
そのときの self.class.ancestors は
[TestFileUtilsNoWrite, FileUtils::NoWrite, Test::Unit::TestCase, Test::Unit::Ass
ertions, MiniTest::Unit::TestCase, MiniTest::Assertions, Object, JSON::Ext::Gene
rator::GeneratorMethods::Object, RakeFileUtils, FileUtils, FileUtils::StreamUtil
s_, PP::ObjectMixin, Kernel, BasicObject]
となっていて、 FileUtils::NoWrite と FileUtils の間に Object が入っている (ここに mkmf.rb で rm_rf が定義されている) のが原因のようです。
以下のようにすると再現できます。
% ruby-trunk -r mkmf -r fileutils -e '
include FileUtils
class C
include FileUtils::NoWrite
def hoge
p self.class.ancestors
rm_rf("hoge")
end
end
C.new.hoge'
[C, FileUtils::NoWrite, Object, FileUtils, FileUtils::StreamUtils_, Kernel, BasicObject]
/home/kazu/opt/ruby-trunk/lib/ruby/1.9.1/mkmf.rb:201:in []': can't convert Hash into String (TypeError) from /home/kazu/opt/ruby-trunk/lib/ruby/1.9.1/mkmf.rb:201:in
rm_rf'
from /home/kazu/opt/ruby-trunk/lib/ruby/1.9.1/fileutils.rb:1556:in rm_rf' from -e:7:in
hoge'
from -e:10:in `'
%
=end