App-mailmake

 view release on metacpan or  search on metacpan

t/010_app_mailmake.t  view on Meta::CPAN

    diag( "Running $cmd" ) if( $DEBUG );
    my( $out, $err, $exit ) = _run( $cmd );
    diag( "stderr: $err" ) if( $err && $DEBUG );
    is( $exit, 0, '--print plain-file: exit 0' );
    like( $out, qr/Hello, World!/, '--print plain-file: body content correct' );
};

# NOTE: --print html + plain (multipart/alternative)
subtest '--print html + plain (multipart/alternative)' => sub
{
    my $cmd = $base_cmd .
              qq{ --plain "Hello World." --html "<p>Hello World.</p>" --print};
    diag( "Running $cmd" ) if( $DEBUG );
    my( $out, $err, $exit ) = _run( $cmd );
    diag( "stderr: $err" ) if( $err && $DEBUG );
    is( $exit, 0, '--print html+plain: exit 0' );
    like( $out, qr/Content-Type:\s+multipart\/alternative/i,
          '--print html+plain: multipart/alternative structure' );
};

# NOTE: --print with attachment (multipart/mixed)
subtest '--print with attachment (multipart/mixed)' => sub
{
    my $attach = $tmp->child( 'attach.txt' );
    $attach->unload_utf8( "Attachment content.\n" ) || die( $attach->error );
    my $cmd = $base_cmd .
              qq{ --plain "See attachment." --attach $attach --print};
    diag( "Running $cmd" ) if( $DEBUG );
    my( $out, $err, $exit ) = _run( $cmd );
    diag( "stderr: $err" ) if( $err && $DEBUG );
    diag( "$base_cmd output:\n$out" ) if( $exit != 0 && $DEBUG );
    is( $exit, 0, '--print attach: exit 0' );
    like( $out, qr/Content-Type:\s+multipart\/mixed/i,
          '--print attach: multipart/mixed structure' );
};

# NOTE: --print with extra header
subtest '--print with extra header' => sub
{
    my $cmd = $base_cmd .
              qq{ --plain "Header test." --header "X-Mailer:mailmake-test" --print};
    diag( "Running $cmd" ) if( $DEBUG );
    my( $out, $err, $exit ) = _run( $cmd );
    diag( "stderr: $err" ) if( $err && $DEBUG );
    is( $exit, 0, '--print extra header: exit 0' );
    like( $out, qr/^X-Mailer:\s*mailmake-test/mi,
          '--print extra header: X-Mailer present' );
};

# NOTE: missing --from should fail
subtest 'missing --from should fail' => sub
{
    my $cmd = qq{$^X -Ilib scripts/mailmake} .
              qq{ --to recipient\@example.com --plain "x" --print};
    diag( "Running $cmd" ) if( $DEBUG );
    my( $out, $err, $exit ) = _run( $cmd );
    $out .= $err;  # merge for error-checking tests
    isnt( $exit, 0, 'missing --from: non-zero exit' );
};

# NOTE: --gpg-sign and --smime-sign together should fail
subtest '--gpg-sign and --smime-sign together should fail' => sub
{
    my $cmd = $base_cmd .
              qq{ --plain "x" --gpg-sign --smime-sign --print};
    diag( "Running $cmd" ) if( $DEBUG );
    my( $out, $err, $exit ) = _run( $cmd );
    $out .= $err;  # merge for error-checking tests
    isnt( $exit, 0, 'conflicting gpg+smime: non-zero exit' );
};

done_testing();

__END__



( run in 0.989 second using v1.01-cache-2.11-cpan-df04353d9ac )