mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/fileutils/test_fileutils.rb (test_chown_R): Add tests for
chown_R. [Feature #9383][ruby-core:59641] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d76340fa68
commit
98fce6fea8
2 changed files with 110 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sun May 25 09:58:02 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
||||||
|
|
||||||
|
* 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@gmail.com>
|
Sun May 25 09:57:09 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
||||||
|
|
||||||
* test/fileutils/test_fileutils.rb: Added recursively chmod tests.
|
* test/fileutils/test_fileutils.rb: Added recursively chmod tests.
|
||||||
|
|
|
@ -1163,6 +1163,76 @@ class TestFileUtils < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
end
|
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?
|
if root_in_posix?
|
||||||
def test_chown_with_root
|
def test_chown_with_root
|
||||||
uid_1, uid_2 = distinct_uids(2)
|
uid_1, uid_2 = distinct_uids(2)
|
||||||
|
@ -1199,6 +1269,30 @@ class TestFileUtils < Test::Unit::TestCase
|
||||||
assert_ownership_user uid_1, 'tmp/dir/a'
|
assert_ownership_user uid_1, 'tmp/dir/a'
|
||||||
}
|
}
|
||||||
end
|
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
|
else
|
||||||
def test_chown_without_permission
|
def test_chown_without_permission
|
||||||
uid_1, uid_2 = distinct_uids(2)
|
uid_1, uid_2 = distinct_uids(2)
|
||||||
|
@ -1210,13 +1304,19 @@ class TestFileUtils < Test::Unit::TestCase
|
||||||
chown uid_2, nil, 'tmp/a'
|
chown uid_2, nil, 'tmp/a'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# FIXME: How can I test this method?
|
def test_chown_R_without_permission
|
||||||
def test_chown_R
|
uid_1, uid_2 = distinct_uids(2)
|
||||||
check_singleton :chown_R
|
return unless uid_1 and uid_2
|
||||||
end if have_file_perm?
|
|
||||||
|
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
|
||||||
|
|
||||||
def test_copy_entry
|
def test_copy_entry
|
||||||
check_singleton :copy_entry
|
check_singleton :copy_entry
|
||||||
|
|
Loading…
Add table
Reference in a new issue