Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autodie doesn't seem to work if perl5i invoked on the command line #248

Open
frithnanth opened this issue Mar 25, 2013 · 4 comments
Open

Comments

@frithnanth
Copy link

At least on my computer:

cpanm perl5i

perl5i is up to date. (v2.11.2)

$ perl5i -e 'open my $in, "<", "nosuchfile"'
$ perl -Mperl5i::2 -e 'open my $in, "<", "nosuchfile"'
Can't open 'nosuchfile' for reading: 'No such file or directory' at -e line 1
$ cat test.pl

!/usr/bin/env perl5i

open my $in, "<", "nosuchfile";
$ ./test.pl
Can't open 'nosuchfile' for reading: 'No such file or directory' at ./test.pl line 3

@schwern
Copy link
Contributor

schwern commented Mar 25, 2013

Looks like it was working in the past, but not now. PERL5LIB=lib ./bin/perl5i -e 'open my $in, "<", "nosuchfile"' works with v2.0.3 but not v2.11.2.

Did a git bisect on it and discovered the problem was introduced in 1c6f3e8. I'll have a look at the bug later if someone doesn't beat me to it.

Would you write up a test please? It would go into t/command_line.t.

@frithnanth
Copy link
Author

This should work on a *nix system. I don't know how to handle the redirection on a Windows box.

#!/usr/bin/env perl

use Test::Simple tests => 2;

my $result = qx{perl5i -e 'open my $in, "<", "nosuchfile"'};
ok($result eq qq{Can't open 'nosuchfile' for reading: } .
qq{'No such file or directory' at -e line 1\n},
"Autodie with perl5i -e");

$result = qx{perl -Mperl5i -e 'open my $in, "<", "nosuchfile"' 2>&1};
ok($result eq qq{Can't open 'nosuchfile' for reading: } .
qq{'No such file or directory' at -e line 1\n},
"Autodie with perl -Mperl5i -e");

@frithnanth
Copy link
Author

Sorry, correct version:

#!/usr/bin/env perl

use Test::Simple tests => 2;

my $result = qx{perl5i -e 'open my $in, "<", "nosuchfile"' 2>&1};
ok($result eq qq{Can't open 'nosuchfile' for reading: } .
qq{'No such file or directory' at -e line 1\n},
"Autodie with perl5i -e");

$result = qx{perl -Mperl5i -e 'open my $in, "<", "nosuchfile"' 2>&1};
ok($result eq qq{Can't open 'nosuchfile' for reading: } .
qq{'No such file or directory' at -e line 1\n},
"Autodie with perl -Mperl5i -e");

@frithnanth
Copy link
Author

OK, I'm confused.
I was trying to write a more "portable" test and I've just wrote the following lines.
What surprises me is that now the first test doesn't fail anymore.

#!/usr/bin/env perl

use IPC::Run 'run';
use Test::Simple tests => 2;

sub myrun
{
run(@_, \my($in, $out, $err));
return $err;
}

my $err = myrun "perl5i", q{-e open my $in, "<", "nosuchfile"};
ok($err eq qq{Can't open 'nosuchfile' for reading: } .
qq{'No such file or directory' at -e line 1\n},
"Autodie with perl5i -e");

$err = myrun "perl", q{-Mperl5i::2}, q{-e open my $in, "<", "nosuchfile"};
ok($err eq qq{Can't open 'nosuchfile' for reading: } .
qq{'No such file or directory' at -e line 1\n},
"Autodie with perl -Mperl5i -e");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants