tests/10-routing.t
changeset 9 db2a8a5b8202
equal deleted inserted replaced
8:44b39238d741 9:db2a8a5b8202
       
     1 #! /usr/bin/perl
       
     2 
       
     3 use strict;
       
     4 use warnings;
       
     5 use Test::More;
       
     6 use File::Basename;
       
     7 use FindBin qw($Bin);
       
     8 use Getopt::Long;
       
     9 use Pod::Usage;
       
    10 use if @ARGV > 0   => 'Data::Dumper';
       
    11 use if $ENV{DEBUG} => 'Smart::Comments';
       
    12 
       
    13 if (@ARGV) {
       
    14     GetOptions(
       
    15         'h|help' => sub { pod2usage -exit => 0, -verbose => 1 },
       
    16         'm|man'  => sub {
       
    17             pod2usage
       
    18               -exit      => 0,
       
    19               -verbose   => 2,
       
    20               -noperldoc => system('perldoc -V 2>/dev/null 1>/dev/null');
       
    21         },
       
    22       )
       
    23       and @ARGV
       
    24       or pod2usage;
       
    25 }
       
    26 
       
    27 use_ok 'Test::MTA::Exim4' or BAIL_OUT 'Unexpected!!!';
       
    28 isa_ok my $exim = Test::MTA::Exim4->new => 'Test::MTA::Exim4';
       
    29 
       
    30 if (@ARGV) {
       
    31     foreach my $address (@ARGV) {
       
    32         -d ($_ = "$Bin/samples/$address")
       
    33           or mkdir $_
       
    34           or -d "$Bin/samples"
       
    35           ? die "Can't create $_: $!\n"
       
    36           : "$Bin/samples directory missing\n";
       
    37 
       
    38         my $outfile = "$_/-bt";
       
    39 
       
    40         $_ = $exim->_run_exim_bt($address);
       
    41         open(my $f, '>', $outfile) or die "$0: Can't open $outfile: $!\n";
       
    42         ok print({$f} (Data::Dumper->Dump([$_], ['bt']))),
       
    43           "data for $address written";
       
    44     }
       
    45 
       
    46     done_testing;
       
    47     exit;
       
    48 }
       
    49 
       
    50 foreach (grep { -f "$_/-bt" } glob "$Bin/samples/*") {
       
    51     my $address = basename $_;
       
    52     my $bt      = do "$_/-bt";
       
    53     my @target;
       
    54     foreach (map { values %$_ } grep { ref } values %$bt) {
       
    55         delete $_->{data};
       
    56         delete $_->{original};
       
    57         push @target, $_;
       
    58     }
       
    59     $exim->routes_as_ok($address, \@target, $address);
       
    60 }
       
    61 
       
    62 done_testing;
       
    63 
       
    64 =head1 NAME
       
    65 
       
    66  10-routing.t - automated tests with Test::MTA::Exim4
       
    67 
       
    68 =head1 SYNOPSIS
       
    69 
       
    70  # learn mode
       
    71  DIRECTORY/10-routing.t ADDRESS...
       
    72 
       
    73  # test mode
       
    74  DIRECTORY/10-routing.t
       
    75  prove [DIRECTORY]
       
    76 
       
    77 =head1 AUTHOR
       
    78 
       
    79 Heiko Schlittermann L<hs@schlittermann.de>
       
    80 
       
    81 =cut
       
    82