fileutils.rb.verbose_install_fix.2.patch

Eric Hodel, 02/27/2013 07:14 AM

Download (23.4 KB)

View differences:

lib/fileutils.rb (working copy)
83 83
#
84 84

  
85 85
module FileUtils
86
  @fileutils_output  = $stderr
87
  @fileutils_label   = ''
88
  extend self
89 86

  
90
  #
91
  # This module has all methods of FileUtils module, but it outputs messages
92
  # before acting.  This equates to passing the <tt>:verbose</tt> flag to
93
  # methods in FileUtils.
94
  #
95
  module Verbose
96
    include FileUtils
97
    @fileutils_output  = $stderr
98
    @fileutils_label   = ''
99
    extend self
100
  end
101

  
102
  #
103
  # This module has all methods of FileUtils module, but never changes
104
  # files/directories.  This equates to passing the <tt>:noop</tt> flag
105
  # to methods in FileUtils.
106
  #
107
  module NoWrite
108
    include FileUtils
109
    @fileutils_output  = $stderr
110
    @fileutils_label   = ''
111
    extend self
112
  end
113

  
114
  #
115
  # This module has all methods of FileUtils module, but never changes
116
  # files/directories, with printing message before acting.
117
  # This equates to passing the <tt>:noop</tt> and <tt>:verbose</tt> flag
118
  # to methods in FileUtils.
119
  #
120
  module DryRun
121
    include FileUtils
122
    @fileutils_output  = $stderr
123
    @fileutils_label   = ''
124
    extend self
87
  def self.private_module_function(name)   #:nodoc:
88
    module_function name
89
    private_class_method name
125 90
  end
126 91

  
127 92
  # This hash table holds command options.
128 93
  OPT_TABLE = {}   #:nodoc: internal use only
129 94

  
130 95
  #
131
  def self.define_command(name, *options)
132
    OPT_TABLE[name.to_s] = options
133

  
134
    if options.include?(:verbose)
135
      Verbose.module_eval(<<-EOS, __FILE__, __LINE__ + 1)
136
        def #{name}(*args)
137
          super(*fu_update_option(args, :verbose => true))
138
        end
139
      EOS
140
    end
141
    if options.include?(:noop)
142
      NoWrite.module_eval(<<-EOS, __FILE__, __LINE__ + 1)
143
        def #{name}(*args)
144
          super(*fu_update_option(args, :noop => true))
145
        end
146
      EOS
147
      DryRun.module_eval(<<-EOS, __FILE__, __LINE__ + 1)
148
        def #{name}(*args)
149
          super(*fu_update_option(args, :noop => true, :verbose => true))
150
        end
151
      EOS
152
    else
153
      NoWrite.module_eval(<<-EOS, __FILE__, __LINE__ + 1)
154
        def #{name}(*); end
155
      EOS
156
      DryRun.module_eval(<<-EOS, __FILE__, __LINE__ + 1)
157
        def #{name}(*); end
158
      EOS
159
    end
160

  
161
    [self, Verbose, DryRun, NoWrite].each do |mod|
162
      mod.module_eval(<<-EOS, __FILE__, __LINE__ + 1)
163
        private :#{name}
164
        class << self; public :#{name}; end
165
      EOS
166
    end
167
  end
168

  
169
  class << self
170
    private :define_command
171
  end
172

  
173
public
174

  
175
  #
176 96
  # Options: (none)
177 97
  #
178 98
  # Returns the name of the current directory.
......
180 100
  def pwd
181 101
    Dir.pwd
182 102
  end
103
  module_function :pwd
183 104

  
184 105
  alias getwd pwd
185

  
186
  define_command('pwd')
187
  define_command('getwd')
106
  module_function :getwd
188 107

  
189 108
  #
190 109
  # Options: verbose
......
206 125
    Dir.chdir(dir, &block)
207 126
    fu_output_message 'cd -' if options[:verbose] and block
208 127
  end
128
  module_function :cd
209 129

  
210 130
  alias chdir cd
