aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2023-10-02 11:46:25 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2023-10-02 11:46:25 +0300
commitbe8d4cb13cb477fe45db31acf74e97eced51dfce (patch)
treefa07bb06d1ac5c173ef1538475fb62c8338141b3
parentc8ec5e0543b90372c8e6d5cc2cd3d2ff89ca0e82 (diff)
downloadpostgresql-be8d4cb13cb477fe45db31acf74e97eced51dfce.tar.gz
postgresql-be8d4cb13cb477fe45db31acf74e97eced51dfce.zip
Add regression tests for psql \g piped into a program
Author: Daniel Vérité Reviewed-by: Peter Eisentraut Discussion: https://www.postgresql.org/message-id/33ce8350-8cd1-45ff-a5fe-f9be7bc70649%40manitou-mail.org
-rw-r--r--src/bin/psql/t/001_basic.pl28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl
index 89aeec46e55..95f4e60ab20 100644
--- a/src/bin/psql/t/001_basic.pl
+++ b/src/bin/psql/t/001_basic.pl
@@ -405,4 +405,32 @@ psql_fails_like(
qr/iteration count is specified more than once/,
'\watch, iteration count is specified more than once');
+# Test \g output piped into a program.
+# The program is perl -pe '' to simply copy the input to the output.
+my $g_file = "$tempdir/g_file_1.out";
+my $perlbin = $^X;
+$perlbin =~ s!\\!/!g if $PostgreSQL::Test::Utils::windows_os;
+my $pipe_cmd = "$perlbin -pe '' >$g_file";
+
+psql_like($node, "SELECT 'one' \\g | $pipe_cmd", qr//, "one command \\g");
+my $c1 = slurp_file($g_file);
+like($c1, qr/one/);
+
+psql_like($node, "SELECT 'two' \\; SELECT 'three' \\g | $pipe_cmd", qr//, "two commands \\g");
+my $c2 = slurp_file($g_file);
+like($c2, qr/two.*three/s);
+
+
+psql_like($node, "\\set SHOW_ALL_RESULTS 0\nSELECT 'four' \\; SELECT 'five' \\g | $pipe_cmd", qr//,
+ "two commands \\g with only last result");
+my $c3 = slurp_file($g_file);
+like($c3, qr/five/);
+unlike($c3, qr/four/);
+
+psql_like($node, "copy (values ('foo'),('bar')) to stdout \\g | $pipe_cmd",
+ qr//,
+ "copy output passed to \\g pipe");
+my $c4 = slurp_file($g_file);
+like($c4, qr/foo.*bar/s);
+
done_testing();