[patch: perl@8211]VMS: add -Duseperlio capacity to configure.com
[p5sagit/p5-mst-13.2.git] / t / op / groups.t
index 78a748f..082d2d1 100755 (executable)
@@ -1,6 +1,16 @@
 #!./perl
 
-$ENV{PATH} = '/bin:/usr/bin:/usr/xpg4/bin:/usr/ucb';
+$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
+
+sub quit {
+    print "1..0 # Skip: no `id` or `groups`\n";
+    exit 0;
+}
+
+quit() if $^O eq 'MSWin32' or $^O =~ /lynxos/i;
 
 # We have to find a command that prints all (effective
 # and real) group names (not ids).  The known commands are:
@@ -11,6 +21,7 @@ $ENV{PATH} = '/bin:/usr/bin:/usr/xpg4/bin:/usr/ucb';
 # Beware 2: id -Gn or id -a format might be id(name) or name(id).
 # Beware 3: the groups= might be anywhere in the id output.
 # Beware 4: groups can have spaces ('id -a' being the only defense against this)
+# Beware 5: id -a might not contain the groups= part.
 #
 # That is, we might meet the following:
 #
@@ -28,7 +39,7 @@ GROUPS: {
     if (($groups = `id -a 2>/dev/null`) ne '') {
        # $groups is of the form:
        # uid=39957(gsar) gid=22(users) groups=33536,39181,22(users),0(root),1067(dev)
-       last GROUPS;
+       last GROUPS if $groups =~ /groups=/;
     }
     if (($groups = `id -Gn 2>/dev/null`) ne '') {
        # $groups could be of the form:
@@ -51,7 +62,11 @@ EOM
        last GROUPS;
     }
     # Okay, not today.
-    print "1..0\n";
+    quit();
+}
+
+unless (eval { getgrgid(0); 1 }) {
+    print "1..0 # Skip: getgrgid() not implemented\n";
     exit 0;
 }
 
@@ -64,11 +79,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 {
@@ -100,7 +115,8 @@ for (split(' ', $()) {
     }
 } 
 
-if ($^O eq "uwin") { # Or anybody else who can have spaces in group names.
+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);