Skip to content

Commit

Permalink
Use test.pl functions in t/op/groups.t
Browse files Browse the repository at this point in the history
The test file was already loading test.pl, but not using any functions
other than skip_all(_if_miniperl).  This ports the rest of the test to
using note(), skip() and ok().

Diff is best read with -w and --color-words or --word-diff.
  • Loading branch information
ilmari committed Nov 18, 2016
1 parent 5107ee8 commit 51d89e3
Showing 1 changed file with 35 additions and 44 deletions.
79 changes: 35 additions & 44 deletions t/op/groups.t
Original file line number Diff line number Diff line change
Expand Up @@ -44,50 +44,49 @@ sub Test {
my $pwgid = $( + 0;
my ($pwgnam) = getgrgid($pwgid);
$pwgnam //= '';
print "# pwgid=$pwgid pwgnam=$pwgnam \$(=$(\n";
note "pwgid=$pwgid pwgnam=$pwgnam \$(=$(";

# Get perl's supplementary groups by looking at $(
my ( $gid_count, $all_perl_groups ) = perl_groups();
my %basegroup = basegroups( $pwgid, $pwgnam );
my @extracted_supplementary_groups = remove_basegroup( \ %basegroup, \ @extracted_groups );

print "1..2\n";
plan 2;


# Test: The supplementary groups in $( should match the
# getgroups(2) kernal API call.
#
my $ngroups_max = posix_ngroups_max();
if ( defined $ngroups_max && $ngroups_max < @extracted_groups ) {
# Some OSes (like darwin)but conceivably others might return
# more groups from `id -a' than can be handled by the
# kernel. On darwin, NGROUPS_MAX is 16 and 12 are taken up for
# the system already.
#
# There is more fall-out from this than just Perl's unit
# tests. You may be a member of a group according to Active
# Directory (or whatever) but the OS won't respect it because
# it's the 17th (or higher) group and there's no space to
# store your membership.
print "ok 1 # SKIP Your platform's `$groups_command' is broken\n";
}

elsif ( darwin() ) {
# darwin uses getgrouplist(3) or an Open Directory API within
# /usr/bin/id and /usr/bin/groups which while "nice" isn't
# accurate for this test. The hard, real, list of groups we're
# running in derives from getgroups(2) and is not dynamic but
# the Libc API getgrouplist(3) is.
#
# In practical terms, this meant that while `id -a' can be
# relied on in other OSes to purely use getgroups(2) and show
# us what's real, darwin will use getgrouplist(3) to show us
# what might be real if only we'd open a new console.
#
print "ok 1 # SKIP darwin's `${groups_command}' can't be trusted\n";
}
SKIP: {
my $ngroups_max = posix_ngroups_max();
if ( defined $ngroups_max && $ngroups_max < @extracted_groups ) {
# Some OSes (like darwin)but conceivably others might return
# more groups from `id -a' than can be handled by the
# kernel. On darwin, NGROUPS_MAX is 16 and 12 are taken up for
# the system already.
#
# There is more fall-out from this than just Perl's unit
# tests. You may be a member of a group according to Active
# Directory (or whatever) but the OS won't respect it because
# it's the 17th (or higher) group and there's no space to
# store your membership.
skip "Your platform's `$groups_command' is broken";
}

else {
if ( darwin() ) {
# darwin uses getgrouplist(3) or an Open Directory API within
# /usr/bin/id and /usr/bin/groups which while "nice" isn't
# accurate for this test. The hard, real, list of groups we're
# running in derives from getgroups(2) and is not dynamic but
# the Libc API getgrouplist(3) is.
#
# In practical terms, this meant that while `id -a' can be
# relied on in other OSes to purely use getgroups(2) and show
# us what's real, darwin will use getgrouplist(3) to show us
# what might be real if only we'd open a new console.
#
skip "darwin's `${groups_command}' can't be trusted";
}

# Read $( but ignore any groups in $( that we failed to parse
# successfully out of the `id -a` mess.
Expand All @@ -101,7 +100,6 @@ sub Test {
if ( match_groups( \ @supplementary_groups,
\ @extracted_supplementary_groups,
$pwgid ) ) {
print "ok 1\n";
$ok1 = 1;
}
elsif ( cygwin_nt() ) {
Expand All @@ -111,24 +109,17 @@ sub Test {
if ( match_groups( \ @supplementary_groups,
\ @extracted_supplementary_groups,
$pwgid ) ) {
print "ok 1 # This Cygwin behaves like Unix (Win2k?)\n";
note "This Cygwin behaves like Unix (Win2k?)";
$ok1 = 1;
}
}

unless ( $ok1 ) {
print "nok 1 (perl's `\$(' disagrees with `${groups_command}'\n";
}
ok $ok1, "perl's `\$(' agrees with `${groups_command}'";
}

# multiple 0's indicate GROUPSTYPE is currently long but should be short
$gid_count->{0} //= 0;
if ( 0 == $pwgid || $gid_count->{0} < 2 ) {
print "ok 2\n";
}
else {
print "not ok 2 (groupstype should be type short, not long)\n";
}
ok 0 == $pwgid || $gid_count->{0} < 2, "groupstype should be type short, not long";

return;
}
Expand Down Expand Up @@ -258,7 +249,7 @@ sub extract_system_groups {
push @extracted, $+{gr_name} || $+{gid};
}
else {
print "# ignoring group entry [$_]\n";
note "ignoring group entry [$_]";
}
}

Expand Down

0 comments on commit 51d89e3

Please sign in to comment.