[Rt-commit] r16190 - in rt/branches/3.999-DANGEROUS: t/maildigest

sunnavy at bestpractical.com sunnavy at bestpractical.com
Thu Oct 2 03:57:32 EDT 2008


Author: sunnavy
Date: Thu Oct  2 03:57:31 2008
New Revision: 16190

Modified:
   rt/branches/3.999-DANGEROUS/   (props changed)
   rt/branches/3.999-DANGEROUS/t/maildigest/attributes.t

Log:
 r16982 at sunnavys-mb:  sunnavy | 2008-10-02 15:57:15 +0800
 a bit refactor


Modified: rt/branches/3.999-DANGEROUS/t/maildigest/attributes.t
==============================================================================
--- rt/branches/3.999-DANGEROUS/t/maildigest/attributes.t	(original)
+++ rt/branches/3.999-DANGEROUS/t/maildigest/attributes.t	Thu Oct  2 03:57:31 2008
@@ -130,48 +130,35 @@
 is( $c_susp, 1, "correct number of suspended messages" );
 
 
-
-
-
 # Now let's actually run the daily and weekly digest tool to make sure we generate those
 
 # the first time get the content
-{open (my $digester, "-|", $RT::SbinPath."/rt-email-digest --mode daily --print");
-my @results = <$digester>;
-my $content = join ('', @results);
-like($content, qr/in the last day/);
-} {
+email_digest_like( '--mode daily --print', qr/in the last day/ );
 # The second time run it for real so we make sure that we get RT to mark the txn as sent
-open (my $digester, "-|", $RT::SbinPath."/rt-email-digest --mode daily");
-my @results = <$digester>;
-my $content = join ('', @results);
-like($content, qr/maildaily\@/);
-close($digester);
-}
+email_digest_like( '--mode daily', qr/maildaily\@/ );
 # now we should have nothing to do, so no content.
-{open (my $digester, "-|", $RT::SbinPath."/rt-email-digest --mode daily --print");
-my @results = <$digester>;
-my $content = join ('', @results);
-is ($content, '');
-} 
+email_digest_like( '--mode daily --print', '' );
 
 # the first time get the content
-{open (my $digester, "-|", $RT::SbinPath."/rt-email-digest --mode weekly --print");
-my @results = <$digester>;
-my $content = join ('', @results);
-like($content, qr/in the last seven days/);
-} {
+email_digest_like( '--mode weekly --print', qr/in the last seven days/ );
 # The second time run it for real so we make sure that we get RT to mark the txn as sent
-open (my $digester, "-|", $RT::SbinPath."/rt-email-digest --mode weekly");
-my @results = <$digester>;
-my $content = join ('', @results);
-like($content, qr/mailweekly\@/);
-close($digester);
-}
+email_digest_like( '--mode weekly', qr/mailweekly\@/ );
 # now we should have nothing to do, so no content.
-{open (my $digester, "-|", $RT::SbinPath."/rt-email-digest --mode weekly --print");
-my @results = <$digester>;
-my $content = join ('', @results);
-is ($content, '');
-} 
+email_digest_like( '--mode weekly --print', '' );
 
+sub email_digest_like {
+    my $arg = shift;
+    my $pattern = shift;
+
+    my $perl = $^X . ' ' . join ' ', map { "-I$_" } grep { not ref } @INC;
+    open my $digester, "-|", "$perl $RT::SbinPath/rt-email-digest $arg";
+    my @results = <$digester>;
+    my $content = join '', @results;
+    if ( ref $pattern && ref $pattern eq 'Regexp' ) {
+        like($content, $pattern);
+    }
+    else {
+        is( $content, $pattern );
+    }
+    close $digester;
+}


More information about the Rt-commit mailing list