Thanks for your patch!
I like your behaviour-based approach more, but I have some questions
about the patch itself
1) There is a comment in query() function:
# We need to match for the newline, because we try to remove it below,
and
# it's possible to consume just the input *without* the newline. In
# interactive psql we emit \r\n, so we need to allow for that. Also need
# to be careful that we don't e.g. match the echoed \echo command,
rather
# than its output.
So, originally, checking that the banner is on it's own line is needed
to distiguish \echo $banner and \warn $banner from their output.
It seems that your patch does not distingush them all the time
(taken from query() function with your patch applied)
my $banner_detect_stdout = qr/\Q$banner\E/;
my $banner_detect_stderr = qr/(^|\n)\Q$banner\E\r?\n/;
Why do you check stderr for newline but not the stdout?
2) Why did you add /Q/E around the $banner variable? It doesn't
contain any regex metacharacters (in query() function there is
$query_cnt inside of $banner, but it should be substituted by Perl).
Maybe it is really necessary and I just don't get it
-----
While testing and checking, I've made a new patch. It's very
simple and it just checks that there is banner in a string, but
the string doesn't start with \echo or \warn
Maybe it needs some additional comments, but lets decide on which
approach to use
-----
There is also a problem of test src/bin/psql/t/030_pager.pl - it
just doesn't work with --without-readline, all regexes seem to be right
and debug output shows correct data. None of our patches
currently solve it, I'll look into it
-----
Regards,
Olegdiff --git a/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm b/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm
index 5bd41a278dd..1a77eae8d84 100644
--- a/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm
+++ b/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm
@@ -155,11 +155,11 @@ sub wait_connect
#
# See query() for details about why/how the banner is used.
my $banner = "background_psql: ready";
- my $banner_match = qr/(^|\n)$banner\r?\n/;
+ my $banner_match = qr/(^|\n)(?!\\echo|\\warn).*$banner\r?\n/;
$self->{stdin} .= "\\echo $banner\n\\warn $banner\n";
$self->{run}->pump()
until ($self->{stdout} =~ /$banner_match/
- && $self->{stderr} =~ /$banner\r?\n/)
+ && $self->{stderr} =~ /$banner_match/)
|| $self->{timeout}->is_expired;
note "connect output:\n",
@@ -270,7 +270,7 @@ sub query
# to be careful that we don't e.g. match the echoed \echo command, rather
# than its output.
my $banner = "background_psql: QUERY_SEPARATOR $query_cnt:";
- my $banner_match = qr/(^|\n)$banner\r?\n/;
+ my $banner_match = qr/(^|\n)(?!\\echo|\\warn).*$banner\r?\n/;
$self->{stdin} .= "$query\n;\n\\echo $banner\n\\warn $banner\n";
pump_until(
$self->{run}, $self->{timeout},