131
  module_function :chdir
211 132

  
212
  define_command('cd', :verbose)
213
  define_command('chdir', :verbose)
133
  OPT_TABLE['cd']    =
134
  OPT_TABLE['chdir'] = [:verbose]
214 135

  
215 136
  #
216 137
  # Options: (none)
......
231 152
    end
232 153
    true
233 154
  end
234

  
235
  define_command('uptodate?')
155
  module_function :uptodate?
236 156

  
237 157
  #
238 158
  # Options: mode noop verbose
......
254 174
      fu_mkdir dir, options[:mode]
255 175
    end
256 176
  end
177
  module_function :mkdir
257 178

  
258
  define_command('mkdir', :mode, :noop, :verbose)
179
  OPT_TABLE['mkdir'] = [:mode, :noop, :verbose]
259 180

  
260 181
  #
261 182
  # Options: mode noop verbose
......
304 225

  
305 226
    return *list
306 227
  end
228
  module_function :mkdir_p
307 229

  
308 230
  alias mkpath    mkdir_p
309 231
  alias makedirs  mkdir_p
232
  module_function :mkpath
233
  module_function :makedirs
310 234

  
311
  define_command('mkdir_p', :mode, :noop, :verbose)
312
  define_command('mkpath', :mode, :noop, :verbose)
313
  define_command('makedirs', :mode, :noop, :verbose)
314

  
315
private
235
  OPT_TABLE['mkdir_p']  =
236
  OPT_TABLE['mkpath']   =
237
  OPT_TABLE['makedirs'] = [:mode, :noop, :verbose]
316 238

  
317 239
  def fu_mkdir(path, mode)   #:nodoc:
318 240
    path = path.chomp(?/)
......
323 245
      Dir.mkdir path
324 246
    end
325 247
  end
326

  
327
public
248
  private_module_function :fu_mkdir
328 249

  
329 250
  #
330 251
  # Options: noop, verbose
......
354 275
      end
355 276
    end
356 277
  end
278
  module_function :rmdir
357 279

  
358
  define_command('rmdir', :parents, :noop, :verbose)
280
  OPT_TABLE['rmdir'] = [:parents, :noop, :verbose]
359 281

  
360 282
  #
361 283
  # Options: force noop verbose
......
388 310
      File.link s, d
389 311
    end
390 312
  end
313
  module_function :ln
391 314

  
392 315
  alias link ln
316
  module_function :link
393 317

  
394
  define_command('ln', :force, :noop, :verbose)
395
  define_command('link', :force, :noop, :verbose)
318
  OPT_TABLE['ln']   =
319
  OPT_TABLE['link'] = [:force, :noop, :verbose]
396 320

  
397 321
  #
398 322
  # Options: force noop verbose
......
425 349
      File.symlink s, d
426 350
    end
427 351
  end
352
  module_function :ln_s
428 353

  
429 354
  alias symlink ln_s
355
  module_function :symlink
430 356

  
431
  define_command('ln_s', :force, :noop, :verbose)
432
  define_command('symlink', :force, :noop, :verbose)
357
  OPT_TABLE['ln_s']    =
358
  OPT_TABLE['symlink'] = [:force, :noop, :verbose]
433 359

  
434 360
  #
435 361
  # Options: noop verbose
......
443 369
    options[:force] = true
444 370
    ln_s src, dest, options
445 371
  end
372
  module_function :ln_sf
446 373

  
447
  define_command('ln_sf', :noop, :verbose)
374
  OPT_TABLE['ln_sf'] = [:noop, :verbose]
448 375

  
449 376
  #
450 377
  # Options: preserve noop verbose
......
467 394
      copy_file s, d, options[:preserve]
468 395
    end
469 396
  end
397
  module_function :cp
470 398

  
471 399
  alias copy cp
400
  module_function :copy
472 401

  
473
  define_command('cp', :preserve, :noop, :verbose)
474
  define_command('copy', :preserve, :noop, :verbose)
