forked from redhotpenguin/perl-Archive-Zip
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch to ensure filehandles created by Archive::Zip::tempFile are clo…
…sed properly
- Loading branch information
1 parent
cc9e250
commit 3d90cee
Showing
4 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/perl | ||
|
||
# Test to make sure temporal filehandles created by Archive::Zip::tempFile are closed properly | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Archive::Zip; | ||
use Test::MockModule; | ||
|
||
use Test::More tests => 2; | ||
|
||
# array to store open filhandles | ||
my @opened_filehandles; | ||
|
||
# mocking File::Temp to store returned filehandles | ||
my $mock_file_temp = Test::MockModule->new('File::Temp'); | ||
|
||
my $previous_tempfile_sub = \&File::Temp::tmpfile; | ||
$mock_file_temp->mock( | ||
tempfile => sub { | ||
my ( $fh, $filename ) = $previous_tempfile_sub->(@_); | ||
push( @opened_filehandles, $fh ); | ||
return ( $fh, $filename ); | ||
} | ||
); | ||
|
||
# calling method | ||
Archive::Zip::tempFile(); | ||
|
||
# testing filehandles are closed | ||
ok( scalar @opened_filehandles == 1, "One filehandle was created" ); | ||
ok( !defined $opened_filehandles[0] | ||
|| !defined fileno( $opened_filehandles[0] ) | ||
|| fileno( $opened_filehandles[0] ) == -1, | ||
"Filehandle is closed" | ||
); | ||
|
3d90cee
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, 👍