From 9bd90f0faaec5b5566b9acfdfb7f6a7560b3855c Mon Sep 17 00:00:00 2001 From: Pali Date: Mon, 9 Dec 2024 21:23:30 +0100 Subject: [PATCH] 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. --- t/13disconnect.t | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/t/13disconnect.t b/t/13disconnect.t index ea4f36eb..61c75549 100644 --- a/t/13disconnect.t +++ b/t/13disconnect.t @@ -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 });