integrate cfgperl contents into mainline
[p5sagit/p5-mst-13.2.git] / t / op / pwent.t
index cd5db34..ca14a99 100755 (executable)
@@ -3,14 +3,19 @@
 BEGIN {
     chdir 't' if -d 't';
     unshift @INC, "../lib" if -d "../lib";
-    eval { require Config; import Config; };
-
-    unless (defined $Config{'i_pwd'} &&
-                   $Config{'i_pwd'} eq 'define' &&
-           -f "/etc/passwd" ) { # Play safe.
-       print "1..0\n";
+    eval {my @n = getpwuid 0};
+    if ($@ && $@ =~ /(The \w+ function is unimplemented)/) {
+       print "1..0 # Skip: $1\n";
        exit 0;
     }
+    eval { require Config; import Config; };
+    my $reason;
+    if ($Config{'i_pwd'} ne 'define') {
+       $reason = '$Config{i_pwd} undefined';
+    }
+    elsif (not -f "/etc/passwd" ) { # Play safe.
+       $reason = 'no /etc/passwd file';
+    }
 
     if (not defined $where) {  # Try NIS.
        foreach my $ypcat (qw(/usr/bin/ypcat /bin/ypcat /etc/ypcat)) {
@@ -18,6 +23,7 @@ BEGIN {
                open(PW, "$ypcat passwd 2>/dev/null |") &&
                defined(<PW>)) {
                $where = "NIS passwd";
+               undef $reason;
                last;
            }
        }
@@ -29,6 +35,7 @@ BEGIN {
                open(PW, "$nidump passwd . 2>/dev/null |") &&
                defined(<PW>)) {
                $where = "NetInfo passwd";
+               undef $reason;
                last;
            }
        }
@@ -38,11 +45,12 @@ BEGIN {
        my $PW = "/etc/passwd";
        if (-f $PW && open(PW, $PW) && defined(<PW>)) {
            $where = $PW;
+           undef $reason;
        }
     }
 
-    if (not defined $where) {  # Give up.
-       print "1..0\n";
+    if ($reason) {     # Give up.
+       print "1..0 # Skip: $reason\n";
        exit 0;
     }
 }
@@ -71,7 +79,11 @@ while (<PW>) {
        warn "# Your $where line $. is empty.\n";
        next;
     }
-    last if $n == $max;
+    if ($n == $max) {
+       local $/;
+       my $junk = <PW>;
+       last;
+    }
     # In principle we could whine if @s != 7 but do we know enough
     # of passwd file formats everywhere?
     if (@s == 7) {