psql: Add tests for \errverbose
authorPeter Eisentraut <peter@eisentraut.org>
Thu, 31 Mar 2022 14:09:44 +0000 (16:09 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Thu, 31 Mar 2022 14:20:27 +0000 (16:20 +0200)
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

index 02a84543fd562677c1fc708d9a61d56b5c853d6d..66796f4978d9e0463ff9cb0ce3191145234269a0 100644 (file)
@@ -132,4 +132,51 @@ server closed the connection unexpectedly
 psql:<stdin>: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:<stdin>:1: ERROR:  .*$
+^LINE 1: SELECT error;$
+^ *^.*$
+^psql:<stdin>: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:<stdin>:2: ERROR:  .*$
+^LINE 2: SELECT error;$
+^ *^.*$
+^psql:<stdin>: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:<stdin>:1: ERROR:  .*$
+^LINE 1: SELECT error$
+^ *^.*$
+^psql:<stdin>:2: error: ERROR:  [0-9A-Z]{5}: .*$
+^LINE 1: SELECT error$
+^ *^.*$
+^LOCATION: .*$/m,
+  '\errverbose after \gdesc with error');
+
 done_testing();