402
  OPT_TABLE['cp']   =
403
  OPT_TABLE['copy'] = [:preserve, :noop, :verbose]
475 404

  
476 405
  #
477 406
  # Options: preserve noop verbose dereference_root remove_destination
......
506 435
      copy_entry s, d, options[:preserve], options[:dereference_root], options[:remove_destination]
507 436
    end
508 437
  end
438
  module_function :cp_r
509 439

  
510
  define_command('cp_r', :preserve, :noop, :verbose, :dereference_root, :remove_destination)
440
  OPT_TABLE['cp_r'] = [:preserve, :noop, :verbose,
441
                       :dereference_root, :remove_destination]
511 442

  
512 443
  #
513 444
  # Copies a file system entry +src+ to +dest+.
......
535 466
      ent.copy_metadata destent.path if preserve
536 467
    end)
537 468
  end
538

  
539
  define_command(:copy_entry)
469
  module_function :copy_entry
540 470

  
541 471
  #
542 472
  # Copies file contents of +src+ to +dest+.
......
547 477
    ent.copy_file dest
548 478
    ent.copy_metadata dest if preserve
549 479
  end
550

  
551
  define_command(:copy_file)
480
  module_function :copy_file
552 481

  
553 482
  #
554 483
  # Copies stream +src+ to +dest+.
......
558 487
  def copy_stream(src, dest)
559 488
    IO.copy_stream(src, dest)
560 489
  end
561

  
562
  define_command(:copy_stream)
490
  module_function :copy_stream
563 491

  
564 492
  #
565 493
  # Options: force noop verbose
......
602 530
      end
603 531
    end
604 532
  end
533
  module_function :mv
605 534

  
606 535
  alias move mv
536
  module_function :move
607 537

  
608
  define_command('mv', :force, :noop, :verbose, :secure)
609
  define_command('move', :force, :noop, :verbose, :secure)
610

  
611
private
538
  OPT_TABLE['mv']   =
539
  OPT_TABLE['move'] = [:force, :noop, :verbose, :secure]
612 540

  
613 541
  def rename_cannot_overwrite_file?   #:nodoc:
614 542
    /cygwin|mswin|mingw|bccwin|emx/ =~ RUBY_PLATFORM
615 543
  end
616

  
617
public
544
  private_module_function :rename_cannot_overwrite_file?
618 545

  
619 546
  #
620 547
  # Options: force noop verbose
......
636 563
      remove_file path, options[:force]
637 564
    end
638 565
  end
566
  module_function :rm
639 567

  
640 568
  alias remove rm
569
  module_function :remove
641 570

  
642
  define_command('rm', :force, :noop, :verbose)
643
  define_command('remove', :force, :noop, :verbose)
571
  OPT_TABLE['rm']     =
572
  OPT_TABLE['remove'] = [:force, :noop, :verbose]
644 573

  
645 574
  #
646 575
  # Options: noop verbose
......
655 584
    options[:force] = true
656 585
    rm list, options
657 586
  end
587
  module_function :rm_f
658 588

  
659 589
  alias safe_unlink rm_f
590
  module_function :safe_unlink
660 591

  
661
  define_command('rm_f', :noop, :verbose)
662
  define_command('safe_unlink', :noop, :verbose)
592
  OPT_TABLE['rm_f']        =
593
  OPT_TABLE['safe_unlink'] = [:noop, :verbose]
663 594

  
664 595
  #
665 596
  # Options: force noop verbose secure
......
696 627
      end
697 628
    end
698 629
  end
630
  module_function :rm_r
699 631

  
700
  define_command('rm_r', :force, :noop, :verbose, :secure)
632
  OPT_TABLE['rm_r'] = [:force, :noop, :verbose, :secure]
701 633

  
702 634
  #
703 635
  # Options: noop verbose secure
......
715 647
    options[:force] = true
716 648
    rm_r list, options
717 649
  end
650
  module_function :rm_rf
718 651

  
719 652
  alias rmtree rm_rf
