Confusing TAP tests readme file

Started by Ildar Musinover 9 years ago3 messages
#1Ildar Musin
i.musin@postgrespro.ru
1 attachment(s)

Hi all,

I was checking out TAP tests documentation. And I found confusing this
part of src/test/perl/README file:

my $ret = $node->psql('postgres', 'SELECT 1');
is($ret, '1', 'SELECT 1 returns 1');

The returning value of psql() function is the exit code of the psql.
Hence this test will never pass since psql returns 0 if query was
successfully executed. Probably it was meant to be the safe_psql()
function instead which returns stdout:

my $ret = $node->safe_psql('postgres', 'SELECT 1');
is($ret, '1', 'SELECT 1 returns 1');

or else:

my ($ret, $stdout, $stderr) =
$node->psql('postgres', 'SELECT 1');
is($stdout, '1', 'SELECT 1 returns 1');

The attached patch fixes this.

Regards,
Ildar Musin

--
Ildar Musin
i.musin@postgrespro.ru

Attachments:

tap_doc.patchtext/x-patch; name=tap_doc.patchDownload
diff --git a/src/test/perl/README b/src/test/perl/README
index 9eae159..36d4120 100644
--- a/src/test/perl/README
+++ b/src/test/perl/README
@@ -41,7 +41,7 @@ against them and evaluate the results. For example:
     $node->init;
     $node->start;
 
-    my $ret = $node->psql('postgres', 'SELECT 1');
+    my $ret = $node->safe_psql('postgres', 'SELECT 1');
     is($ret, '1', 'SELECT 1 returns 1');
 
     $node->stop('fast');
#2Michael Paquier
michael.paquier@gmail.com
In reply to: Ildar Musin (#1)
Re: Confusing TAP tests readme file

On Mon, Jul 25, 2016 at 7:42 PM, Ildar Musin <i.musin@postgrespro.ru> wrote:

I was checking out TAP tests documentation. And I found confusing this part
of src/test/perl/README file:

my $ret = $node->psql('postgres', 'SELECT 1');
is($ret, '1', 'SELECT 1 returns 1');

Good catch.

The returning value of psql() function is the exit code of the psql. Hence
this test will never pass since psql returns 0 if query was successfully
executed. Probably it was meant to be the safe_psql() function instead which
returns stdout:

my $ret = $node->safe_psql('postgres', 'SELECT 1');
is($ret, '1', 'SELECT 1 returns 1');

or else:

my ($ret, $stdout, $stderr) =
$node->psql('postgres', 'SELECT 1');
is($stdout, '1', 'SELECT 1 returns 1');

The attached patch fixes this.

Just using psql_safe looks fine to me.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Fujii Masao
masao.fujii@gmail.com
In reply to: Michael Paquier (#2)
Re: Confusing TAP tests readme file

On Mon, Jul 25, 2016 at 9:53 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Mon, Jul 25, 2016 at 7:42 PM, Ildar Musin <i.musin@postgrespro.ru> wrote:

I was checking out TAP tests documentation. And I found confusing this part
of src/test/perl/README file:

my $ret = $node->psql('postgres', 'SELECT 1');
is($ret, '1', 'SELECT 1 returns 1');

Good catch.

The returning value of psql() function is the exit code of the psql. Hence
this test will never pass since psql returns 0 if query was successfully
executed. Probably it was meant to be the safe_psql() function instead which
returns stdout:

my $ret = $node->safe_psql('postgres', 'SELECT 1');
is($ret, '1', 'SELECT 1 returns 1');

or else:

my ($ret, $stdout, $stderr) =
$node->psql('postgres', 'SELECT 1');
is($stdout, '1', 'SELECT 1 returns 1');

The attached patch fixes this.

Just using psql_safe looks fine to me.

Pushed. Thanks!

Regards,

--
Fujii Masao

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers