[PATCH v1] Add a way to supply stdin to TAP tests

Started by David Fetterover 6 years ago6 messages
#1David Fetter
david@fetter.org
1 attachment(s)

Folks,

Our test coverage needs all the help it can get.

This patch, extracted from another by Fabian Coelho, helps move things
in that direction.

I'd like to argue that it's not a new feature, and that it should be
back-patched as far as possible.

Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

Attachments:

v1-0001-Add-a-way-to-supply-stdin-to-TAP-tests.patchtext/x-diff; charset=us-asciiDownload
From 08fe538383c7a3519f5bb8a0e379b023afc0bb9d Mon Sep 17 00:00:00 2001
From: David Fetter <david@fetter.org>
Date: Sun, 28 Apr 2019 08:01:01 -0700
Subject: [PATCH v1] Add a way to supply stdin to TAP tests
To: hackers
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.20.1"

This is a multi-part message in MIME format.
--------------2.20.1
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


by Fabian Coelho

This will help increase test coverage for anything that might need it,
and a lot of things currently need it.

diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm
index a164cdbd8c..6ad7f681ae 100644
--- a/src/test/perl/TestLib.pm
+++ b/src/test/perl/TestLib.pm
@@ -519,22 +519,24 @@ sub command_fails_like
 }
 
 # Run a command and check its status and outputs.
-# The 5 arguments are:
+# The 5 to 6 arguments are:
 # - cmd: ref to list for command, options and arguments to run
 # - ret: expected exit status
 # - out: ref to list of re to be checked against stdout (all must match)
 # - err: ref to list of re to be checked against stderr (all must match)
 # - test_name: name of test
