~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/fileutils/test_fileutils.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# $Id: test_fileutils.rb 28743 2010-07-24 10:38:16Z yugui $
 
1
# $Id: test_fileutils.rb 32709 2011-07-27 15:33:56Z naruse $
2
2
 
3
3
require 'fileutils'
4
4
require_relative 'fileasserts'
8
8
 
9
9
class TestFileUtils < Test::Unit::TestCase
10
10
  TMPROOT = "#{Dir.tmpdir}/fileutils.rb.#{$$}"
 
11
  include Test::Unit::FileAssertions
11
12
end
12
13
 
13
14
prevdir = Dir.pwd
229
230
    }
230
231
  end
231
232
 
 
233
  def test_cp_preserve_permissions
 
234
    bug4507 = '[ruby-core:35518]'
 
235
    touch 'tmp/cptmp'
 
236
    chmod 0755, 'tmp/cptmp'
 
237
    cp 'tmp/cptmp', 'tmp/cptmp2'
 
238
    assert_equal(File.stat('tmp/cptmp').mode,
 
239
                 File.stat('tmp/cptmp2').mode,
 
240
                 bug4507)
 
241
  end
 
242
 
232
243
  def test_cp_symlink
233
244
    touch 'tmp/cptmp'
234
245
    # src==dest (2) symlink and its target
882
893
    assert_equal 0500, File.stat('tmp/a').mode & 0777
883
894
  end if have_file_perm?
884
895
 
 
896
  def test_chmod_symbol_mode
 
897
    check_singleton :chmod
 
898
 
 
899
    touch 'tmp/a'
 
900
    chmod "u=wrx,g=,o=", 'tmp/a'
 
901
    assert_equal 0700, File.stat('tmp/a').mode & 0777
 
902
    chmod "u=rx,go=", 'tmp/a'
 
903
    assert_equal 0500, File.stat('tmp/a').mode & 0777
 
904
    chmod "+wrx", 'tmp/a'
 
905
    assert_equal 0777, File.stat('tmp/a').mode & 0777
 
906
    chmod "u+s,o=s", 'tmp/a'
 
907
    assert_equal 04770, File.stat('tmp/a').mode & 07777
 
908
    chmod "u-w,go-wrx", 'tmp/a'
 
909
    assert_equal 04500, File.stat('tmp/a').mode & 07777
 
910
    chmod "+s", 'tmp/a'
 
911
    assert_equal 06500, File.stat('tmp/a').mode & 07777
 
912
 
 
913
    # FreeBSD ufs and tmpfs don't allow to change sticky bit against
 
914
    # regular file. It's slightly strange. Anyway it's no effect bit.
 
915
    # see /usr/src/sys/ufs/ufs/ufs_chmod()
 
916
    # NetBSD and OpenBSD also denies it.
 
917
    if /freebsd|netbsd|openbsd/ !~ RUBY_PLATFORM
 
918
      chmod "u+t,o+t", 'tmp/a'
 
919
      assert_equal 07500, File.stat('tmp/a').mode & 07777
 
920
      chmod "a-t,a-s", 'tmp/a'
 
921
      assert_equal 0500, File.stat('tmp/a').mode & 07777
 
922
    end
 
923
 
 
924
  end if have_file_perm?
 
925
 
 
926
 
885
927
  def test_chmod_R
886
928
    check_singleton :chmod_R
887
929
 
900
942
    chmod_R 0700, 'tmp/dir'   # to remove
901
943
  end if have_file_perm?
902
944
 
 
945
  def test_chmod_symbol_mode_R
 
946
    check_singleton :chmod_R
 
947
 
 
948
    mkdir_p 'tmp/dir/dir'
 
949
    touch %w( tmp/dir/file tmp/dir/dir/file )
 
950
    chmod_R "u=wrx,g=,o=", 'tmp/dir'
 
951
    assert_equal 0700, File.stat('tmp/dir').mode & 0777
 
952
    assert_equal 0700, File.stat('tmp/dir/file').mode & 0777
 
953
    assert_equal 0700, File.stat('tmp/dir/dir').mode & 0777
 
954
    assert_equal 0700, File.stat('tmp/dir/dir/file').mode & 0777
 
955
    chmod_R "u=xr,g+X,o=", 'tmp/dir'
 
956
    assert_equal 0510, File.stat('tmp/dir').mode & 0777
 
957
    assert_equal 0500, File.stat('tmp/dir/file').mode & 0777
 
958
    assert_equal 0510, File.stat('tmp/dir/dir').mode & 0777
 
959
    assert_equal 0500, File.stat('tmp/dir/dir/file').mode & 0777
 
960
    chmod_R 0700, 'tmp/dir'   # to remove
 
961
  end if have_file_perm?
 
962
 
903
963
  # FIXME: How can I test this method?
904
964
  def test_chown
905
965
    check_singleton :chown