This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Need @INC = '../lib' mantra
[perl5.git] / t / op / groups.t
index 824e88d..4d3dcaf 100755 (executable)
@@ -3,6 +3,31 @@
 $ENV{PATH} ="/bin:/usr/bin:/usr/xpg4/bin:/usr/ucb" .
     exists $ENV{PATH} ? ":$ENV{PATH}" : "";
 $ENV{LC_ALL} = "C"; # so that external utilities speak English
+$ENV{LANGUAGE} = 'C'; # GNU locale extension
+
+BEGIN {
+    chdir 't';
+    @INC = '../lib';
+
+    require Config;
+    if ($@) {
+       print "1..0 # Skip: no Config\n";
+    } else {
+       Config->import;
+    }
+}
+
+sub quit {
+    print "1..0 # Skip: no `id` or `groups`\n";
+    exit 0;
+}
+
+unless (eval { getgrgid(0); 1 }) {
+    print "1..0 # Skip: getgrgid() not implemented\n";
+    exit 0;
+}
+
+quit() if (($^O eq 'MSWin32' || $^O eq 'NetWare') or $^O =~ /lynxos/i);
 
 # We have to find a command that prints all (effective
 # and real) group names (not ids).  The known commands are:
@@ -48,16 +73,19 @@ GROUPS: {
 #
 # If these tests fail, report the particular incantation you use
 # on this platform to find *all* the groups that an arbitrary
-# luser may belong to, using the 'perlbug' program.
+# user may belong to, using the 'perlbug' program.
 EOM
        }
        last GROUPS;
     }
     # Okay, not today.
-    print "1..0\n";
-    exit 0;
+    quit();
 }
 
+chomp($groups);
+
+print "# groups = $groups\n";
+
 # Remember that group names can contain whitespace, '-', et cetera.
 # That is: do not \w, do not \S.
 if ($groups =~ /groups=(.+)( [ug]id=|$)/) {
@@ -67,11 +95,11 @@ if ($groups =~ /groups=(.+)( [ug]id=|$)/) {
     # prefer names over numbers
     for (@g0) {
         # 42(zot me)
-       if (/^(\d+)(?:\(([^)]+)\))?$/) {
+       if (/^(\d+)(?:\(([^)]+)\))?/) {
            push @g1, ($2 || $1);
        }
         # zot me(42)
-       elsif (/^([^(]*)\((\d+)\)$/) {
+       elsif (/^([^(]*)\((\d+)\)/) {
            push @g1, ($1 || $2);
        }
        else {
@@ -88,10 +116,15 @@ print "1..2\n";
 
 $pwgid = $( + 0;
 ($pwgnam) = getgrgid($pwgid);
-@basegroup{$pwgid,$pwgnam} = (1,1);
-
+if ($Config{myuname} =~ /^cygwin_nt/i) { # basegroup on CYGWIN_NT has id = 0.
+    @basegroup{$pwgid,$pwgnam} = (0,0);
+} else {
+    @basegroup{$pwgid,$pwgnam} = (1,1);
+}
 $seen{$pwgid}++;
 
+print "# pwgid = $pwgid, pwgnam = $pwgnam\n";
+
 for (split(' ', $()) {
     next if $seen{$_}++;
     ($group) = getgrgid($_);
@@ -103,7 +136,10 @@ for (split(' ', $()) {
     }
 } 
 
-if ($^O eq "uwin") { # Or anybody else who can have spaces in group names.
+print "# gr = @gr\n";
+
+if ($^O =~ /^(?:uwin|solaris)$/) {
+       # Or anybody else who can have spaces in group names.
        $gr1 = join(' ', grep(!$did{$_}++, sort split(' ', join(' ', @gr))));
 } else {
        $gr1 = join(' ', sort @gr);
@@ -111,7 +147,7 @@ if ($^O eq "uwin") { # Or anybody else who can have spaces in group names.
 
 $gr2 = join(' ', grep(!$basegroup{$_}++, sort split(' ',$groups)));
 
-if ($gr1 eq $gr2) {
+if ($gr1 eq $gr2 || ($gr1 eq '' && $gr2 eq $pwgid)) {
     print "ok 1\n";
 }
 else {