This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Don't prefix posix props with Is
[perl5.git] / lib / User / pwent.t
CommitLineData
c7506216
JH
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7
8BEGIN {
9 our $haspw;
10 eval { my @n = getpwuid 0 };
11 $haspw = 1 unless $@ && $@ =~ /unimplemented/;
12 unless ($haspw) { print "1..0 # Skip: no getpwuid\n"; exit 0 }
13 use Config;
8a1f71b2
PP
14 # VMS's pwd.h struct passwd conflicts with the one in vmsish.h
15 $haspw = 0 unless ( $Config{'i_pwd'} eq 'define' || $^O eq 'VMS' );
c7506216
JH
16 unless ($haspw) { print "1..0 # Skip: no pwd.h\n"; exit 0 }
17}
18
19BEGIN {
8a1f71b2
PP
20 our $uid = 0;
21 # On VMS getpwuid(0) may return [$gid,0] UIC info (which may not exist).
22 # It is better to use the $< uid for testing on VMS instead.
23 if ( $^O eq 'VMS' ) { $uid = $< ; }
d6c666a6 24 if ( $^O eq 'cygwin' ) { $uid = 500 ; }
8a1f71b2
PP
25 our @pwent = getpwuid $uid; # This is the function getpwuid.
26 unless (@pwent) { print "1..0 # Skip: no uid $uid\n"; exit 0 }
c7506216
JH
27}
28
29print "1..9\n";
30
31use User::pwent;
32
33print "ok 1\n";
34
8a1f71b2 35my $pwent = getpwuid $uid; # This is the OO getpwuid.
c7506216 36
8a1f71b2 37my $uid_expect = $uid;
5a356883
JP
38if ( $^O eq 'cygwin' ) {
39 print "not " unless ( $pwent->uid == $uid_expect
40 || $pwent->uid == 500 ); # go figure
41}
42else {
43 print "not " unless $pwent->uid == $uid_expect ;
44}
c7506216
JH
45print "ok 2\n";
46
598f41c0 47print "not " unless $pwent->name eq $pwent[0];
c7506216
JH
48print "ok 3\n";
49
598f41c0
JH
50if ($^O eq 'os390') {
51 print "not "
52 unless not defined $pwent->passwd &&
53 $pwent[1] eq '0'; # go figure
54} else {
55 print "not " unless $pwent->passwd eq $pwent[1];
56}
c7506216
JH
57print "ok 4\n";
58
59print "not " unless $pwent->uid == $pwent[2];
60print "ok 5\n";
61
62print "not " unless $pwent->gid == $pwent[3];
63print "ok 6\n";
64
65# The quota and comment fields are unportable.
66
67print "not " unless $pwent->gecos eq $pwent[6];
68print "ok 7\n";
69
70print "not " unless $pwent->dir eq $pwent[7];
71print "ok 8\n";
72
73print "not " unless $pwent->shell eq $pwent[8];
74print "ok 9\n";
75
76# The expire field is unportable.
77
78# Testing pretty much anything else is unportable:
79# there maybe more than one username with uid 0;
80# uid 0's home directory may be "/" or "/root' or something else,
81# and so on.
82