Skip to content

Commit de39eaa

Browse files
committed
Migrate maniadd + readonly + noop behaviour to its own test. NB. Bug found, lack of trailng \n in MANIFEST file will get manifest file marked writable
1 parent 8ff20c1 commit de39eaa

File tree

2 files changed

+53
-19
lines changed

2 files changed

+53
-19
lines changed

t/Manifest.t

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -313,25 +313,6 @@ is_deeply( $files, \%expect, 'maniadd() vs MANIFEST without trailing newline');
313313
#add_file('MANIFEST' => 'Makefile.PL');
314314
#maniadd({ foo => 'bar' });
315315

316-
SKIP: {
317-
chmod( 0400, 'MANIFEST' );
318-
skip "Can't make MANIFEST read-only", 2 if -w 'MANIFEST' or $Config{osname} eq 'cygwin';
319-
320-
eval {
321-
maniadd({ 'foo' => 'bar' });
322-
};
323-
is( $@, '', "maniadd() won't open MANIFEST if it doesn't need to" );
324-
325-
eval {
326-
maniadd({ 'grrrwoof' => 'yippie' });
327-
};
328-
like( $@, qr/^\Qmaniadd() could not open MANIFEST:\E/,
329-
"maniadd() dies if it can't open the MANIFEST" );
330-
331-
chmod( 0600, 'MANIFEST' );
332-
}
333-
334-
335316
END {
336317
note "remove all files";
337318
for my $file ( sort keys %Files ) {

t/maniadd.t

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use strict;
2+
use warnings;
3+
4+
use lib 't/lib';
5+
use ManifestTest qw( catch_warning canon_warning spew runtemp );
6+
use ExtUtils::Manifest qw( maniadd );
7+
use Config;
8+
use Test::More tests => 5;
9+
10+
my $LAST_ERROR;
11+
12+
# Return 1 if it fatalled, undef otherwise.
13+
# Its almost bash!
14+
# !fatal = expect not fatal.
15+
# fatal = expect fatal
16+
sub fatal(&) {
17+
my ($code) = @_;
18+
my ($ok);
19+
{
20+
local $@;
21+
$ok = eval { $code->(); 1 };
22+
$LAST_ERROR = $@;
23+
}
24+
return !$ok;
25+
}
26+
27+
runtemp "maniadd.unneeded_readonly" => sub {
28+
note "Ensuring maniadd does not need to write to a file to add entries";
29+
spew( "MANIFEST", "foo #bar\n" );
30+
SKIP: {
31+
chmod( 0400, "MANIFEST" );
32+
33+
if ( -w "MANIFEST" or $Config{osname} eq "cygwin" ) {
34+
skip "Cant make manifest readonly", 5;
35+
}
36+
37+
ok( !fatal { maniadd( { "foo" => "bar" } ) }, "maniadd() wont die adding an existing key" )
38+
or diag $LAST_ERROR;
39+
40+
# TODO: work out why 'maniadd' + "file without trailing newline" => File marked writeable.
41+
ok ( !-w "MANIFEST", "MANIFEST is still readonly" );
42+
43+
ok( fatal { maniadd( { "grrrwoof" => "yippie" } ) }, "maniadd will die adding a new key" )
44+
or diag $LAST_ERROR;
45+
46+
like( $LAST_ERROR, qr/^\Qmaniadd() could not open MANIFEST:\E/, "maniadd dies with the expected warning" );
47+
48+
ok ( !-w "MANIFEST", "MANIFEST is still readonly" );
49+
50+
chmod( 0600, 'MANIFEST' );
51+
}
52+
53+
};

0 commit comments

Comments
 (0)