-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate maniadd + readonly + noop behaviour to its own test.
- Loading branch information
1 parent
8ff20c1
commit 0900948
Showing
2 changed files
with
54 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use lib 't/lib'; | ||
use ManifestTest qw( catch_warning canon_warning spew runtemp ); | ||
use ExtUtils::Manifest qw( maniadd ); | ||
use Config; | ||
use Test::More tests => 5; | ||
|
||
my $LAST_ERROR; | ||
|
||
# Return 1 if it fatalled, undef otherwise. | ||
# Its almost bash! | ||
# !fatal = expect not fatal. | ||
# fatal = expect fatal | ||
sub fatal(&) { | ||
my ($code) = @_; | ||
my ($ok); | ||
{ | ||
local $@; | ||
$ok = eval { $code->(); 1 }; | ||
$LAST_ERROR = $@; | ||
} | ||
return !$ok; | ||
} | ||
|
||
runtemp "maniadd.unneeded_readonly" => sub { | ||
note "Ensuring maniadd does not need to write to a file for existing entries"; | ||
|
||
spew( "MANIFEST", "foo #bar\n" ); | ||
SKIP: { | ||
chmod( 0400, "MANIFEST" ); | ||
|
||
if ( -w "MANIFEST" or $Config{osname} eq "cygwin" ) { | ||
skip "Cant make manifest readonly", 5; | ||
} | ||
|
||
ok( !fatal { maniadd( { "foo" => "bar" } ) }, "maniadd() wont die adding an existing key" ) | ||
or diag $LAST_ERROR; | ||
|
||
ok( !-w "MANIFEST", "MANIFEST is still readonly" ); | ||
|
||
ok( fatal { maniadd( { "grrrwoof" => "yippie" } ) }, "maniadd will die adding a new key" ) | ||
or diag $LAST_ERROR; | ||
|
||
like( $LAST_ERROR, qr/^\Qmaniadd() could not open MANIFEST:\E/, "maniadd dies with the expected warning" ); | ||
|
||
ok( !-w "MANIFEST", "MANIFEST is still readonly" ); | ||
|
||
chmod( 0600, 'MANIFEST' ); | ||
} | ||
|
||
}; |