[Rt-commit] rt branch, 4.0/test-warnings, updated. rt-4.0.0-180-gbe279e5

Shawn Moore sartak at bestpractical.com
Tue May 3 13:39:01 EDT 2011


The branch, 4.0/test-warnings has been updated
       via  be279e5f4594a64996300070a84ad8c6d556aca4 (commit)
      from  c9569e64752cce0da3f1fd640301608876b06acc (commit)

Summary of changes:
 t/mail/crypt-gnupg.t |   75 +++++++++++++++++++++++++++----------------------
 1 files changed, 41 insertions(+), 34 deletions(-)

- Log -----------------------------------------------------------------
commit be279e5f4594a64996300070a84ad8c6d556aca4
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue May 3 13:36:08 2011 -0400

    use Test::Warn for most of t/mail/crypt-gnupg.t
    
        See also: http://issues.bestpractical.com/Ticket/Display.html?id=17275
        which shows there are warnings we aren't testing yet, since the old
        style "collect all warnings into one string and do a single regex
        match" was hiding them.

diff --git a/t/mail/crypt-gnupg.t b/t/mail/crypt-gnupg.t
index 7c47d51..fd75928 100644
--- a/t/mail/crypt-gnupg.t
+++ b/t/mail/crypt-gnupg.t
@@ -12,6 +12,7 @@ BEGIN {
 }
 
 use RT::Test::GnuPG tests => 96, gnupg_options => { homedir => $homedir };
+use Test::Warn;
 
 use_ok('MIME::Entity');
 
@@ -77,17 +78,21 @@ diag 'only signing. missing passphrase';
 
 diag 'only signing. wrong passphrase';
 {
-    my $warnings;
-    local $SIG{__WARN__} = sub {
-        $warnings .= "@_";
-    };
-
     my $entity = MIME::Entity->build(
         From    => 'rt at example.com',
         Subject => 'test',
         Data    => ['test'],
     );
-    my %res = RT::Crypt::GnuPG::SignEncrypt( Entity => $entity, Encrypt => 0, Passphrase => 'wrong' );
+
+    my %res;
+    warning_like {
+        %res = RT::Crypt::GnuPG::SignEncrypt(
+            Entity     => $entity,
+            Encrypt    => 0,
+            Passphrase => 'wrong',
+        );
+    } qr/bad passphrase/;
+
     ok( $res{'exit_code'}, "couldn't sign with bad passphrase");
     ok( $res{'error'} || $res{'logger'}, "error is here" );
 
@@ -95,8 +100,6 @@ diag 'only signing. wrong passphrase';
     is( scalar @status, 1, 'one record');
     is( $status[0]->{'Operation'}, 'PassphraseCheck', 'operation is correct');
     is( $status[0]->{'Status'}, 'BAD', 'wrong passphrase');
-
-    like($warnings, qr/bad passphrase/);
 }
 
 diag 'encryption only';
@@ -127,26 +130,27 @@ diag 'encryption only';
 
 diag 'encryption only, bad recipient';
 {
-    my $warnings;
-    local $SIG{__WARN__} = sub {
-        $warnings .= "@_";
-    };
-
     my $entity = MIME::Entity->build(
         From    => 'rt at example.com',
         To      => 'keyless at example.com',
         Subject => 'test',
         Data    => ['test'],
     );
-    my %res = RT::Crypt::GnuPG::SignEncrypt( Entity => $entity, Sign => 0 );
+
+    my %res;
+    warning_like {
+        %res = RT::Crypt::GnuPG::SignEncrypt(
+            Entity => $entity,
+            Sign   => 0,
+        );
+    } qr/public key not found/;
+
     ok( $res{'exit_code'}, 'no way to encrypt without keys of recipients');
     ok( $res{'logger'}, "errors are in logger" );
 
     my @status = RT::Crypt::GnuPG::ParseStatus( $res{'status'} );
     is( scalar @status, 1, 'one record');
     is( $status[0]->{'Keyword'}, 'INV_RECP', 'invalid recipient');
-
-    like($warnings, qr/public key not found/);
 }
 
 diag 'encryption and signing with combined method';
@@ -226,48 +230,51 @@ diag 'find signed/encrypted part deep inside';
 
 diag 'wrong signed/encrypted parts: no protocol';
 {
-    my $warnings;
-    local $SIG{__WARN__} = sub {
-        $warnings .= "@_";
-    };
-
     my $entity = MIME::Entity->build(
         From    => 'rt at example.com',
         To      => 'rt at example.com',
         Subject => 'test',
         Data    => ['test'],
     );
-    my %res = RT::Crypt::GnuPG::SignEncrypt( Entity => $entity, Sign => 0 );
+
+    my %res = RT::Crypt::GnuPG::SignEncrypt(
+        Entity => $entity,
+        Sign   => 0,
+    );
+
     ok( !$res{'exit_code'}, 'success' );
     $entity->head->mime_attr( 'Content-Type.protocol' => undef );
 
-    my @parts = RT::Crypt::GnuPG::FindProtectedParts( Entity => $entity );
-    is( scalar @parts, 0, 'no protected parts' );
+    my @parts;
+    warning_like {
+        @parts = RT::Crypt::GnuPG::FindProtectedParts( Entity => $entity );
+    } qr{Entity is 'multipart/encrypted', but has no protocol defined. Skipped};
 
-    like($warnings, qr{Entity is 'multipart/encrypted', but has no protocol defined. Skipped});
+    is( scalar @parts, 0, 'no protected parts' );
 }
 
 diag 'wrong signed/encrypted parts: not enought parts';
 {
-    my $warnings;
-    local $SIG{__WARN__} = sub {
-        $warnings .= "@_";
-    };
-
     my $entity = MIME::Entity->build(
         From    => 'rt at example.com',
         To      => 'rt at example.com',
         Subject => 'test',
         Data    => ['test'],
     );
-    my %res = RT::Crypt::GnuPG::SignEncrypt( Entity => $entity, Sign => 0 );
+
+    my %res = RT::Crypt::GnuPG::SignEncrypt(
+        Entity => $entity,
+        Sign   => 0,
+    );
+
     ok( !$res{'exit_code'}, 'success' );
     $entity->parts([ $entity->parts(0) ]);
 
-    my @parts = RT::Crypt::GnuPG::FindProtectedParts( Entity => $entity );
+    my @parts;
+    warning_like {
+        @parts = RT::Crypt::GnuPG::FindProtectedParts( Entity => $entity );
+    } qr/Encrypted or signed entity must has two subparts. Skipped/;
     is( scalar @parts, 0, 'no protected parts' );
-
-    like($warnings, qr/Encrypted or signed entity must has two subparts. Skipped/);
 }
 
 diag 'wrong signed/encrypted parts: wrong proto';

-----------------------------------------------------------------------


More information about the Rt-commit mailing list