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