| Server IP : 23.254.227.96 / Your IP : 216.73.216.183 Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64 User : viralblo ( 1001) PHP Version : 8.1.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/perl-Try-Tiny/t/ |
Upload File : |
use strict;
use warnings;
use Test::More tests => 8;
use Try::Tiny;
sub _eval {
local $@;
local $Test::Builder::Level = $Test::Builder::Level + 2;
return ( scalar(eval { $_[0]->(); 1 }), $@ );
}
sub throws_ok (&$$) {
my ( $code, $regex, $desc ) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 1;
my ( $ok, $error ) = _eval($code);
if ( $ok ) {
fail($desc);
} else {
like($error || '', $regex, $desc );
}
}
throws_ok {
try { 1 }; catch { 2 };
} qr/\QUseless bare catch()/, 'Bare catch() detected';
throws_ok {
try { 1 }; finally { 2 };
} qr/\QUseless bare finally()/, 'Bare finally() detected';
throws_ok {
try { 1 }; catch { 2 } finally { 2 };
} qr/\QUseless bare catch()/, 'Bare catch()/finally() detected';
throws_ok {
try { 1 }; finally { 2 } catch { 2 };
} qr/\QUseless bare finally()/, 'Bare finally()/catch() detected';
throws_ok {
try { 1 } catch { 2 } catch { 3 } finally { 4 } finally { 5 }
} qr/\QA try() may not be followed by multiple catch() blocks/, 'Multi-catch detected';
throws_ok {
try { 1 } catch { 2 }
do { 2 }
} qr/\Qtry() encountered an unexpected argument (2) - perhaps a missing semi-colon before or at/,
'Unterminated try detected';
sub foo {
try { 0 }; catch { 2 }
}
throws_ok {
if (foo()) {
# ...
}
} qr/\QUseless bare catch/,
'Bare catch at the end of a function call';
sub bar {
try { 0 }; finally { 2 }
}
throws_ok {
if (bar()) {
# ...
}
} qr/\QUseless bare finally/,
'Bare finally at the end of a function call';