From 9494ef8b2de3a7224eb85800606e7c046964cbd2 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 31 Jul 2019 12:57:21 -0700 Subject: [ruby/fileutils] Do not break in verbose mode if using FileUtils with a frozen object If FileUtils is included into another object, and verbose mode is used, a FrozenError is currently raised unless the object has the @fileutils_output and @fileutils_label instance variables. This fixes things so that it does not attempt to set the instance variables, but it still uses them if they are present. https://github.com/ruby/fileutils/commit/689cb9c56a --- test/fileutils/test_fileutils.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index 4480c2745b..41100e12a9 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -6,6 +6,7 @@ require 'etc' require_relative 'fileasserts' require 'pathname' require 'tmpdir' +require 'stringio' require 'test/unit' class TestFileUtils < Test::Unit::TestCase @@ -1673,6 +1674,29 @@ class TestFileUtils < Test::Unit::TestCase check_singleton :chdir end + def test_chdir_verbose + assert_output_lines(["cd .", "cd -"], FileUtils) do + FileUtils.chdir('.', verbose: true){} + end + end + + def test_chdir_verbose_frozen + o = Object.new + o.extend(FileUtils) + o.singleton_class.send(:public, :chdir) + o.freeze + orig_stderr = $stderr + $stderr = StringIO.new + o.chdir('.', verbose: true){} + $stderr.rewind + assert_equal(<<-END, $stderr.read) +cd . +cd - + END + ensure + $stderr = orig_stderr if orig_stderr + end + def test_getwd check_singleton :getwd end -- cgit v1.2.3