diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-07-31 12:57:21 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-09-27 11:39:02 +0900 |
commit | 9494ef8b2de3a7224eb85800606e7c046964cbd2 (patch) | |
tree | d7a0a42148a614f23fcdd4a18b6bd2e96b77149d /test/fileutils | |
parent | 02cd42050515b3af67396a25e78d948adcac6cdf (diff) |
[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
Diffstat (limited to 'test/fileutils')
-rw-r--r-- | test/fileutils/test_fileutils.rb | 24 |
1 files changed, 24 insertions, 0 deletions
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 |