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