]>
Commit | Line | Data |
---|---|---|
427c49bc A |
1 | #!/usr/bin/perl -w |
2 | # | |
d8f41ccd | 3 | # Copyright (c) 2006-2007,2012 Apple Inc. All Rights Reserved. |
427c49bc A |
4 | # |
5 | ||
6 | my $pid = $$; | |
7 | ||
8 | END { | |
9 | return unless $$ == $pid; | |
10 | rm_test($_) for @TOCLEAN; | |
11 | } | |
12 | ||
13 | use strict; | |
14 | use Test::More; | |
15 | use IPC::Run3; | |
16 | ||
17 | sub plan_security { | |
18 | ||
19 | unless (1) { | |
20 | plan skip_all => "security not installed"; | |
21 | exit; | |
22 | }; | |
23 | plan @_; | |
24 | } | |
25 | ||
26 | use Carp; | |
27 | our @TOCLEAN; | |
28 | END { | |
29 | return unless $$ == $pid; | |
30 | $SIG{__WARN__} = sub { 1 }; | |
31 | cleanup_test($_) for @TOCLEAN; | |
32 | } | |
33 | ||
34 | our $output = ''; | |
35 | ||
36 | sub build_test { | |
37 | my $xd = "/tmp/test-$pid"; | |
38 | my $security = 'security'; | |
39 | $ENV{HOME} = $xd; | |
40 | push @TOCLEAN, [$xd, $security]; | |
41 | return ($xd, $security); | |
42 | } | |
43 | ||
44 | sub rm_test { | |
45 | my ($xd, $security) = @{+shift}; | |
46 | #rmtree [$xd]; | |
47 | } | |
48 | ||
49 | sub cleanup_test { | |
50 | return unless $ENV{TEST_VERBOSE}; | |
51 | my ($xd, $security) = @{+shift}; | |
52 | } | |
53 | ||
54 | sub is_output { | |
55 | my ($security, $cmd, $arg, $expected, $test) = @_; | |
56 | $output = ''; | |
57 | run3([$security, $cmd, @$arg], \undef, \$output, \$output); | |
58 | # open(STDOUT, ">&STDERR") || die "couldn't dup strerr: $!"; | |
59 | # open(my $out, '-|', $security, $cmd, @$arg); | |
60 | # while (<$out>) { $output .= $_; } | |
61 | ||
62 | my $cmp = (grep {ref ($_) eq 'Regexp'} @$expected) | |
63 | ? \&is_deeply_like : \&is_deeply; | |
64 | @_ = ([sort split (/\r?\n/, $output)], [sort @$expected], $test || join(' ', $cmd, @$arg)); | |
65 | goto &$cmp; | |
66 | } | |
67 | ||
68 | 1; |