Blame t/local/30_error.t

Packit b893dc
#!/usr/bin/perl
Packit b893dc
Packit b893dc
use strict;
Packit b893dc
use warnings;
Packit b893dc
use Test::More;
Packit b893dc
Packit b893dc
eval "use Test::Exception; use Test::Warn; use Test::NoWarnings; 1;";
Packit b893dc
plan skip_all => 'Requires Test::Exception, Test::Warn and Test::NoWarnings' if $@;
Packit b893dc
plan tests => 11;
Packit b893dc
Packit b893dc
use Net::SSLeay;
Packit b893dc
Net::SSLeay::load_error_strings();
Packit b893dc
Packit b893dc
# Note, die_now usually just prints the process id and the argument string eg:
Packit b893dc
# 57611: test
Packit b893dc
# but on some systems, perhaps if diagnostics are enabled, it might [roduce something like:
Packit b893dc
# found: Uncaught exception from user code:
Packit b893dc
# 	57611: test
Packit b893dc
# therefore the qr match strings below have been chnaged so they dont have tooccur at the 
Packit b893dc
# beginning of the line.
Packit b893dc
{
Packit b893dc
    throws_ok(sub {
Packit b893dc
            Net::SSLeay::die_now('test')
Packit b893dc
    }, qr/$$: test\n$/, 'die_now dies without errors');
Packit b893dc
Packit b893dc
    lives_ok(sub {
Packit b893dc
            Net::SSLeay::die_if_ssl_error('test');
Packit b893dc
    }, 'die_if_ssl_error lives without errors');
Packit b893dc
Packit b893dc
    put_err();
Packit b893dc
    throws_ok(sub {
Packit b893dc
            Net::SSLeay::die_now('test');
Packit b893dc
    }, qr/$$: test\n$/, 'die_now dies with errors');
Packit b893dc
Packit b893dc
    put_err();
Packit b893dc
    throws_ok(sub {
Packit b893dc
            Net::SSLeay::die_if_ssl_error('test');
Packit b893dc
    }, qr/$$: test\n$/, 'die_if_ssl_error dies with errors');
Packit b893dc
}
Packit b893dc
Packit b893dc
{
Packit b893dc
    local $Net::SSLeay::trace = 1;
Packit b893dc
Packit b893dc
    throws_ok(sub {
Packit b893dc
            Net::SSLeay::die_now('foo');
Packit b893dc
    }, qr/$$: foo\n$/, 'die_now dies without arrors and with trace');
Packit b893dc
Packit b893dc
    lives_ok(sub {
Packit b893dc
            Net::SSLeay::die_if_ssl_error('foo');
Packit b893dc
    }, 'die_if_ssl_error lives without errors and with trace');
Packit b893dc
Packit b893dc
    put_err();
Packit b893dc
    warning_like(sub {
Packit b893dc
            throws_ok(sub {
Packit b893dc
                    Net::SSLeay::die_now('foo');
Packit b893dc
            }, qr/^$$: foo\n$/, 'die_now dies with errors and trace');
Packit b893dc
    }, qr/foo $$: 1 - error:2006d080/i, 'die_now raises warnings about the occurred error when tracing');
Packit b893dc
Packit b893dc
    put_err();
Packit b893dc
    warning_like(sub {
Packit b893dc
            throws_ok(sub {
Packit b893dc
                Net::SSLeay::die_if_ssl_error('foo');
Packit b893dc
            }, qr/^$$: foo\n$/, 'die_if_ssl_error dies with errors and trace');
Packit b893dc
    }, qr/foo $$: 1 - error:2006d080/i, 'die_if_ssl_error raises warnings about the occurred error when tracing');
Packit b893dc
}
Packit b893dc
Packit b893dc
sub put_err {
Packit b893dc
    Net::SSLeay::ERR_put_error(
Packit b893dc
        32, #lib
Packit b893dc
       109, #func
Packit b893dc
       128, #reason
Packit b893dc
         1, #file
Packit b893dc
         1, #line
Packit b893dc
    );
Packit b893dc
}