diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-02-17 10:22:09 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-02-17 10:22:09 +0000 |
commit | 1ac36ecf0048efd1c19fa5c932b8f3a56bc466d6 (patch) | |
tree | 5492297de0c8e058b2df9c05dff72bcdc670182c /test/fileutils | |
parent | 68319db7acc4a49410a3f2cd31327fe96161f2b8 (diff) | |
download | bundler-1ac36ecf0048efd1c19fa5c932b8f3a56bc466d6.tar.gz |
test_fileutils.rb: cache distinct UIDs
* test/fileutils/test_fileutils.rb: cache distinct UIDs as
constants at initialization. assume no UIDs will be
added/removed during tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/fileutils')
-rw-r--r-- | test/fileutils/test_fileutils.rb | 55 |
1 files changed, 21 insertions, 34 deletions
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index f3b80d1fda..35b3f52cfa 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -122,6 +122,8 @@ class TestFileUtils < Test::Unit::TestCase include m extend m + UID_1, UID_2 = distinct_uids(2) + include FileUtils def check_singleton(name) @@ -1189,7 +1191,7 @@ class TestFileUtils < Test::Unit::TestCase if have_file_perm? def test_chown_error - uid, = distinct_uids(1) + uid = UID_1 return unless uid touch 'tmp/a' @@ -1301,14 +1303,11 @@ class TestFileUtils < Test::Unit::TestCase if root_in_posix? def test_chown_with_root - uid_1, uid_2 = distinct_uids(2) - return unless uid_1 and uid_2 - gid = @groups[0] # Most of the time, root only has one group files = ['tmp/a1', 'tmp/a2'] files.each {|file| touch file} - [uid_1, uid_2].each {|uid| + [UID_1, UID_2].each {|uid| assert_output_lines(["chown #{uid}:#{gid} tmp/a1 tmp/a2"]) { chown uid, gid, files, verbose: true files.each {|file| @@ -1320,69 +1319,57 @@ class TestFileUtils < Test::Unit::TestCase end def test_chown_dir_user_ownership_not_recursive_with_root - uid_1, uid_2 = distinct_uids(2) - return unless uid_1 and uid_2 - assert_output_lines([]) { mkdir 'tmp/dir' touch 'tmp/dir/a' - chown uid_1, nil, ['tmp/dir', 'tmp/dir/a'] - assert_ownership_user uid_1, 'tmp/dir' - assert_ownership_user uid_1, 'tmp/dir/a' - chown uid_2, nil, 'tmp/dir' - assert_ownership_user uid_2, 'tmp/dir' + chown UID_1, nil, ['tmp/dir', 'tmp/dir/a'] + assert_ownership_user UID_1, 'tmp/dir' + assert_ownership_user UID_1, 'tmp/dir/a' + chown UID_2, nil, 'tmp/dir' + assert_ownership_user UID_2, 'tmp/dir' # Make sure FileUtils.chown does not chown recursively - assert_ownership_user uid_1, 'tmp/dir/a' + 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' + chown_R UID_1, nil, 'tmp/dir' list.each {|dir| - assert_ownership_user uid_1, dir + assert_ownership_user UID_1, dir } - chown_R uid_1, nil, 'tmp/d' - assert_ownership_user uid_1, 'tmp/d' + 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'] + chown_R UID_2, nil, ['tmp/dir', 'tmp/d'] list += ['tmp/d'] list.each {|dir| - assert_ownership_user uid_2, dir + assert_ownership_user UID_2, dir } } end else def test_chown_without_permission - uid_1, uid_2 = distinct_uids(2) - return unless uid_1 and uid_2 - touch 'tmp/a' assert_raise(Errno::EPERM) { - chown uid_1, nil, 'tmp/a' - chown uid_2, nil, 'tmp/a' + chown UID_1, nil, 'tmp/a' + 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' + chown_R UID_1, nil, 'tmp/a' + chown_R UID_2, nil, 'tmp/a' } end end - end + end if UID_1 and UID_2 def test_copy_entry check_singleton :copy_entry |