From: David Mitchell Date: Sat, 20 Feb 2010 19:34:05 +0000 (+0000) Subject: stop op/groups.t skipping on Linux X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=67d13d020f12d3ee57eba5c0a0265a692cf02e3f;p=p5sagit%2Fp5-mst-13.2.git stop op/groups.t skipping on Linux My linux (with selinux) includes a "context=" field as part of the output of "id -a". Make the extraction of the "groups=(.+)" entry of "id -a" more robust in the presence of unpredictable (in name and ordering) fields, by splitting on fieldname=(.*), then looking for a field name of 'groups'. --- diff --git a/t/op/groups.t b/t/op/groups.t index 5227014..c1cc889 100644 --- a/t/op/groups.t +++ b/t/op/groups.t @@ -203,6 +203,9 @@ sub _system_groups { # uid=39957(gsar) gid=22(users) groups=33536,39181,22(users),0(root),1067(dev) # FreeBSD since 6.2 has a fake id -a: # uid=1001(tobez) gid=20(staff) groups=20(staff), 0(wheel), 68(dialer) + # + # Linux may also have a context= field + return ( $cmd, $str ); } @@ -243,9 +246,17 @@ sub extract_system_groups { # Remember that group names can contain whitespace, '-', '(parens)', # et cetera. That is: do not \w, do not \S. my @extracted; - if ($groups_string =~ /groups=(.+)( [ug]id=|$)/) { - my $gr = $1; + my @fields = split /\b(\w+=)/, $groups_string; + my $gr; + for my $i (0..@fields-2) { + if ($fields[$i] eq 'groups=') { + $gr = $fields[$i+1]; + $gr =~ s/ $//; + last; + } + } + if (defined $gr) { my @g = split m{, ?}, $gr; # prefer names over numbers for (@g) {