chiark / gitweb /
found on davenant in /usr/local/src/misc
[chiark-utils.git] / cprogs / really.testcases~
1 #!/usr/bin/perl
2
3 $testuser=   'testac';
4 $testgroup=  'testac';
5 $testuid=    1000;
6 $testgid=    1000;
7 @testxgids=  qw(1000);
8 $numgid=     50008;
9 $othergroup= 'daemon';
10 $othergid=   1;
11
12 $tests= <<END;
13 -u $testuser
14 $testuid $testgid @testxgids
15
16 -u $testuser -z
17 ERROR
18
19 -u $testuser -g $othergroup
20 $testuid $othergid @testxgids $othergid
21
22 -u $testuser -z -g $othergroup
23 $testuid $othergid $othergid
24
25 -u $testuser -G $numgid -g $othergroup
26 $testuid $numgid @testxgids $numgid $othergid
27
28 -u $testuser -z -G $numgid -g $othergroup
29 $testuid $numgid $numgid $othergid
30
31 -u $testuser -g $testgroup -G $testgid
32 $testuid $testgid @testxgids
33
34 -u $testuser -z -g $testgroup -G $testgid
35 $testuid $testgid @testxgids
36
37 -u $testuser -g $othergroup -g $testgroup -G $testgid
38 $testuid $othergid @testxgids $othergid
39
40 -u $testuser -z -g $othergroup -g $testgroup -G $testgid
41 $testuid $othergid $othergid
42
43 -u $testuser -G $numgid -g $othergroup -g $testgroup -G $testgid
44 $testuid $numgid @testxgids $numgid $othergid
45
46 -u $testuser -z -G $numgid -g $othergroup -g $testgroup -G $testgid
47 $testuid $numgid $numgid $othergid
48
49
50 0 $orggid @orgxgids
51
52 -z
53 ERROR
54
55 -g $othergroup
56 $orguid $othergid $othergid @orgxgids
57
58 -z -g $othergroup
59 $orguid $othergid $othergid
60
61 -G $numgid -g $othergroup
62 $orguid $numgid $numgid $othergid @orgxgids
63
64 -z -G $numgid -g $othergroup
65 $orguid $numgid $numgid $othergid
66
67 -g $orggroup -G $orggid
68 $orguid $orggid @orgxgids
69
70 -z -g $orggroup -G $orggid
71 $orguid $orggid $orggid
72
73 -g $othergroup -g $orggroup -G $orggid
74 $orguid $othergid $othergid @orgxgids
75
76 -z -g $othergroup -g $orggroup -G $orggid
77 $orguid $othergid $othergid $orggid
78
79 -G $numgid -g $othergroup -g $orggroup -G $orggid
80 $orguid $numgid $numgid $othergid @orgxgids
81
82 -z -G $numgid -g $othergroup -g $orggroup -G $orggid
83 $orguid $numgid $numgid $othergid
84 END
85
86 sub parseid ($) {
87     my ($id) = @_;
88     my $orgid= $id;
89     my $out= '';
90     my $part;
91     chomp($id);
92     $id =~ s/^uid=(\d+)// or return $orgid;
93     $out= $1;
94     $id =~ s/^\([^\)]+\)//; $id =~ s/^\s+// or return $orgid;
95     $id =~ s/^gid=(\d+)// or return $orgid;
96     $out.= " $1";
97     $id =~ s/^\([^\)]+\)//; $id =~ s/^\s+// or return $orgid;
98     $id =~ s/^groups=// or return $orgid;
99     for $part (split(/,/,$id)) {
100         $part =~ s/^(\d+)// or return $orgid;
101         $out.= " $1";
102         $part =~ s/^\([^\)]+\)//; $part eq '' or return $orgid;
103     }
104     return $out;
105 }
106
107 $org= `id`;
108 $org =~ m/^uid=\d+\(([^\)]+)\) gid=\d+\(([^\)]+)\) / or die "$org ?";
109 $orguser= $1; $orggroup= $2;
110 $org= parseid($org);
111 $org =~ m/^\d+ \d+ / or die $org;
112 ($orguid,$orggid,$orgxgids)= split(/ /,$org);
113
114 @tests= split(/\n/,$tests);
115 for ($i=0; $i<$#tests; $i+=3) {
116     $tests[$i+2] =~ m/\S/ and die "$tests[$i+2] $i";
117     $out= `./really-test $tests[$i] id`;
118     $newout= parseid($out);
119     next if $newout eq $tests[$i+1];
120     die "$newout ~= $tests[$i+1] ($tests[$i]) $i";
121 }