Skip to content

Commit

Permalink
Extend t/13disconnect.t test for localizing HandleError
Browse files Browse the repository at this point in the history
Add test case that custom HandleError and also localized custom HandleError
does not trigger any error after disconnect.
  • Loading branch information
pali authored and choroba committed Dec 25, 2024
1 parent bca1103 commit 93e2ac3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions t/13disconnect.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ require 'lib.pl';

my $dbh1 = DbiTestConnect($test_dsn, $test_user, $test_password, { RaiseError => 1, PrintError => 0 });

plan tests => 17;

plan tests => 19;

my $err1;
my $err2;
# set HandleError with catching of all errors
$dbh1->{HandleError} = sub { $err1 = $_[0]; };
{
# localize HandleError with different closure and ensure that the original one is restored after the disconnect()
local $dbh1->{HandleError} = sub { $err2 = $_[0]; };
ok $dbh1->{Active};
ok $dbh1->disconnect();
ok !$dbh1->{Active};
}
ok !defined $err1 or diag $err1;
ok !defined $err2 or diag $err2;

ok my $dbh2 = DBI->connect($test_dsn, $test_user, $test_password, { RaiseError => 1, PrintError => 0 });
ok my $dbh3 = DBI->connect($test_dsn, $test_user, $test_password, { RaiseError => 1, PrintError => 0 });
Expand Down

0 comments on commit 93e2ac3

Please sign in to comment.