653
  module_function :rmtree
720 654

  
721
  define_command('rm_rf', :noop, :verbose, :secure)
722
  define_command('rmtree', :noop, :verbose, :secure)
655
  OPT_TABLE['rm_rf']  =
656
  OPT_TABLE['rmtree'] = [:noop, :verbose, :secure]
723 657

  
724 658
  #
725 659
  # This method removes a file system entry +path+.  +path+ shall be a
......
807 741
  rescue
808 742
    raise unless force
809 743
  end
810

  
811
  define_command(:remove_entry_secure)
812

  
813
private
744
  module_function :remove_entry_secure
814 745

  
815 746
  def fu_have_symlink?   #:nodoc:
816 747
    File.symlink nil, nil
......
819 750
  rescue TypeError
820 751
    return true
821 752
  end
753
  private_module_function :fu_have_symlink?
822 754

  
823 755
  def fu_stat_identical_entry?(a, b)   #:nodoc:
824 756
    a.dev == b.dev and a.ino == b.ino
825 757
  end
826

  
827
public
758
  private_module_function :fu_stat_identical_entry?
828 759

  
829 760
  #
830 761
  # This method removes a file system entry +path+.
......
844 775
  rescue
845 776
    raise unless force
846 777
  end
847

  
848
  define_command(:remove_entry)
778
  module_function :remove_entry
849 779

  
850 780
  #
851 781
  # Removes a file +path+.
......
856 786
  rescue
857 787
    raise unless force
858 788
  end
859

  
860
  define_command(:remove_file)
789
  module_function :remove_file
861 790

  
862 791
  #
863 792
  # Removes a directory +dir+ and its contents recursively.
......
866 795
  def remove_dir(path, force = false)
867 796
    remove_entry path, force   # FIXME?? check if it is a directory
868 797
  end
869

  
870
  define_command(:remove_dir)
798
  module_function :remove_dir
871 799

  
872 800
  #
873 801
  # Returns true if the contents of a file A and a file B are identical.
......
883 811
      }
884 812
    }
885 813
  end
814
  module_function :compare_file
886 815

  
887 816
  alias identical? compare_file
888 817
  alias cmp compare_file
889

  
890
  define_command(:compare_file)
891
  define_command(:identical?)
892
  define_command(:cmp)
818
  module_function :identical?
819
  module_function :cmp
893 820

  
894 821
  #
895 822
  # Returns true if the contents of a stream +a+ and +b+ are identical.
......
905 832
    end while sa == sb
906 833
    false
907 834
  end
908

  
909
  define_command(:compare_stream)
835
  module_function :compare_stream
910 836

  
911 837
  #
912 838
  # Options: mode preserve noop verbose
......
931 857
      end
932 858
    end
933 859
  end
860
  module_function :install
934 861

  
935
  define_command('install', :mode, :preserve, :noop, :verbose)
936

  
937
private
862
  OPT_TABLE['install'] = [:mode, :preserve, :noop, :verbose]
938 863

  
939 864
  def user_mask(target)  #:nodoc:
940 865
    mask = 0
......
952 877
    end
953 878
    mask
954 879
  end
880
  private_module_function :user_mask
955 881

  
956 882
  def mode_mask(mode, path)  #:nodoc:
957 883
    mask = 0
......
973 899
    end
974 900
    mask
975 901
  end
902
  private_module_function :mode_mask
976 903

  
977 904
  def symbolic_modes_to_i(modes, path)  #:nodoc:
978 905
    current_mode = (File.stat(path).mode & 07777)
......
993 920
      end
994 921
    end
995 922
  end
923
  private_module_function :symbolic_modes_to_i
996 924

  
997 925
  def fu_mode(mode, path)  #:nodoc:
998 926
    mode.is_a?(String) ? symbolic_modes_to_i(mode, path) : mode
999 927
  end
928
  private_module_function :fu_mode
1000 929

  
1001 930
  def mode_to_s(mode)  #:nodoc:
