mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bc159ec502
commit
e6847d1c55
3 changed files with 63 additions and 1 deletions
|
@ -1,3 +1,12 @@
|
|||
Mon Dec 23 18:37:16 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* hash.c (HAS_EXTRA_STATES): warn extra states only when something
|
||||
|
|
|
@ -86,6 +86,15 @@ EOT
|
|||
File modes expected to be equal:
|
||||
<#{'%0*o' % [width, mode1]}>: "#{file1}"
|
||||
<#{'%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
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# $Id$
|
||||
|
||||
require 'fileutils'
|
||||
require 'etc'
|
||||
require_relative 'fileasserts'
|
||||
require 'pathname'
|
||||
require 'tmpdir'
|
||||
|
@ -111,6 +112,7 @@ class TestFileUtils
|
|||
|
||||
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
|
|||
}
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue