summaryrefslogtreecommitdiff
path: root/test/fileutils
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-01 16:16:05 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-01 16:16:05 +0000
commit0a1e7d1568584f22f743347c5e3b64dbf705dd83 (patch)
treeca5212186edf7edf56bde3e4f8540979061f220a /test/fileutils
parent0468df6249fa9ec94217f87f4213a8e1032c67f5 (diff)
* lib/fileutils.rb (FileUtils#chmod): accept symbolic mode argument.
The patch was written by takkanm. [ruby-core:26029][Feature #2190] * lib/fileutils.rb (FileUtils#fu_mode): new helper function. * lib/fileutils.rb (FileUtils#symbolic_modes_to_i): ditto. * lib/fileutils.rb (FileUtils#mode_mask): ditto. * lib/fileutils.rb (FileUtils#user_mask): ditto. * test/fileutils/test_fileutils.rb (TestFileUtils#test_chmod_symbol_mode): new test for the above symbolic mode. * test/fileutils/test_fileutils.rb (TestFileUtils#test_chmod_R): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/fileutils')
-rw-r--r--test/fileutils/test_fileutils.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb
index 290ba21..68f3631 100644
--- a/test/fileutils/test_fileutils.rb
+++ b/test/fileutils/test_fileutils.rb
@@ -893,6 +893,29 @@ class TestFileUtils
assert_equal 0500, File.stat('tmp/a').mode & 0777
end if have_file_perm?
+ def test_chmod_symbol_mode
+ check_singleton :chmod
+
+ touch 'tmp/a'
+ chmod "u=wrx,g=,o=", 'tmp/a'
+ assert_equal 0700, File.stat('tmp/a').mode & 0777
+ chmod "u=rx,go=", 'tmp/a'
+ assert_equal 0500, File.stat('tmp/a').mode & 0777
+ chmod "+wrx", 'tmp/a'
+ assert_equal 0777, File.stat('tmp/a').mode & 0777
+ chmod "u+s,o=s", 'tmp/a'
+ assert_equal 04770, File.stat('tmp/a').mode & 07777
+ chmod "u-w,go-wrx", 'tmp/a'
+ assert_equal 04500, File.stat('tmp/a').mode & 07777
+ chmod "+s", 'tmp/a'
+ assert_equal 06500, File.stat('tmp/a').mode & 07777
+ chmod "u+t,o+t", 'tmp/a'
+ assert_equal 07500, File.stat('tmp/a').mode & 07777
+ chmod "a-t,a-s", 'tmp/a'
+ assert_equal 0500, File.stat('tmp/a').mode & 07777
+ end if have_file_perm?
+
+
def test_chmod_R
check_singleton :chmod_R
@@ -911,6 +934,24 @@ class TestFileUtils
chmod_R 0700, 'tmp/dir' # to remove
end if have_file_perm?
+ def test_chmod_symbol_mode_R
+ check_singleton :chmod_R
+
+ mkdir_p 'tmp/dir/dir'
+ touch %w( tmp/dir/file tmp/dir/dir/file )
+ chmod_R "u=wrx,g=,o=", 'tmp/dir'
+ assert_equal 0700, File.stat('tmp/dir').mode & 0777
+ assert_equal 0700, File.stat('tmp/dir/file').mode & 0777
+ assert_equal 0700, File.stat('tmp/dir/dir').mode & 0777
+ assert_equal 0700, File.stat('tmp/dir/dir/file').mode & 0777
+ chmod_R "u=xr,g+X,o=", 'tmp/dir'
+ assert_equal 0510, File.stat('tmp/dir').mode & 0777
+ assert_equal 0500, File.stat('tmp/dir/file').mode & 0777
+ assert_equal 0510, File.stat('tmp/dir/dir').mode & 0777
+ assert_equal 0500, File.stat('tmp/dir/dir/file').mode & 0777
+ chmod_R 0700, 'tmp/dir' # to remove
+ end if have_file_perm?
+
# FIXME: How can I test this method?
def test_chown
check_singleton :chown