[前][次][番号順一覧][スレッド一覧]

ruby-changes:34011

From: hsbt <ko1@a...>
Date: Sun, 25 May 2014 09:59:00 +0900 (JST)
Subject: [ruby-changes:34011] hsbt:r46092 (trunk): * test/fileutils/test_fileutils.rb (test_chown_R): Add tests for

hsbt	2014-05-25 09:58:54 +0900 (Sun, 25 May 2014)

  New Revision: 46092

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=46092

  Log:
    * test/fileutils/test_fileutils.rb (test_chown_R): Add tests for
      chown_R. [Feature #9383][ruby-core:59641]

  Modified files:
    trunk/ChangeLog
    trunk/test/fileutils/test_fileutils.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46091)
+++ ChangeLog	(revision 46092)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun May 25 09:58:02 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
+
+	* test/fileutils/test_fileutils.rb (test_chown_R): Add tests for
+	  chown_R. [Feature #9383][ruby-core:59641]
+
 Sun May 25 09:57:09 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* test/fileutils/test_fileutils.rb: Added recursively chmod tests.
Index: test/fileutils/test_fileutils.rb
===================================================================
--- test/fileutils/test_fileutils.rb	(revision 46091)
+++ test/fileutils/test_fileutils.rb	(revision 46092)
@@ -1163,6 +1163,76 @@ class TestFileUtils < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L1163
       }
     end
 
+    def test_chown_R
+      check_singleton :chown_R
+
+      return unless @groups[1]
+
+      input_group_1 = @groups[0]
+      input_group_2 = @groups[1]
+      assert_output_lines([]) {
+        list = ['tmp/dir', 'tmp/dir/a', 'tmp/dir/a/b', 'tmp/dir/a/b/c']
+        mkdir_p 'tmp/dir/a/b/c'
+        touch 'tmp/d'
+        # string input
+        chown_R nil, input_group_1, 'tmp/dir'
+        list.each {|dir|
+          assert_ownership_group @groups[0], dir
+        }
+        chown_R nil, input_group_1, 'tmp/d'
+        assert_ownership_group @groups[0], 'tmp/d'
+        # list input
+        chown_R nil, input_group_2, ['tmp/dir', 'tmp/d']
+        list += ['tmp/d']
+        list.each {|dir|
+          assert_ownership_group @groups[1], dir
+        }
+      }
+    end
+
+    def test_chown_R_verbose
+      assert_output_lines(["chown -R :#{@groups[0]} tmp/dir tmp/d"]) {
+        list = ['tmp/dir', 'tmp/dir/a', 'tmp/dir/a/b', 'tmp/dir/a/b/c']
+        mkdir_p 'tmp/dir/a/b/c'
+        touch 'tmp/d'
+        chown_R nil, @groups[0], ['tmp/dir', 'tmp/d'], :verbose => true
+        list.each {|dir|
+          assert_ownership_group @groups[0], dir
+        }
+      }
+    end
+
+    def test_chown_R_noop
+      return unless @groups[1]
+
+      assert_output_lines([]) {
+        list = ['tmp/dir', 'tmp/dir/a', 'tmp/dir/a/b', 'tmp/dir/a/b/c']
+        mkdir_p 'tmp/dir/a/b/c'
+        chown_R nil, @groups[0], 'tmp/dir', :noop => false
+        list.each {|dir|
+          assert_ownership_group @groups[0], dir
+        }
+        chown_R nil, @groups[1], 'tmp/dir', :noop => true
+        list.each {|dir|
+          assert_ownership_group @groups[0], dir
+        }
+      }
+    end
+
+    def test_chown_R_force
+      assert_output_lines([]) {
+        list = ['tmp/dir', 'tmp/dir/a', 'tmp/dir/a/b', 'tmp/dir/a/b/c']
+        mkdir_p 'tmp/dir/a/b/c'
+        assert_raise_with_message(Errno::ENOENT, /No such file or directory/) {
+            chown_R nil, @groups[0], ['tmp/dir', 'invalid'], :force => false
+        }
+        chown_R nil, @groups[0], ['tmp/dir', 'invalid'], :force => true
+        list.each {|dir|
+          assert_ownership_group @groups[0], dir
+        }
+      }
+    end
+
     if root_in_posix?
       def test_chown_with_root
         uid_1, uid_2 = distinct_uids(2)
@@ -1199,6 +1269,30 @@ class TestFileUtils < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L1269
           assert_ownership_user uid_1, 'tmp/dir/a'
         }
       end
+
+      def test_chown_R_with_root
+        uid_1, uid_2 = distinct_uids(2)
+        return unless uid_1 and uid_2
+
+        assert_output_lines([]) {
+          list = ['tmp/dir', 'tmp/dir/a', 'tmp/dir/a/b', 'tmp/dir/a/b/c']
+          mkdir_p 'tmp/dir/a/b/c'
+          touch 'tmp/d'
+          # string input
+          chown_R uid_1, nil, 'tmp/dir'
+          list.each {|dir|
+            assert_ownership_user uid_1, dir
+          }
+          chown_R uid_1, nil, 'tmp/d'
+          assert_ownership_user uid_1, 'tmp/d'
+          # list input
+          chown_R uid_2, nil, ['tmp/dir', 'tmp/d']
+          list += ['tmp/d']
+          list.each {|dir|
+            assert_ownership_user uid_2, dir
+          }
+        }
+      end
     else
       def test_chown_without_permission
         uid_1, uid_2 = distinct_uids(2)
@@ -1210,14 +1304,20 @@ class TestFileUtils < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L1304
           chown uid_2, nil, 'tmp/a'
         }
       end
+
+      def test_chown_R_without_permission
+        uid_1, uid_2 = distinct_uids(2)
+        return unless uid_1 and uid_2
+
+        touch 'tmp/a'
+        exception = assert_raise(Errno::EPERM) {
+          chown_R uid_1, nil, 'tmp/a'
+          chown_R uid_2, nil, 'tmp/a'
+        }
+      end
     end
   end
 
-  # FIXME: How can I test this method?
-  def test_chown_R
-    check_singleton :chown_R
-  end if have_file_perm?
-
   def test_copy_entry
     check_singleton :copy_entry
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]