+# - in: standard input
 sub command_checks_all
 {
 	local $Test::Builder::Level = $Test::Builder::Level + 1;
 
-	my ($cmd, $expected_ret, $out, $err, $test_name) = @_;
+	my ($cmd, $expected_ret, $out, $err, $test_name, $in) = @_;
+	$in = '' if not defined $in;
 
 	# run command
 	my ($stdout, $stderr);
 	print("# Running: " . join(" ", @{$cmd}) . "\n");
-	IPC::Run::run($cmd, '>', \$stdout, '2>', \$stderr);
+	IPC::Run::run($cmd, '<', \$in, '>', \$stdout, '2>', \$stderr);
 
 	# See http://perldoc.perl.org/perlvar.html#%24CHILD_ERROR
 	my $ret = $?;

--------------2.20.1--


#2Kyotaro HORIGUCHI
horiguchi.kyotaro@lab.ntt.co.jp
In reply to: David Fetter (#1)
Re: [PATCH v1] Add a way to supply stdin to TAP tests

Hi.

At Sun, 28 Apr 2019 17:07:16 +0200, David Fetter <david@fetter.org> wrote in <20190428150716.GP28936@fetter.org>

Our test coverage needs all the help it can get.

This patch, extracted from another by Fabian Coelho, helps move things
in that direction.

I'd like to argue that it's not a new feature, and that it should be
back-patched as far as possible.

The comment for the parameter "in".

+# - in: standard input

Perhaps this is "string to be fed to standard input". This also
can be a I/O reference but we don't care that?

+ $in = '' if not defined $in;

run($cmd, '<', \undef) seems to work, maybe assuming "<
/dev/null", which might be better?

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

#3David Fetter
david@fetter.org
In reply to: Kyotaro HORIGUCHI (#2)
Re: [PATCH v1] Add a way to supply stdin to TAP tests

On Tue, May 07, 2019 at 11:05:32AM +0900, Kyotaro HORIGUCHI wrote:

Hi.

At Sun, 28 Apr 2019 17:07:16 +0200, David Fetter <david@fetter.org> wrote in <20190428150716.GP28936@fetter.org>

Our test coverage needs all the help it can get.

This patch, extracted from another by Fabian Coelho, helps move things
in that direction.

I'd like to argue that it's not a new feature, and that it should be
back-patched as far as possible.

The comment for the parameter "in".

+# - in: standard input

Perhaps this is "string to be fed to standard input". This also
can be a I/O reference but we don't care that?

OK

+ $in = '' if not defined $in;

run($cmd, '<', \undef) seems to work, maybe assuming "<
/dev/null", which might be better?

Is /dev/null a thing on Windows?

Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

#4Andrew Dunstan
andrew.dunstan@2ndquadrant.com
In reply to: David Fetter (#3)
Re: [PATCH v1] Add a way to supply stdin to TAP tests

On 5/6/19 10:42 PM, David Fetter wrote:

On Tue, May 07, 2019 at 11:05:32AM +0900, Kyotaro HORIGUCHI wrote:

Hi.

At Sun, 28 Apr 2019 17:07:16 +0200, David Fetter <david@fetter.org> wrote in <20190428150716.GP28936@fetter.org>

Our test coverage needs all the help it can get.

This patch, extracted from another by Fabian Coelho, helps move things
in that direction.

I'd like to argue that it's not a new feature, and that it should be
back-patched as far as possible.

The comment for the parameter "in".

+# - in: standard input

Perhaps this is "string to be fed to standard input". This also
can be a I/O reference but we don't care that?

OK

+ $in = '' if not defined $in;

run($cmd, '<', \undef) seems to work, maybe assuming "<
/dev/null", which might be better?

Is /dev/null a thing on Windows?

Not as such, although there is NUL (see src/include/port.h).

However, I don't think we should be faking anything here. I think it
would be better to  avoid setting $in if not supplied and then have this:

if (defined($in))

{

    IPC::Run::run($cmd, '<', \$in, '>', \$stdout, '2>', \$stderr);

}

else

{

    IPC::Run::run($cmd, >', \$stdout, '2>', \$stderr);   

}

cheers

andrew

--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#5David Fetter
david@fetter.org
In reply to: Andrew Dunstan (#4)
1 attachment(s)
Re: [PATCH v1] Add a way to supply stdin to TAP tests

On Tue, May 07, 2019 at 09:39:57AM -0400, Andrew Dunstan wrote:

On 5/6/19 10:42 PM, David Fetter wrote:

On Tue, May 07, 2019 at 11:05:32AM +0900, Kyotaro HORIGUCHI wrote:

Hi.

At Sun, 28 Apr 2019 17:07:16 +0200, David Fetter <david@fetter.org> wrote in <20190428150716.GP28936@fetter.org>

Our test coverage needs all the help it can get.

This patch, extracted from another by Fabian Coelho, helps move things
in that direction.

I'd like to argue that it's not a new feature, and that it should be
back-patched as far as possible.

The comment for the parameter "in".

+# - in: standard input

Perhaps this is "string to be fed to standard input". This also
can be a I/O reference but we don't care that?

OK

+ $in = '' if not defined $in;

run($cmd, '<', \undef) seems to work, maybe assuming "<
/dev/null", which might be better?

Is /dev/null a thing on Windows?

However, I don't think we should be faking anything here. I think it
would be better to� avoid setting $in if not supplied and then have this:

if (defined($in))

{

��� IPC::Run::run($cmd, '<', \$in, '>', \$stdout, '2>', \$stderr);

}

else

{

��� IPC::Run::run($cmd, >', \$stdout, '2>', \$stderr);���

}

Done that way.

Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

Attachments:

v2-0001-Add-a-way-to-supply-stdin-to-TAP-tests.patchtext/x-diff; charset=us-asciiDownload
From cfb0693c485a8b577c3fd96289ce249b3888777a Mon Sep 17 00:00:00 2001
From: David Fetter <david@fetter.org>
Date: Sun, 28 Apr 2019 08:01:01 -0700
Subject: [PATCH v2] Add a way to supply stdin to TAP tests
To: hackers
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.21.0"

This is a multi-part message in MIME format.
--------------2.21.0
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


by Fabian Coelho

This will help increase test coverage for anything that might need it,
and a lot of things currently need it.

diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm
index a164cdbd8c..6ad7f681ae 100644
--- a/src/test/perl/TestLib.pm
+++ b/src/test/perl/TestLib.pm
@@ -519,22 +519,24 @@ sub command_fails_like
 }
 
 # Run a command and check its status and outputs.
-# The 5 arguments are:
+# The 5 to 6 arguments are:
 # - cmd: ref to list for command, options and arguments to run
 # - ret: expected exit status
 # - out: ref to list of re to be checked against stdout (all must match)
 # - err: ref to list of re to be checked against stderr (all must match)
 # - test_name: name of test
+# - in: standard input
 sub command_checks_all
 {
 	local $Test::Builder::Level = $Test::Builder::Level + 1;
 
-	my ($cmd, $expected_ret, $out, $err, $test_name) = @_;
+	my ($cmd, $expected_ret, $out, $err, $test_name, $in) = @_;
+	$in = '' if not defined $in;
 
 	# run command
 	my ($stdout, $stderr);
 	print("# Running: " . join(" ", @{$cmd}) . "\n");
-	IPC::Run::run($cmd, '>', \$stdout, '2>', \$stderr);
+	IPC::Run::run($cmd, '<', \$in, '>', \$stdout, '2>', \$stderr);
 
 	# See http://perldoc.perl.org/perlvar.html#%24CHILD_ERROR
 	my $ret = $?;

--------------2.21.0--


#6David Fetter
david@fetter.org
In reply to: David Fetter (#5)
1 attachment(s)
Re: [PATCH v1] Add a way to supply stdin to TAP tests

On Tue, May 07, 2019 at 06:47:59PM +0200, David Fetter wrote:

On Tue, May 07, 2019 at 09:39:57AM -0400, Andrew Dunstan wrote:

On 5/6/19 10:42 PM, David Fetter wrote:

On Tue, May 07, 2019 at 11:05:32AM +0900, Kyotaro HORIGUCHI wrote:

Hi.

At Sun, 28 Apr 2019 17:07:16 +0200, David Fetter <david@fetter.org> wrote in <20190428150716.GP28936@fetter.org>

Our test coverage needs all the help it can get.

This patch, extracted from another by Fabian Coelho, helps move things
in that direction.

I'd like to argue that it's not a new feature, and that it should be
back-patched as far as possible.

The comment for the parameter "in".

+# - in: standard input

Perhaps this is "string to be fed to standard input". This also
can be a I/O reference but we don't care that?

OK

+ $in = '' if not defined $in;

run($cmd, '<', \undef) seems to work, maybe assuming "<
/dev/null", which might be better?

Is /dev/null a thing on Windows?

However, I don't think we should be faking anything here. I think it
would be better to� avoid setting $in if not supplied and then have this:

if (defined($in))

{

��� IPC::Run::run($cmd, '<', \$in, '>', \$stdout, '2>', \$stderr);

}

else

{

��� IPC::Run::run($cmd, >', \$stdout, '2>', \$stderr);���

}

Done that way.

It helps to commit the work before putting together the patch.

Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

Attachments:

v3-0001-Add-a-way-to-supply-stdin-to-TAP-tests.patchtext/x-diff; charset=us-asciiDownload
From 3d56bdc7acb5f70e57dc4a19b99ad31e7a13127a Mon Sep 17 00:00:00 2001
From: David Fetter <david@fetter.org>
Date: Sun, 28 Apr 2019 08:01:01 -0700
Subject: [PATCH v3] Add a way to supply stdin to TAP tests
To: hackers
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.21.0"

This is a multi-part message in MIME format.
--------------2.21.0
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


by Fabian Coelho

This will help increase test coverage for anything that might need it,
and a lot of things currently need it.

diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm
index a164cdbd8c..b9b18950ed 100644
--- a/src/test/perl/TestLib.pm
+++ b/src/test/perl/TestLib.pm
@@ -519,22 +519,30 @@ sub command_fails_like
 }
 
 # Run a command and check its status and outputs.
-# The 5 arguments are:
+# The 5 to 6 arguments are:
 # - cmd: ref to list for command, options and arguments to run
 # - ret: expected exit status
 # - out: ref to list of re to be checked against stdout (all must match)
 # - err: ref to list of re to be checked against stderr (all must match)
 # - test_name: name of test
+# - in: standard input
 sub command_checks_all
 {
 	local $Test::Builder::Level = $Test::Builder::Level + 1;
 
-	my ($cmd, $expected_ret, $out, $err, $test_name) = @_;
+	my ($cmd, $expected_ret, $out, $err, $test_name, $in) = @_;
 
 	# run command
 	my ($stdout, $stderr);
 	print("# Running: " . join(" ", @{$cmd}) . "\n");
-	IPC::Run::run($cmd, '>', \$stdout, '2>', \$stderr);
+    if (defined $in)
+    {
+        IPC::Run::run($cmd, '<', \$in, '>', \$stdout, '2>', \$stderr);
+    }
+    else
+    {
+        IPC::Run::run($cmd, '>', \$stdout, '2>', \$stderr);
+    }
 
 	# See http://perldoc.perl.org/perlvar.html#%24CHILD_ERROR
 	my $ret = $?;

--------------2.21.0--