diff --git a/src/test/modules/test_misc/meson.build b/src/test/modules/test_misc/meson.build index 9c50de7efb0..dff852de839 100644 --- a/src/test/modules/test_misc/meson.build +++ b/src/test/modules/test_misc/meson.build @@ -16,6 +16,7 @@ tests += { 't/005_timeouts.pl', 't/006_signal_autovacuum.pl', 't/007_catcache_inval.pl', + 't/008_psql_on_error_die.pl', ], }, } diff --git a/src/test/modules/test_misc/t/008_psql_on_error_die.pl b/src/test/modules/test_misc/t/008_psql_on_error_die.pl new file mode 100644 index 00000000000..3590c9f6601 --- /dev/null +++ b/src/test/modules/test_misc/t/008_psql_on_error_die.pl @@ -0,0 +1,30 @@ + +# Copyright (c) 2025, PostgreSQL Global Development Group + +# Tests that check that calling node->psql with on_error_die => 1 and without +# passing $stderr will result in intuitive exception + +use strict; +use warnings FATAL => 'all'; +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +eval +{ + $node->psql('postgres', q{SELEC 1}, on_error_die => 1); +}; + +if ($@) +{ + print $@; + like($@, qr//, "Expected "); + unlike($@, qr/Use of uninitialized value in concatenation/, + "This is a 'warnings FATAL' output, we don't want this"); +} + +done_testing(); diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm index 1c11750ac1d..bc2eade8e8e 100644 --- a/src/test/perl/PostgreSQL/Test/Cluster.pm +++ b/src/test/perl/PostgreSQL/Test/Cluster.pm @@ -2235,6 +2235,14 @@ sub psql chomp $$stderr; } + # With use warnings FATAL => 'all' we could fail during the following dies + # due to undefined $$stderr (wantarray is false and stderr wasn't passed). + # Initialize it with a placeholder + if (!defined($$stderr)) + { + $$stderr = ""; + } + # See http://perldoc.perl.org/perlvar.html#%24CHILD_ERROR # We don't use IPC::Run::Simple to limit dependencies. #