This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add test for User::pwent.
[perl5.git] / t / 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;
14 $haspw = 0 unless $Config{'i_pwd'} eq 'define';
15 unless ($haspw) { print "1..0 # Skip: no pwd.h\n"; exit 0 }
16}
17
18BEGIN {
19 our @pwent = getpwuid 0; # This is the function getpwuid.
20 unless (@pwent) { print "1..0 # Skip: no uid 0\n"; exit 0 }
21}
22
23print "1..9\n";
24
25use User::pwent;
26
27print "ok 1\n";
28
29my $pwent = getpwuid 0; # This is the OO getpwuid.
30
31print "not " unless $pwent->uid == 0;
32print "ok 2\n";
33
34print "not " unless $pwent->name == $pwent[0];
35print "ok 3\n";
36
37print "not " unless $pwent->passwd eq $pwent[1];
38print "ok 4\n";
39
40print "not " unless $pwent->uid == $pwent[2];
41print "ok 5\n";
42
43print "not " unless $pwent->gid == $pwent[3];
44print "ok 6\n";
45
46# The quota and comment fields are unportable.
47
48print "not " unless $pwent->gecos eq $pwent[6];
49print "ok 7\n";
50
51print "not " unless $pwent->dir eq $pwent[7];
52print "ok 8\n";
53
54print "not " unless $pwent->shell eq $pwent[8];
55print "ok 9\n";
56
57# The expire field is unportable.
58
59# Testing pretty much anything else is unportable:
60# there maybe more than one username with uid 0;
61# uid 0's home directory may be "/" or "/root' or something else,
62# and so on.
63