1002 931
    mode.is_a?(String) ? mode : "%o" % mode
1003 932
  end
1004 933

  
1005
public
1006

  
1007 934
  #
1008 935
  # Options: noop verbose
1009 936
  #
......
1046 973
      Entry_.new(path).chmod(fu_mode(mode, path))
1047 974
    end
1048 975
  end
976
  module_function :chmod
1049 977

  
1050
  define_command('chmod', :noop, :verbose)
978
  OPT_TABLE['chmod'] = [:noop, :verbose]
1051 979

  
1052 980
  #
1053 981
  # Options: noop verbose force
......
1075 1003
      end
1076 1004
    end
1077 1005
  end
1006
  module_function :chmod_R
1078 1007

  
1079
  define_command('chmod_R', :noop, :verbose, :force)
1008
  OPT_TABLE['chmod_R'] = [:noop, :verbose, :force]
1080 1009

  
1081 1010
  #
1082 1011
  # Options: noop verbose
......
1103 1032
      Entry_.new(path).chown uid, gid
1104 1033
    end
1105 1034
  end
1035
  module_function :chown
1106 1036

  
1107
  define_command('chown', :noop, :verbose)
1037
  OPT_TABLE['chown'] = [:noop, :verbose]
1108 1038

  
1109 1039
  #
1110 1040
  # Options: noop verbose force
......
1139 1069
      end
1140 1070
    end
1141 1071
  end
1072
  module_function :chown_R
1142 1073

  
1143
  define_command('chown_R', :noop, :verbose, :force)
1144

  
1145
private
1074
  OPT_TABLE['chown_R'] = [:noop, :verbose, :force]
1146 1075

  
1147 1076
  begin
1148 1077
    require 'etc'
......
1158 1087
        Etc.getpwnam(user).uid
1159 1088
      end
1160 1089
    end
1090
    private_module_function :fu_get_uid
1161 1091

  
1162 1092
    def fu_get_gid(group)   #:nodoc:
1163 1093
      return nil unless group
......
1170 1100
        Etc.getgrnam(group).gid
1171 1101
      end
1172 1102
    end
1103
    private_module_function :fu_get_gid
1173 1104

  
1174 1105
  rescue LoadError
1175 1106
    # need Win32 support???
......
1177 1108
    def fu_get_uid(user)   #:nodoc:
1178 1109
      user    # FIXME
1179 1110
    end
1111
    private_module_function :fu_get_uid
1180 1112

  
1181 1113
    def fu_get_gid(group)   #:nodoc:
1182 1114
      group   # FIXME
1183 1115
    end
1116
    private_module_function :fu_get_gid
1184 1117
  end
1185 1118

  
1186
public
1187

  
1188 1119
  #
1189 1120
  # Options: noop verbose
1190 1121
  #
......
1217 1148
      end
1218 1149
    end
1219 1150
  end
1151
  module_function :touch
1220 1152

  
1221
  define_command('touch', :noop, :verbose, :mtime, :nocreate)
1153
  OPT_TABLE['touch'] = [:noop, :verbose, :mtime, :nocreate]
1222 1154

  
1223
private
1155
  private
1224 1156

  
1225 1157
  module StreamUtils_
1226 1158
    private
......
1552 1484
      post.call self
1553 1485
    end
1554 1486

  
1555
  private
1487
    private
1556 1488

  
1557 1489
    $fileutils_rb_have_lchmod = nil
1558 1490

  
......
1608 1540
    end
1609 1541
  end   # class Entry_
1610 1542

  
1611
private
1612

  
1613 1543
  def fu_list(arg)   #:nodoc:
1614 1544
    [arg].flatten.map {|path| File.path(path) }
1615 1545
  end
1546
  private_module_function :fu_list
1616 1547

  
1617 1548
  def fu_each_src_dest(src, dest)   #:nodoc:
1618 1549
    fu_each_src_dest0(src, dest) do |s, d|
......
1620 1551
      yield s, d, File.stat(s)
1621 1552
    end
