diff --git a/ChangeLog b/ChangeLog index 7caa04dd31..de7833d9ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Sat Sep 24 08:29:36 2005 Minero Aoki + + * lib/fileutils.rb: fix visibility of FileUtils::NoWrite, Verbose, + DryRun. [ruby-core:05954] + + * test/fileutils/test_nowrite.rb: test it. + + * test/fileutils/test_dryrun.rb: new file. + + * test/fileutils/test_verbose.rb: new file. + Sat Sep 24 07:59:01 2005 Minero Aoki * sample/ripper/colorize.rb: removed (replaced by ruby2html.rb). diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 36d5f70c0d..a2c411f6e3 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -1080,7 +1080,7 @@ module FileUtils def path if @path - @path + File.path(@path) else join(@prefix, @rel) end @@ -1486,6 +1486,9 @@ module FileUtils OPT_TABLE.keys.select {|m| OPT_TABLE[m].include?(opt.to_s) } end + METHODS = singleton_methods() - %w( private_module_function + commands options have_option? options_of collect_method ) + # # This module has all methods of FileUtils module, but it outputs messages # before acting. This equates to passing the :verbose flag to @@ -1500,9 +1503,15 @@ module FileUtils def #{name}(*args) super(*fu_update_option(args, :verbose => true)) end + private :#{name} EOS end extend self + class << self + ::FileUtils::METHODS.each do |m| + public m + end + end end # @@ -1519,9 +1528,15 @@ module FileUtils def #{name}(*args) super(*fu_update_option(args, :noop => true)) end + private :#{name} EOS end extend self + class << self + ::FileUtils::METHODS.each do |m| + public m + end + end end # @@ -1539,9 +1554,15 @@ module FileUtils def #{name}(*args) super(*fu_update_option(args, :noop => true, :verbose => true)) end + private :#{name} EOS end extend self + class << self + ::FileUtils::METHODS.each do |m| + public m + end + end end end diff --git a/test/fileutils/test_dryrun.rb b/test/fileutils/test_dryrun.rb new file mode 100644 index 0000000000..2fdd65d2f6 --- /dev/null +++ b/test/fileutils/test_dryrun.rb @@ -0,0 +1,25 @@ +# $Id$ + +require 'test/unit' +require 'fileutils' + +class TestFileUtilsDryRun < Test::Unit::TestCase + + include FileUtils::DryRun + + def test_visibility + FileUtils::METHODS.each do |m| + assert_equal true, FileUtils::DryRun.respond_to?(m, true), + "FileUtils::DryRun.#{m} not defined" + assert_equal true, FileUtils::DryRun.respond_to?(m, false), + "FileUtils::DryRun.#{m} not public" + end + FileUtils::METHODS.each do |m| + assert_equal true, respond_to?(m, true) + "FileUtils::DryRun\##{m} is not defined" + assert_equal true, FileUtils::DryRun.private_method_defined?(m), + "FileUtils::DryRun\##{m} is not private" + end + end + +end diff --git a/test/fileutils/test_nowrite.rb b/test/fileutils/test_nowrite.rb index 4e6701b967..369f8ca608 100644 --- a/test/fileutils/test_nowrite.rb +++ b/test/fileutils/test_nowrite.rb @@ -1,18 +1,30 @@ -# -# test/fileutils/test_nowrite.rb -# +# $Id$ require 'fileutils' require 'fileasserts' require 'tmpdir' require 'test/unit' - -class TestNoWrite < Test::Unit::TestCase +class TestFileUtilsNoWrite < Test::Unit::TestCase include FileUtils::NoWrite - def my_rm_rf( path ) + def test_visibility + FileUtils::METHODS.each do |m| + assert_equal true, FileUtils::NoWrite.respond_to?(m, true), + "FileUtils::NoWrite.#{m} is not defined" + assert_equal true, FileUtils::NoWrite.respond_to?(m, false), + "FileUtils::NoWrite.#{m} is not public" + end + FileUtils::METHODS.each do |m| + assert_equal true, respond_to?(m, true), + "FileUtils::NoWrite\##{m} is not defined" + assert_equal true, FileUtils::NoWrite.private_method_defined?(m), + "FileUtils::NoWrite\##{m} is not private" + end + end + + def my_rm_rf(path) if File.exist?('/bin/rm') system %Q[/bin/rm -rf "#{path}"] else @@ -50,7 +62,7 @@ class TestNoWrite < Test::Unit::TestCase check 'tmp/mv' end - def check( dest ) + def check(dest) assert_file_not_exist dest assert_file_exist SRC assert_same_file SRC, COPY diff --git a/test/fileutils/test_verbose.rb b/test/fileutils/test_verbose.rb new file mode 100644 index 0000000000..e60e85ea4e --- /dev/null +++ b/test/fileutils/test_verbose.rb @@ -0,0 +1,25 @@ +# $Id$ + +require 'test/unit' +require 'fileutils' + +class TestFileUtilsVerbose < Test::Unit::TestCase + + include FileUtils::Verbose + + def test_visibility + FileUtils::METHODS.each do |m| + assert_equal true, FileUtils::Verbose.respond_to?(m, true), + "FileUtils::Verbose.#{m} is not defined" + assert_equal true, FileUtils::Verbose.respond_to?(m, false), + "FileUtils::Verbose.#{m} is not public" + end + FileUtils::METHODS.each do |m| + assert_equal true, respond_to?(m, true), + "FileUtils::Verbose.#{m} is not defined" + assert_equal true, FileUtils::Verbose.private_method_defined?(m), + "FileUtils::Verbose.#{m} is not private" + end + end + +end