dbdpg icon indicating copy to clipboard operation
dbdpg copied to clipboard

Tests fail if root's shell is not a Bourne shell

Open AnneBennett opened this issue 3 years ago • 1 comments

At line 40 in t/dbdpg_test_setup.pl there's an "su" call which redirects output using Bourne shell syntax: $info = qx{su -m $testuser -c "$initdb --locale=C -E UTF8 -D $testdir/data 2>&1"}; If root's shell is, for example, tcsh, the above fails as follows: it writes to a file called "1" in the testdir: initdb: error: too many command-line arguments (first is "2") Try "initdb --help" for more information. In other words, it interprets the command, including "2>&1", using (in my case) tcsh.

I was able to work around that by setting the environment variable SHELL to /bin/sh before calling "cpan DBD::Pg", but you might consider setting that in the test environment, or as a --shell option to su, or perhaps putting a warning about this in the README file.

Thanks very much for DBD-Pg - I use it all the time! Much appreciated!

Anne.

AnneBennett avatar Nov 07 '22 03:11 AnneBennett

Unfortunately, su -s /bin/sh doesn't work on macOS, Solaris, or FreeBSD. The su commands on those operating systems don't support -s/--shell. I'm not sure if all those are supported by DBD::Pg, but I know there are some macOS users.

Maybe $info = qx{su -m $testuser -c "/bin/sh -c '$initdb --locale=C -E UTF8 -D $testdir/data 2>&1'"};? (Untested.)

esabol avatar Nov 07 '22 04:11 esabol

That seems to work, from my limited testing by forcing tcsh as a default shell. @AnneBennett could you test the solution above on your system?

turnstep avatar Mar 05 '23 00:03 turnstep

That seems to work, from my limited testing by forcing tcsh as a default shell. @AnneBennett could you test the solution above on your system?

I'll look into this in a couple of weeks; I don't have access to the environment to test this just now.

Anne.

AnneBennett avatar Mar 05 '23 01:03 AnneBennett

That seems to work, from my limited testing by forcing tcsh as a default shell. @AnneBennett could you test the solution above on your system?

Sorry about the delay.

I went to the first build directory that cpan had created for this installation back in November, and I edited t/dbdpg_test_setup.pl at line 410 from:

$info = qx{su -m $testuser -c "$initdb --locale=C -E UTF8 -D $testdir/data 2>&1"};

to:

$info = qx{su -m $testuser -c "/bin/sh -c '$initdb --locale=C -E UTF8 -D $testdir/data 2>&1'"};

Then I ran "make clean; /path/to/perl Makefile.PL; make; make test". Tests passed! :-)

Anne.

AnneBennett avatar Mar 23 '23 20:03 AnneBennett

Thanks, @AnneBennett ! I have submitted PR #114 with the change you've tested in order to address this.

esabol avatar Mar 23 '23 23:03 esabol

Fixed as of DBD::Pg version 3.16.2

turnstep avatar Aug 14 '23 19:08 turnstep