Skip to content

Commit 06591cf

Browse files
palichoroba
authored andcommitted
Extend t/13disconnect.t test for localizing HandleError
Add test case that custom HandleError and also localized custom HandleError does not trigger any error after disconnect.
1 parent 650fd80 commit 06591cf

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

t/13disconnect.t

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ require 'lib.pl';
1010

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

13-
plan tests => 17;
14-
13+
plan tests => 19;
14+
15+
my $err1;
16+
my $err2;
17+
# set HandleError with catching of all errors
18+
$dbh1->{HandleError} = sub { $err1 = $_[0]; };
19+
{
20+
# localize HandleError with different closure and ensure that the original one is restored after the disconnect()
21+
local $dbh1->{HandleError} = sub { $err2 = $_[0]; };
1522
ok $dbh1->{Active};
1623
ok $dbh1->disconnect();
1724
ok !$dbh1->{Active};
25+
}
26+
ok !defined $err1 or diag $err1;
27+
ok !defined $err2 or diag $err2;
1828

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

0 commit comments

Comments
 (0)