test_etc.rb: fix for non unique GID

* test/etc/test_etc.rb (TestEtc#test_getgrgid): fix for non unique GID.
  No unixen systems guarantee that GID is unique. Etc.getgrgid would
  not return the first entry in the order of Etc.group for shared GID.
  [ruby-core:47312] [Bug #6935]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shirosaki 2012-08-27 11:57:43 +00:00
parent 0b89d6d5f9
commit a5849245c6
2 changed files with 18 additions and 6 deletions

View File

@ -1,3 +1,10 @@
Mon Aug 27 20:19:49 2012 Hiroshi Shirosaki <h.shirosaki@gmail.com>
* test/etc/test_etc.rb (TestEtc#test_getgrgid): fix for non unique GID.
No unixen systems guarantee that GID is unique. Etc.getgrgid would
not return the first entry in the order of Etc.group for shared GID.
[ruby-core:47312] [Bug #6935]
Mon Aug 27 18:19:36 2012 Koichi Sasada <ko1@atdot.net> Mon Aug 27 18:19:36 2012 Koichi Sasada <ko1@atdot.net>
* include/ruby/ruby.h (rb_float_value): optimize it. * include/ruby/ruby.h (rb_float_value): optimize it.

View File

@ -76,13 +76,18 @@ class TestEtc < Test::Unit::TestCase
end end
def test_getgrgid def test_getgrgid
groups = {} # group database is not unique on GID, and which entry will be
Etc.group do |s| # returned by getgrgid() is not specified.
groups[s.gid] ||= s groups = Hash.new {[]}
# on MacOSX, same entries are returned from /etc/group and Open
# Directory.
Etc.group {|s| groups[s.gid] |= [s]}
groups.each_pair do |gid, s|
assert_include(s, Etc.getgrgid(gid))
end end
groups.each_value do |s| s = groups[Process.egid]
assert_equal(s, Etc.getgrgid(s.gid)) unless s.empty?
assert_equal(s, Etc.getgrgid) if Process.egid == s.gid assert_include(s, Etc.getgrgid)
end end
end end