ruby-changes:32285
From: nobu <ko1@a...>
Date: Mon, 23 Dec 2013 18:37:33 +0900 (JST)
Subject: [ruby-changes:32285] nobu:r44364 (trunk): test_fileutils.rb: tests for chown
nobu 2013-12-23 18:37:23 +0900 (Mon, 23 Dec 2013) New Revision: 44364 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44364 Log: test_fileutils.rb: tests for chown * test/fileutils/fileasserts.rb (assert_ownership_group): new assertion for group ownership. * test/fileutils/test_fileutils.rb (test_chown{,_verbose,_noop}): based on the patch by vajrasky (Vajrasky Kok) at [ruby-core:59281]. [Feature #9286] Modified files: trunk/ChangeLog trunk/test/fileutils/fileasserts.rb trunk/test/fileutils/test_fileutils.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 44363) +++ ChangeLog (revision 44364) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Dec 23 18:37:16 2013 Nobuyoshi Nakada <nobu@r...> + + * test/fileutils/fileasserts.rb (assert_ownership_group): new + assertion for group ownership. + + * test/fileutils/test_fileutils.rb (test_chown{,_verbose,_noop}): + based on the patch by vajrasky (Vajrasky Kok) at + [ruby-core:59281]. [Feature #9286] + Mon Dec 23 15:53:45 2013 Nobuyoshi Nakada <nobu@r...> * hash.c (HAS_EXTRA_STATES): warn extra states only when something Index: test/fileutils/test_fileutils.rb =================================================================== --- test/fileutils/test_fileutils.rb (revision 44363) +++ test/fileutils/test_fileutils.rb (revision 44364) @@ -1,6 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L1 # $Id$ require 'fileutils' +require 'etc' require_relative 'fileasserts' require 'pathname' require 'tmpdir' @@ -111,6 +112,7 @@ class TestFileUtils https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L112 def setup @prevdir = Dir.pwd + @groups = Process.groups tmproot = TMPROOT mymkdir tmproot unless File.directory?(tmproot) Dir.chdir tmproot @@ -1052,11 +1054,53 @@ class TestFileUtils https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L1054 } end if have_file_perm? - # FIXME: How can I test this method? def test_chown check_singleton :chown + + return unless @groups[1] + + input_group_1 = @groups[0] + assert_output_lines([]) { + touch 'tmp/a' + # integer input for group, nil for user + chown nil, input_group_1, 'tmp/a' + assert_ownership_group @groups[0], 'tmp/a' + } + + input_group_2 = Etc.getgrgid(@groups[1]).name + assert_output_lines([]) { + touch 'tmp/b' + # string input for group, -1 for user + chown -1, input_group_2, 'tmp/b' + assert_ownership_group @groups[1], 'tmp/b' + } end if have_file_perm? + def test_chown_verbose + assert_output_lines(["chown :#{@groups[0]} tmp/a1 tmp/a2"]) { + touch 'tmp/a1' + touch 'tmp/a2' + chown nil, @groups[0], ['tmp/a1', 'tmp/a2'], verbose: true + assert_ownership_group @groups[0], 'tmp/a1' + assert_ownership_group @groups[0], 'tmp/a2' + } + end if have_file_perm? + + def test_chown_noop + return unless @groups[1] + assert_output_lines([]) { + touch 'tmp/a' + chown nil, @groups[0], 'tmp/a', :noop => false + assert_ownership_group @groups[0], 'tmp/a' + chown nil, @groups[1], 'tmp/a', :noop => true + assert_ownership_group @groups[0], 'tmp/a' + chown nil, @groups[1], 'tmp/a' + assert_ownership_group @groups[1], 'tmp/a' + } + end if have_file_perm? + + # FIXME: Need to add test for chown with root account + # FIXME: How can I test this method? def test_chown_R check_singleton :chown_R Index: test/fileutils/fileasserts.rb =================================================================== --- test/fileutils/fileasserts.rb (revision 44363) +++ test/fileutils/fileasserts.rb (revision 44364) @@ -88,6 +88,15 @@ File modes expected to be equal: https://github.com/ruby/ruby/blob/trunk/test/fileutils/fileasserts.rb#L88 <#{'%0*o' % [width, mode2]}>: "#{file2}" EOT end + + def assert_ownership_group(expected, file) + actual = File.stat(file).gid + assert expected == actual, <<EOT +File group ownership of "#{file}" unexpected: + Expected: <#{expected}> + Actual: <#{actual}> +EOT + end end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/