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 is incompatible with Test::MockFile #44

Open
toddr opened this issue May 3, 2019 · 8 comments
Open

autodie is incompatible with Test::MockFile #44

toddr opened this issue May 3, 2019 · 8 comments

Comments

@toddr
Copy link
Member

toddr commented May 3, 2019

$>perl -Mautodie -MTest::MockFile -E'my $file = "/log"; my $logg = Test::MockFile->file( $file, "one\ntwo\n"); open(my $fh, "<", $file) or die($!); say <$fh>' 
Can't open '/log' for reading: 'No such file or directory' at -e line 1
190503.133746 [email protected] (/usr/local/cpanel)

$>perl -MTest::MockFile -E'my $file = "/log"; my $logg = Test::MockFile->file( $file, "one\ntwo\n"); open(my $fh, "<", $file) or die($!); say <$fh>'
one
two
@toddr
Copy link
Member Author

toddr commented May 3, 2019

On load of Test::MockFile, we need to die if we detect $INC{'autodie.pm'}.

@FGasper
Copy link
Contributor

FGasper commented May 3, 2019

@toddr: That seems a pretty aggressive approach. It assumes one part of a test won’t use the mock and another won’t use a temp directory.

Is it possible to work with it if there is “no autodie” local to the T::MF usage?

@toddr
Copy link
Member Author

toddr commented May 3, 2019

I would have to provide an unimport and so would autodie if it doesn't already. That's a perfectly good phase 2 but that'd be a lot of work.

@FGasper
Copy link
Contributor

FGasper commented May 10, 2019

Another problem with the idea of making autodie mutually exclusive with this module is that autodie also encompasses non-filesystem operations. I suspect it’s not uncommon, for example, for tests to create a pair of sockets via socketpair and do tests on those. That’s a case where autodie is useful but has nothing to do with T::MF.

@atoomic
Copy link
Contributor

atoomic commented Aug 11, 2021

another example

╰─> perl -MTest::MockFile -E 'use autodie; my $f = q[/a/b/c]; my $m = Test::MockFile->file(q[/a/b/c] => 123); say q[ok] if -f $f; open(my $fh, "+<", $f ) or die $!'
ok
Can't open '/a/b/c' with mode '+<': 'No such file or directory' at -e line 1

@FGasper
Copy link
Contributor

FGasper commented Aug 12, 2021

It may be better to wait until Leon’s autocroak module is usable than to try to fix this.

@FGasper
Copy link
Contributor

FGasper commented Mar 4, 2022

https://github.com/cpanel/p5-Filesys-Restrict (private repo) would also address this, perhaps more neatly.

@tomgreen98
Copy link

Im wondering if this needs some effort to work with autodie and similar tools. More and more code we see is using patterns similar to autodie. Being able to mock the filesystem is much nicer than using a temp folder.

There has got to be a way to patch autodie to work with these mocks when Test::MockFile sees autodie or similar is loaded.

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

No branches or pull requests

4 participants