1622 1553
  end
1554
  private_module_function :fu_each_src_dest
1623 1555

  
1624 1556
  def fu_each_src_dest0(src, dest)   #:nodoc:
1625 1557
    if tmp = Array.try_convert(src)
......
1636 1568
      end
1637 1569
    end
1638 1570
  end
1571
  private_module_function :fu_each_src_dest0
1639 1572

  
1640 1573
  def fu_same?(a, b)   #:nodoc:
1641 1574
    File.identical?(a, b)
1642 1575
  end
1576
  private_module_function :fu_same?
1643 1577

  
1644 1578
  def fu_check_options(options, optdecl)   #:nodoc:
1645 1579
    h = options.dup
......
1648 1582
    end
1649 1583
    raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
1650 1584
  end
1585
  private_module_function :fu_check_options
1651 1586

  
1652 1587
  def fu_update_option(args, new)   #:nodoc:
1653 1588
    if tmp = Hash.try_convert(args.last)
......
1657 1592
    end
1658 1593
    args
1659 1594
  end
1595
  private_module_function :fu_update_option
1596

  
1597
  @fileutils_output = $stderr
1598
  @fileutils_label  = ''
1660 1599

  
1661 1600
  def fu_output_message(msg)   #:nodoc:
1662 1601
    @fileutils_output ||= $stderr
1663 1602
    @fileutils_label  ||= ''
1664 1603
    @fileutils_output.puts @fileutils_label + msg
1665 1604
  end
1605
  private_module_function :fu_output_message
1666 1606

  
1667 1607
  #
1668 1608
  # Returns an Array of method names which have any options.
......
1712 1652
    OPT_TABLE.keys.select {|m| OPT_TABLE[m].include?(opt) }
1713 1653
  end
1714 1654

  
1715
  # LOW_METHODS
1655
  LOW_METHODS = singleton_methods(false) - collect_method(:noop).map(&:intern)
1656
  module LowMethods
1657
    module_eval("private\n" + ::FileUtils::LOW_METHODS.map {|name| "def #{name}(*)end"}.join("\n"),
1658
                __FILE__, __LINE__)
1659
  end
1660

  
1661
  METHODS = singleton_methods() - [:private_module_function,
1662
      :commands, :options, :have_option?, :options_of, :collect_method]
1663

  
1716 1664
  #
1717
  #   :pwd, :getwd, :cd, :chdir,
1718
  #   :uptodate?, :copy_entry, :copy_file, :copy_stream, :remove_entry_secure,
1719
  #   :remove_entry, :remove_file, :remove_dir, :compare_file, :identical?,
1720
  #   :cmp, :compare_stream
1665
  # This module has all methods of FileUtils module, but it outputs messages
1666
  # before acting.  This equates to passing the <tt>:verbose</tt> flag to
1667
  # methods in FileUtils.
1721 1668
  #
1722
  # DEPRECATED - Only here for backward compatibility.
1723
  LOW_METHODS = (commands - collect_method(:noop)).map(&:to_sym)
1669
  module Verbose
1670
    include FileUtils
1671
    @fileutils_output  = $stderr
1672
    @fileutils_label   = ''
1673
    ::FileUtils.collect_method(:verbose).each do |name|
1674
      module_eval(<<-EOS, __FILE__, __LINE__ + 1)
1675
        def #{name}(*args)
1676
          super(*fu_update_option(args, :verbose => true))
1677
        end
1678
        private :#{name}
1679
      EOS
1680
    end
1681
    extend self
1682
    class << self
1683
      ::FileUtils::METHODS.each do |m|
1684
        public m
1685
      end
1686
    end
1687
  end
1724 1688

  
1689
  #
1690
  # This module has all methods of FileUtils module, but never changes
1691
  # files/directories.  This equates to passing the <tt>:noop</tt> flag
1692
  # to methods in FileUtils.
1693
  #
1694
  module NoWrite
1695
    include FileUtils
1696
    include LowMethods
1697
    @fileutils_output  = $stderr
