From d3ab618290543017402b3bec9d36dde881becb18 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 31 Mar 2022 16:09:44 +0200 Subject: [PATCH] psql: Add tests for \errverbose This is another piece of functionality that happens while a user query is being sent and which did not have any test coverage. --- src/bin/psql/t/001_basic.pl | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl index 02a84543fd..66796f4978 100644 --- a/src/bin/psql/t/001_basic.pl +++ b/src/bin/psql/t/001_basic.pl @@ -132,4 +132,51 @@ server closed the connection unexpectedly psql::2: fatal: connection to server was lost', 'server crash: error message'); +# test \errverbose +# +# (This is not in the regular regression tests because the output +# contains the source code location and we don't want to have to +# update that every time it changes.) + +psql_like( + $node, + 'SELECT 1; +\errverbose', + qr/^1\nThere is no previous error\.$/, + '\errverbose with no previous error'); + +# There are three main ways to run a query that might affect +# \errverbose: The normal way, using a cursor by setting FETCH_COUNT, +# and using \gdesc. Test them all. + +like(($node->psql('postgres', "SELECT error;\n\\errverbose", on_error_stop => 0))[2], + qr/\A^psql::1: ERROR: .*$ +^LINE 1: SELECT error;$ +^ *^.*$ +^psql::2: error: ERROR: [0-9A-Z]{5}: .*$ +^LINE 1: SELECT error;$ +^ *^.*$ +^LOCATION: .*$/m, + '\errverbose after normal query with error'); + +like(($node->psql('postgres', "\\set FETCH_COUNT 1\nSELECT error;\n\\errverbose", on_error_stop => 0))[2], + qr/\A^psql::2: ERROR: .*$ +^LINE 2: SELECT error;$ +^ *^.*$ +^psql::3: error: ERROR: [0-9A-Z]{5}: .*$ +^LINE 2: SELECT error;$ +^ *^.*$ +^LOCATION: .*$/m, + '\errverbose after FETCH_COUNT query with error'); + +like(($node->psql('postgres', "SELECT error\\gdesc\n\\errverbose", on_error_stop => 0))[2], + qr/\A^psql::1: ERROR: .*$ +^LINE 1: SELECT error$ +^ *^.*$ +^psql::2: error: ERROR: [0-9A-Z]{5}: .*$ +^LINE 1: SELECT error$ +^ *^.*$ +^LOCATION: .*$/m, + '\errverbose after \gdesc with error'); + done_testing(); -- 2.39.5