# HG changeset patch # User Heiko Schlittermann (JUMPER) # Date 1422137629 -3600 # Node ID db2a8a5b82020c994d370dc23fbca874dd3dfe2b # Parent 44b39238d741a44395985882bfd1de7ffc753088 Switched to Test::MTA::Exim4 diff -r 44b39238d741 -r db2a8a5b8202 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sat Jan 24 23:13:49 2015 +0100 @@ -0,0 +1,2 @@ +syntax:glob +tests/samples/ diff -r 44b39238d741 -r db2a8a5b8202 Makefile --- a/Makefile Sat Jan 24 22:51:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -# primitive, but it's 0:12 am -# .hs - -all: - @perl -c check - -install: all - install -m 0755 -d /etc/exim4/bin - install -m 0755 check /etc/exim4/bin/ - perl -i -pe 's{^(# local source :).*$$}{$$1 $(shell pwd)}' /etc/exim4/bin/check diff -r 44b39238d741 -r db2a8a5b8202 check --- a/check Sat Jan 24 22:51:08 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,175 +0,0 @@ -#! /usr/bin/perl -# © Heiko Schlittermann -# global source: https://keller.schlittermann.de/hg/exim-checks -# local source : - -use strict; -use warnings; - -use File::Temp; -use File::Basename; -use Getopt::Long; -use Pod::Usage; -use FindBin qw($Bin); - -my $ME = basename $0; - -my $opt_init = 0; -my $opt_refresh = 0; -my $opt_dir = \'dirname($opt_config) . "/checks"'; - -my $opt_config = undef; -my $opt_exim = undef; - -sub slurp { local ($/, @ARGV) = (undef, @_); <> }; - -MAIN: { - - GetOptions( - "i|init" => \$opt_init, - "r|refresh" => \$opt_refresh, - "d|dir=s" => \$opt_dir, - "c|config=s" => \$opt_config, - "exim|binary=s" => \$opt_exim, - "h|help" => sub { pod2usage(-exitval => 0, -verbose => 1) }, - "m|man" => sub { pod2usage(-exitval => 0, -verbose => 3) }, - ) or pod2usage(); - - defined $opt_exim - or $opt_exim = ( - grep { -x } - map { ("$_/exim", "$_/exim4") } - qw( - /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin) - )[0] - or die "$ME: Can't find the exim(4) binary\n"; - - defined $opt_config - or $opt_config = ( - map { /.*\s(\S+)$/ && $1 } grep /Configuration file is\s+/, - qx/$opt_exim -v -bV/ - )[0] - or die "$ME: Can't find exim config\n"; - - $opt_dir = eval $$opt_dir if ref $opt_dir; - - print "% using $opt_config and dir $opt_dir\n"; - - if ($opt_init or $opt_refresh) { - foreach my $address (@ARGV) { - if ($opt_init) { - mkdir $_ = "$opt_dir/$address", 0777 - or die "Can't mkdir $_: $!\n"; - } - else { - -d ($_ = "$opt_dir/$address") or die "Can't find die $_: $!\n"; - } - foreach my $opt ("v", "t") { - my $file = "$opt_dir/$address/$opt"; - system("exim4 -C $opt_config -v -b$opt '$address' >$file"); - } - } - exit; - } - - foreach my $dir ( - @ARGV - ? map { /\// ? $_ : "$opt_dir/$_" } @ARGV - : glob("$opt_dir/*") - ) - { - my $address = basename $dir; - print "checking $address:"; - - for my $opt ("v", "t") { - - print $opt eq "v" ? " verify:" : " test:"; - - my $checkfile = "$dir/$opt"; - my $expect = slurp $checkfile; - my $result = qx/exim4 -C $opt_config -v -b$opt '$address'/; - - foreach ($expect, $result) { - s/^\s+host\s.*//m; - s/^\s+host\s.*//m; - } - - print "ok" and next if $result eq $expect; - - my $tmp_expect = new File::Temp; - my $tmp_result = new File::Temp; - - $tmp_expect->print($expect); - $tmp_result->print($result); - - print "* DIFFERS *\n"; - - $_ = join " " => "diff", "-u", - "--label=got", - "--label=expected", - $tmp_result->filename, - $tmp_expect->filename; - chomp; - - $_ = qx/$_/; - s/^/\t/mg; - print; - } - - print "\n"; - } -} - -__END__ - -=head1 NAME - -check - checks exim routing agains pre-defined values - -=head1 SYNOPSIS - - check [options] [
...] - - check [options] -i|--init
... - check [options] -r|--refresh
... - - check {-h|-m}|{--help|--man} - -=head1 DESCRIPTION - -This tools calls exim4 and checks the output of C> -and C> against some pre-defined values. - -=head1 OPTIONS - -=over 4 - -=item B<-c>|B<--config> I - -The location of the exim config to use. (default: autodetected by C) - -=item B<-d>|B<--dir> I - -The directory containing the checks (default: C) - -=item B<-i>|B<--init> I
- -Initialize the tests (run them for the first time and remember -the results. (default: not used) - -=item B<-r>|B<--refresh> I
- -Refresh the results (should be used after a verified change). -(default: not used) - -=item B<--exim> I - -The exim binary to use. This option should be rarely used. (default: -autodetected in some standard locations). - -=back - -=cut - -# vim:sts=4 sw=4 aw ai sm: diff -r 44b39238d741 -r db2a8a5b8202 tests/10-routing.t --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/10-routing.t Sat Jan 24 23:13:49 2015 +0100 @@ -0,0 +1,82 @@ +#! /usr/bin/perl + +use strict; +use warnings; +use Test::More; +use File::Basename; +use FindBin qw($Bin); +use Getopt::Long; +use Pod::Usage; +use if @ARGV > 0 => 'Data::Dumper'; +use if $ENV{DEBUG} => 'Smart::Comments'; + +if (@ARGV) { + GetOptions( + 'h|help' => sub { pod2usage -exit => 0, -verbose => 1 }, + 'm|man' => sub { + pod2usage + -exit => 0, + -verbose => 2, + -noperldoc => system('perldoc -V 2>/dev/null 1>/dev/null'); + }, + ) + and @ARGV + or pod2usage; +} + +use_ok 'Test::MTA::Exim4' or BAIL_OUT 'Unexpected!!!'; +isa_ok my $exim = Test::MTA::Exim4->new => 'Test::MTA::Exim4'; + +if (@ARGV) { + foreach my $address (@ARGV) { + -d ($_ = "$Bin/samples/$address") + or mkdir $_ + or -d "$Bin/samples" + ? die "Can't create $_: $!\n" + : "$Bin/samples directory missing\n"; + + my $outfile = "$_/-bt"; + + $_ = $exim->_run_exim_bt($address); + open(my $f, '>', $outfile) or die "$0: Can't open $outfile: $!\n"; + ok print({$f} (Data::Dumper->Dump([$_], ['bt']))), + "data for $address written"; + } + + done_testing; + exit; +} + +foreach (grep { -f "$_/-bt" } glob "$Bin/samples/*") { + my $address = basename $_; + my $bt = do "$_/-bt"; + my @target; + foreach (map { values %$_ } grep { ref } values %$bt) { + delete $_->{data}; + delete $_->{original}; + push @target, $_; + } + $exim->routes_as_ok($address, \@target, $address); +} + +done_testing; + +=head1 NAME + + 10-routing.t - automated tests with Test::MTA::Exim4 + +=head1 SYNOPSIS + + # learn mode + DIRECTORY/10-routing.t ADDRESS... + + # test mode + DIRECTORY/10-routing.t + prove [DIRECTORY] + +=head1 AUTHOR + +Heiko Schlittermann L + +=cut +