Tests for psql \g and \o

Started by Daniel Veriteover 3 years ago7 messageshackers
Jump to latest
#1Daniel Verite
daniel@manitou-mail.org

Hi,

Here's a patch adding regression tests for \g and \o, and TAP tests
for \g | program,

It's a follow up to the discussion at [1]/messages/by-id/4333844c-2244-4d6e-a49a-1d483fbe304f@manitou-mail.org. Since this discussion
already has a slot in the CF [2]https://commitfest.postgresql.org/40/3923/ with a committed patch, let's start a
new separate thread.

[1]: /messages/by-id/4333844c-2244-4d6e-a49a-1d483fbe304f@manitou-mail.org
/messages/by-id/4333844c-2244-4d6e-a49a-1d483fbe304f@manitou-mail.org

[2]: https://commitfest.postgresql.org/40/3923/

Best regards,
--
Daniel Vérité
https://postgresql.verite.pro/
Twitter: @DanielVerite

Attachments:

tests-psql-g-o-file.patchtext/plainDownload+216-0
#2Michael Paquier
michael@paquier.xyz
In reply to: Daniel Verite (#1)
Re: Tests for psql \g and \o

On Tue, Nov 01, 2022 at 12:42:47PM +0100, Daniel Verite wrote:

It's a follow up to the discussion at [1]. Since this discussion
already has a slot in the CF [2] with a committed patch, let's start a
new separate thread.

+psql_like($node, "SELECT 'one' \\g | cat >$g_file", qr//, "one command \\g");
+my $c1 = slurp_file($g_file);
+like($c1, qr/one/);

Windows may not have an equivalent for "cat", no? Note that psql's
001_basic.pl has no restriction in place for Windows. Perhaps you
could use the same trick as basebackup_to_shell, where GZIP is used to
write some arbitrary data.. Anyway, this has some quoting issues
especially if the file's path has whitespaces? This is located in
File::Temp::tempdir, still it does not sound like a good thing to rely
on this assumption on portability grounds.
--
Michael

#3Daniel Verite
daniel@manitou-mail.org
In reply to: Michael Paquier (#2)
Re: Tests for psql \g and \o

Michael Paquier wrote:

+psql_like($node, "SELECT 'one' \\g | cat >$g_file", qr//, "one command
\\g");
+my $c1 = slurp_file($g_file);
+like($c1, qr/one/);

Windows may not have an equivalent for "cat", no? Note that psql's
001_basic.pl has no restriction in place for Windows. Perhaps you
could use the same trick as basebackup_to_shell, where GZIP is used to
write some arbitrary data.. Anyway, this has some quoting issues
especially if the file's path has whitespaces? This is located in
File::Temp::tempdir, still it does not sound like a good thing to rely
on this assumption on portability grounds.

PFA a new patch addressing these issues.

Best regards,
--
Daniel Vérité
https://postgresql.verite.pro/
Twitter: @DanielVerite

Attachments:

tests-psql-g-o-file-v2.patchtext/plainDownload+216-0
#4Michael Paquier
michael@paquier.xyz
In reply to: Daniel Verite (#3)
Re: Tests for psql \g and \o

On Wed, Nov 23, 2022 at 09:18:57PM +0100, Daniel Verite wrote:

PFA a new patch addressing these issues.

Thanks, the tests part of the main regression test suite look good to
me, so I have applied them after fixing a few typos and tweaking the
style of the test. Regarding the tests with pipes, I had cold feet
with the dependencies on cat for non-WIN32 or findstr for WIN32. cat
is used in the kerberos and ldap tests, though I am wondering whether
we shouldn't take an approach similar to other tests where the command
may not exist, and where we should check if there is something in the
environment..
--
Michael

#5Daniel Verite
daniel@manitou-mail.org
In reply to: Michael Paquier (#4)
Re: Tests for psql \g and \o

Michael Paquier wrote:

Thanks, the tests part of the main regression test suite look good to
me, so I have applied them after fixing a few typos and tweaking the
style of the test.

Thanks!

Regarding the tests with pipes, I had cold feet with the
dependencies on cat for non-WIN32 or findstr for WIN32.

OK. If the issue is that these programs might be missing, I guess
we could check that beforehand with IPC::Run and skip the
corresponding psql tests if they're not available or not working
as expected.

Best regards,
--
Daniel Vérité
https://postgresql.verite.pro/
Twitter: @DanielVerite

#6Justin Pryzby
pryzby@telsasoft.com
In reply to: Michael Paquier (#4)
Re: Tests for psql \g and \o

On Wed, Nov 30, 2022 at 02:50:16PM +0900, Michael Paquier wrote:

On Wed, Nov 23, 2022 at 09:18:57PM +0100, Daniel Verite wrote:

PFA a new patch addressing these issues.

Thanks, the tests part of the main regression test suite look good to
me, so I have applied them after fixing a few typos and tweaking the
style of the test. Regarding the tests with pipes, I had cold feet
with the dependencies on cat for non-WIN32 or findstr for WIN32.

I think you could do that with a perl 0-liner.

$ echo foo |perl -pe ''
foo

--
Justin

#7Michael Paquier
michael@paquier.xyz
In reply to: Justin Pryzby (#6)
Re: Tests for psql \g and \o

On Wed, Nov 30, 2022 at 12:33:59PM -0600, Justin Pryzby wrote:

I think you could do that with a perl 0-liner.

Right. And this could do something similar to
025_stuck_on_old_timeline.pl in terms of finding the binary for perl.
--
Michael