1698
    @fileutils_label   = ''
1699
    ::FileUtils.collect_method(:noop).each do |name|
1700
      module_eval(<<-EOS, __FILE__, __LINE__ + 1)
1701
        def #{name}(*args)
1702
          super(*fu_update_option(args, :noop => true))
1703
        end
1704
        private :#{name}
1705
      EOS
1706
    end
1707
    extend self
1708
    class << self
1709
      ::FileUtils::METHODS.each do |m|
1710
        public m
1711
      end
1712
    end
1713
  end
1725 1714

  
1726
  # METHODS
1727 1715
  #
1728
  #   :pwd, :getwd, :cd, :chdir, :uptodate?, :mkdir, :mkdir_p, :mkpath, :makedirs,
1729
  #   :rmdir, :ln, :link, :ln_s, :symlink, :ln_sf, :cp, :copy, :cp_r, :copy_entry,
1730
  #   :copy_file, :copy_stream, :mv, :move, :rm, :remove, :rm_f, :safe_unlink,
1731
  #   :rm_r, :rm_rf, :rmtree, :remove_entry_secure, :remove_entry, :remove_file,
1732
  #   :remove_dir, :compare_file, :identical?, :cmp, :compare_stream, :install,
1733
  #   :chmod, :chmod_R, :chown, :chown_R, :touch
1716
  # This module has all methods of FileUtils module, but never changes
1717
  # files/directories, with printing message before acting.
1718
  # This equates to passing the <tt>:noop</tt> and <tt>:verbose</tt> flag
1719
  # to methods in FileUtils.
1734 1720
  #
1735
  # DEPRECATED - Only here for backward compatibility.
1736
  METHODS = commands.map(&:to_sym)
1721
  module DryRun
1722
    include FileUtils
1723
    include LowMethods
1724
    @fileutils_output  = $stderr
1725
    @fileutils_label   = ''
1726
    ::FileUtils.collect_method(:noop).each do |name|
1727
      module_eval(<<-EOS, __FILE__, __LINE__ + 1)
1728
        def #{name}(*args)
1729
          super(*fu_update_option(args, :noop => true, :verbose => true))
1730
        end
1731
        private :#{name}
1732
      EOS
1733
    end
1734
    extend self
1735
    class << self
1736
      ::FileUtils::METHODS.each do |m|
1737
        public m
1738
      end
1739
    end
1740
  end
1737 1741

  
1738 1742
end
test/fileutils/test_dryrun.rb (working copy)
2 2

  
3 3
require 'fileutils'
4 4
require 'test/unit'
5
require_relative 'clobber'
5
require_relative 'visibility_tests'
6 6

  
7 7
class TestFileUtilsDryRun < Test::Unit::TestCase
8 8

  
9 9
  include FileUtils::DryRun
10
  include TestFileUtils::Clobber
10
  include TestFileUtils::Visibility
11 11

  
12
  FileUtils::METHODS.each do |m|
13
    define_method "test_singleton_visibility_#{m}" do
14
      assert_equal true, FileUtils::DryRun.respond_to?(m, true),
15
                   "FileUtils::DryRun.#{m} not defined"
16
      assert_equal true, FileUtils::DryRun.respond_to?(m, false),
17
                   "FileUtils::DryRun.#{m} not public"
18
    end
19

  
20
    define_method "test_instance_visibility_#{m}" do
21
      assert_equal true, respond_to?(m, true),
22
                   "FileUtils::DryRun\##{m} is not defined"
23
      assert_equal true, FileUtils::DryRun.private_method_defined?(m),
24
                   "FileUtils::DryRun\##{m} is not private"
25
    end
12
  def setup
13
    super
14
    @fu_module = FileUtils::DryRun
26 15
  end
27 16

  
28 17
end
test/fileutils/test_nowrite.rb (working copy)
2 2

  
3 3
require 'fileutils'
4 4
require 'test/unit'
5
require_relative 'clobber'
5
require_relative 'visibility_tests'
6 6

  
7 7
class TestFileUtilsNoWrite < Test::Unit::TestCase
8 8

  
9 9
  include FileUtils::NoWrite
