1#!/usr/bin/perl 2 3use strict; 4 5use Test::More; 6use lib 't'; 7use Test::Utils; 8use File::Spec::Functions qw( :ALL ); 9 10my %tests = ( 11'grepmail -l Handy t/mailboxes/mailarc-1.txt t/mailboxes/mailarc-2.txt' 12 => ['list_handy','none'], 13'grepmail -e Handy -l t/mailboxes/mailarc-1.txt t/mailboxes/mailarc-2.txt' 14 => ['list_handy','none'], 15"grepmail -l -E $single_quote\$email =~ /Handy/$single_quote t/mailboxes/mailarc-1.txt t/mailboxes/mailarc-2.txt" 16 => ['list_handy','none'], 17"grepmail -E $single_quote\$email =~ /Handy/$single_quote -l t/mailboxes/mailarc-1.txt t/mailboxes/mailarc-2.txt" 18 => ['list_handy','none'], 19'grepmail -l Handy t/mailboxes/mailarc-1-dos.txt t/mailboxes/mailarc-2.txt' 20 => ['list_handy_dos','none'], 21); 22 23my %expected_errors = ( 24); 25 26mkdir 't/temp', 0700; 27 28plan tests => scalar (keys %tests) * 2; 29 30my %skip = SetSkip(\%tests); 31 32foreach my $test (sort keys %tests) 33{ 34 print "Running test:\n $test\n"; 35 36 SKIP: 37 { 38 skip("$skip{$test}",2) if exists $skip{$test}; 39 40 TestIt($test, $tests{$test}, $expected_errors{$test}); 41 } 42} 43 44# --------------------------------------------------------------------------- 45 46sub TestIt 47{ 48 my $test = shift; 49 my ($stdout_file,$stderr_file) = @{ shift @_ }; 50 my $error_expected = shift; 51 52 my $testname = [splitdir($0)]->[-1]; 53 $testname =~ s#\.t##; 54 55 { 56 my @standard_inc = split /###/, `perl -e '\$" = "###";print "\@INC"'`; 57 my @extra_inc; 58 foreach my $inc (@INC) 59 { 60 push @extra_inc, "$single_quote$inc$single_quote" 61 unless grep { /^$inc$/ } @standard_inc; 62 } 63 64 local $" = ' -I'; 65 if (@extra_inc) 66 { 67 $test =~ s#\bgrepmail\s#$^X -I@extra_inc blib/script/grepmail -C t/temp/cache #g; 68 } 69 else 70 { 71 $test =~ s#\bgrepmail\s#$^X blib/script/grepmail -C t/temp/cache #g; 72 } 73 } 74 75 my $test_stdout = catfile('t','temp',"${testname}_$stdout_file.stdout"); 76 my $test_stderr = catfile('t','temp',"${testname}_$stderr_file.stderr"); 77 78 system "$test 1>$test_stdout 2>$test_stderr"; 79 80 if (!$? && defined $error_expected) 81 { 82 ok(0,"Did not encounter an error executing the test when one was expected.\n\n"); 83 return; 84 } 85 86 if ($? && !defined $error_expected) 87 { 88 ok(0, "Encountered an error executing the test when one was not expected.\n" . 89 "See $test_stdout and $test_stderr.\n\n"); 90 return; 91 } 92 93 94 my $real_stdout = catfile('t','results',$stdout_file); 95 my $real_stderr = catfile('t','results',$stderr_file); 96 97 Do_Diff($test_stdout,$real_stdout); 98 Do_Diff($test_stderr,$real_stderr); 99} 100 101# --------------------------------------------------------------------------- 102 103sub SetSkip 104{ 105 my %tests = %{ shift @_ }; 106 107 my %skip; 108 109 return %skip; 110} 111 112# --------------------------------------------------------------------------- 113 114