Skip to content

Commit

Permalink
Migrate maniadd + readonly + noop behaviour to its own test.
Browse files Browse the repository at this point in the history
  • Loading branch information
kentfredric committed Apr 6, 2015
1 parent 8ff20c1 commit 0900948
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 deletions.
21 changes: 1 addition & 20 deletions t/Manifest.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ chdir 't';

use strict;

use Test::More tests => 66;
use Test::More tests => 64;
use Cwd;

use File::Spec;
Expand Down Expand Up @@ -313,25 +313,6 @@ is_deeply( $files, \%expect, 'maniadd() vs MANIFEST without trailing newline');
#add_file('MANIFEST' => 'Makefile.PL');
#maniadd({ foo => 'bar' });

SKIP: {
chmod( 0400, 'MANIFEST' );
skip "Can't make MANIFEST read-only", 2 if -w 'MANIFEST' or $Config{osname} eq 'cygwin';

eval {
maniadd({ 'foo' => 'bar' });
};
is( $@, '', "maniadd() won't open MANIFEST if it doesn't need to" );

eval {
maniadd({ 'grrrwoof' => 'yippie' });
};
like( $@, qr/^\Qmaniadd() could not open MANIFEST:\E/,
"maniadd() dies if it can't open the MANIFEST" );

chmod( 0600, 'MANIFEST' );
}


END {
note "remove all files";
for my $file ( sort keys %Files ) {
Expand Down
53 changes: 53 additions & 0 deletions t/maniadd.t
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' );
}

};

0 comments on commit 0900948

Please sign in to comment.