This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
whitespace-proof grent.t
[perl5.git] / t / op / grent.t
CommitLineData
c5987ebb
JH
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = "../lib" if -d "../lib";
6 eval { require Config; import Config; };
7
8 my $GR = "/etc/group";
9
10 if ($Config{'i_grp'} ne 'define' or not -f $GR or not open(GR, $GR)) {
11 print "1..0\n";
12 exit 0;
13 }
14}
15
16print "1..1\n";
17
18# Go through at most this many groups.
19my $max = 25; #
20
21my $n = 0;
22my $not;
23my $tst = 1;
24
25$not = 0;
26while (<GR>) {
27 last if $n == $max;
28 chomp;
29 @s = split /:/;
30 if (@s == 4) {
31 my ($name_s,$passwd_s,$gid_s,$members_s) = @s;
5e5f18aa 32 $members_s =~ s/\s*,\s*/,/g;
fc8a54e6
GS
33 $members_s =~ s/\s+$//;
34 $members_s =~ s/^\s+//;
c5987ebb
JH
35 @n = getgrgid($gid_s);
36 # 'nogroup' et al.
37 next unless @n;
38 my ($name,$passwd,$gid,$members) = @n;
39 # Protect against one-to-many and many-to-one mappings.
40 if ($name_s ne $name) {
41 @n = getgrnam($name_s);
42 ($name,$passwd,$gid,$members) = @n;
43 next if $name_s ne $name;
44 }
5e5f18aa 45 $members =~ s/\s+/,/g;
c5987ebb
JH
46 $not = 1, last
47 if $name ne $name_s or
48# Shadow passwords confuse this.
49# $passwd ne $passwd_s or
50 $gid ne $gid_s or
51 $members ne $members_s;
52 }
53 $n++;
54}
55
56print "not " if $not;
57print "ok ", $tst++, "\n";
58
59close(GR);