10
  include TestFileUtils::Clobber
10
  include TestFileUtils::Visibility
11 11

  
12
  FileUtils::METHODS.each do |m|
13
    define_method "test_singleton_visibility_#{m}" do
14
      assert_equal true, FileUtils::NoWrite.respond_to?(m, true),
15
                   "FileUtils::NoWrite.#{m} is not defined"
16
      assert_equal true, FileUtils::NoWrite.respond_to?(m, false),
17
                   "FileUtils::NoWrite.#{m} is not public"
18
    end
19

  
20
    define_method "test_instance_visibility_#{m}" do
21
      assert_equal true, respond_to?(m, true),
22
                   "FileUtils::NoWrite\##{m} is not defined"
23
      assert_equal true, FileUtils::NoWrite.private_method_defined?(m),
24
                   "FileUtils::NoWrite\##{m} is not private"
25
    end
12
  def setup
13
    super
14
    @fu_module = FileUtils::NoWrite
26 15
  end
27 16

  
28 17
end
test/fileutils/test_verbose.rb (working copy)
2 2

  
3 3
require 'test/unit'
4 4
require 'fileutils'
5
require_relative 'visibility_tests'
5 6

  
6 7
class TestFileUtilsVerbose < Test::Unit::TestCase
7 8

  
8 9
  include FileUtils::Verbose
10
  include TestFileUtils::Visibility
9 11

  
10
  FileUtils::METHODS.each do |m|
11
    define_method "test_singleton_visibility_#{m}" do
12
      assert_equal true, FileUtils::Verbose.respond_to?(m, true),
13
                   "FileUtils::Verbose.#{m} is not defined"
14
      assert_equal true, FileUtils::Verbose.respond_to?(m, false),
15
                   "FileUtils::Verbose.#{m} is not public"
16
    end
17

  
18
    define_method "test_visibility_#{m}" do
19
      assert_equal true, respond_to?(m, true),
20
                   "FileUtils::Verbose\##{m} is not defined"
21
      assert_equal true, FileUtils::Verbose.private_method_defined?(m),
22
                   "FileUtils::Verbose\##{m} is not private"
23
    end
12
  def setup
13
    super
14
    @fu_module = FileUtils::Verbose
24 15
  end
25 16

  
26 17
end
test/fileutils/visibility_tests.rb (working copy)
1
require 'test/unit'
2
require 'fileutils'
3

  
4
class TestFileUtils < Test::Unit::TestCase
5
end
6

  
7
##
8
# These tests are reused in the FileUtils::Verbose, FileUtils::NoWrite and
9
# FileUtils::DryRun tests
10

  
11
module TestFileUtils::Visibility
12

  
13
  FileUtils::METHODS.each do |m|
14
    define_method "test_singleton_visibility_#{m}" do
15
      assert @fu_module.respond_to?(m, true),
16
             "FileUtils::Verbose.#{m} is not defined"
17
      assert @fu_module.respond_to?(m, false),
18
             "FileUtils::Verbose.#{m} is not public"
19
    end
20

  
21
    define_method "test_visibility_#{m}" do
22
      assert respond_to?(m, true),
23
             "FileUtils::Verbose\##{m} is not defined"
24
      assert @fu_module.private_method_defined?(m),
25
             "FileUtils::Verbose\##{m} is not private"
26
    end
27
  end
28

  
29
  FileUtils::StreamUtils_.private_instance_methods.each do |m|
30
    define_method "test_singleton_visibility_#{m}" do
31
      assert @fu_module.respond_to?(m, true),
32
             "FileUtils::Verbose\##{m} is not defined"
33
    end
34

  
35
    define_method "test_visibility_#{m}" do
36
      assert respond_to?(m, true),
37
             "FileUtils::Verbose\##{m} is not defined"
38
    end
39
  end
40

  
41
end