Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit be8d4cb

Browse filesBrowse files
committed
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
1 parent c8ec5e0 commit be8d4cb
Copy full SHA for be8d4cb

File tree

Expand file treeCollapse file tree

1 file changed

+28
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-0
lines changed

‎src/bin/psql/t/001_basic.pl

Copy file name to clipboardExpand all lines: src/bin/psql/t/001_basic.pl
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,4 +405,32 @@ sub psql_fails_like
405405
qr/iteration count is specified more than once/,
406406
'\watch, iteration count is specified more than once');
407407

408+
# Test \g output piped into a program.
409+
# The program is perl -pe '' to simply copy the input to the output.
410+
my $g_file = "$tempdir/g_file_1.out";
411+
my $perlbin = $^X;
412+
$perlbin =~ s!\\!/!g if $PostgreSQL::Test::Utils::windows_os;
413+
my $pipe_cmd = "$perlbin -pe '' >$g_file";
414+
415+
psql_like($node, "SELECT 'one' \\g | $pipe_cmd", qr//, "one command \\g");
416+
my $c1 = slurp_file($g_file);
417+
like($c1, qr/one/);
418+
419+
psql_like($node, "SELECT 'two' \\; SELECT 'three' \\g | $pipe_cmd", qr//, "two commands \\g");
420+
my $c2 = slurp_file($g_file);
421+
like($c2, qr/two.*three/s);
422+
423+
424+
psql_like($node, "\\set SHOW_ALL_RESULTS 0\nSELECT 'four' \\; SELECT 'five' \\g | $pipe_cmd", qr//,
425+
"two commands \\g with only last result");
426+
my $c3 = slurp_file($g_file);
427+
like($c3, qr/five/);
428+
unlike($c3, qr/four/);
429+
430+
psql_like($node, "copy (values ('foo'),('bar')) to stdout \\g | $pipe_cmd",
431+
qr//,
432+
"copy output passed to \\g pipe");
433+
my $c4 = slurp_file($g_file);
434+
like($c4, qr/foo.*bar/s);
435+
408436
done_testing();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.