1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
|
#!/usr/bin/perl -w
use strict;
use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
use MBTest tests => 32;
use_ok 'Module::Build';
ensure_blib('Module::Build');
use Module::Build::ConfigData;
my $have_yaml = Module::Build::ConfigData->feature('YAML_support');
#########################
my $tmp = MBTest->tmpdir;
use DistGen;
my $dist = DistGen->new( dir => $tmp );
$dist->remove_file( 't/basic.t' );
$dist->change_build_pl
({
module_name => 'Simple',
scripts => [ 'script' ],
license => 'perl',
requires => { 'File::Spec' => 0 },
});
$dist->add_file( 'script', <<'---' );
#!perl -w
print "Hello, World!\n";
---
$dist->add_file( 'test.pl', <<'---' );
#!/usr/bin/perl
use Test;
plan tests => 2;
ok 1;
require Module::Build;
skip $ENV{PERL_CORE} && "no blib in core",
$INC{'Module/Build.pm'}, qr/blib/, 'Module::Build should be loaded from blib';
print "# Cwd: ", Module::Build->cwd, "\n";
print "# \@INC: (@INC)\n";
print "Done.\n"; # t/compat.t looks for this
---
$dist->add_file( 'lib/Simple/Script.PL', <<'---' );
#!perl -w
my $filename = shift;
open FH, "> $filename" or die "Can't create $filename: $!";
print FH "Contents: $filename\n";
close FH;
---
$dist->regen;
$dist->chdir_in;
#########################
my $mb = Module::Build->new_from_context;
ok $mb;
is $mb->license, 'perl';
# Make sure cleanup files added before create_build_script() get respected
$mb->add_to_cleanup('before_script');
eval {$mb->create_build_script};
is $@, '';
ok -e $mb->build_script;
my $dist_dir = 'Simple-0.01';
# VMS in traditional mode needs the $dist_dir name to not have a '.' in it
# as this is a directory delimiter. In extended character set mode the dot
# is permitted for Unix format file specifications.
if ($^O eq 'VMS') {
my $Is_VMS_noefs = 1;
my $vms_efs = 0;
if (eval 'require VMS::Feature') {
$vms_efs = VMS::Feature::current("efs_charset");
} else {
my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || '';
$vms_efs = $efs_charset =~ /^[ET1]/i;
}
$Is_VMS_noefs = 0 if $vms_efs;
if ($Is_VMS_noefs) {
$dist_dir = 'Simple-0_01';
}
}
is $mb->dist_dir, $dist_dir;
# The 'cleanup' file doesn't exist yet
ok grep {$_ eq 'before_script'} $mb->cleanup;
$mb->add_to_cleanup('save_out');
# The 'cleanup' file now exists
ok grep {$_ eq 'before_script'} $mb->cleanup;
ok grep {$_ eq 'save_out' } $mb->cleanup;
{
# Make sure verbose=>1 works
my $all_ok = 1;
my $output = eval {
stdout_of( sub { $mb->dispatch('test', verbose => 1) } )
};
$all_ok &&= is($@, '');
$all_ok &&= like($output, qr/all tests successful/i);
# This is the output of lib/Simple/Script.PL
$all_ok &&= ok(-e $mb->localize_file_path('lib/Simple/Script'));
unless ($all_ok) {
# We use diag() so Test::Harness doesn't get confused.
diag("vvvvvvvvvvvvvvvvvvvvv Simple/test.pl output vvvvvvvvvvvvvvvvvvvvv");
diag($output);
diag("^^^^^^^^^^^^^^^^^^^^^ Simple/test.pl output ^^^^^^^^^^^^^^^^^^^^^");
}
}
SKIP: {
skip( 'YAML_support feature is not enabled', 7 ) unless $have_yaml;
my $output = eval {
stdout_of( sub { $mb->dispatch('disttest') } )
};
is $@, '';
# After a test, the distdir should contain a blib/ directory
ok -e File::Spec->catdir('Simple-0.01', 'blib');
eval {$mb->dispatch('distdir')};
is $@, '';
# The 'distdir' should contain a lib/ directory
ok -e File::Spec->catdir('Simple-0.01', 'lib');
# The freshly run 'distdir' should never contain a blib/ directory, or
# else it could get into the tarball
ok ! -e File::Spec->catdir('Simple-0.01', 'blib');
# Make sure all of the above was done by the new version of Module::Build
my $fh = IO::File->new(File::Spec->catfile($dist->dirname, 'META.yml'));
my $contents = do {local $/; <$fh>};
$contents =~ /Module::Build version ([0-9_.]+)/m;
cmp_ok $1, '==', $mb->VERSION, "Check version used to create META.yml: $1 == " . $mb->VERSION;
SKIP: {
skip( "not sure if we can create a tarball on this platform", 1 )
unless $mb->check_installed_version('Archive::Tar', 0) ||
$mb->isa('Module::Build::Platform::Unix');
$mb->add_to_cleanup($mb->dist_dir . ".tar.gz");
eval {$mb->dispatch('dist')};
is $@, '';
}
}
{
# Make sure the 'script' file was recognized as a script.
my $scripts = $mb->script_files;
ok $scripts->{script};
# Check that a shebang line is rewritten
my $blib_script = File::Spec->catfile( qw( blib script script ) );
ok -e $blib_script;
SKIP: {
skip("We do not rewrite shebang on VMS", 1) if $^O eq 'VMS';
my $fh = IO::File->new($blib_script);
my $first_line = <$fh>;
isnt $first_line, "#!perl -w\n", "should rewrite the shebang line";
}
}
{
# Check PPD
$mb->dispatch('ppd', args => {codebase => '/path/to/codebase'});
my $ppd = slurp('Simple.ppd');
# This test is quite a hack since with XML you don't really want to
# do a strict string comparison, but absent an XML parser it's the
# best we can do.
is $ppd, <<'EOF';
<SOFTPKG NAME="Simple" VERSION="0,01,0,0">
<TITLE>Simple</TITLE>
<ABSTRACT>Perl extension for blah blah blah</ABSTRACT>
<AUTHOR>A. U. Thor, a.u.thor@a.galaxy.far.far.away</AUTHOR>
<IMPLEMENTATION>
<DEPENDENCY NAME="File-Spec" VERSION="0,0,0,0" />
<CODEBASE HREF="/path/to/codebase" />
</IMPLEMENTATION>
</SOFTPKG>
EOF
}
eval {$mb->dispatch('realclean')};
is $@, '';
ok ! -e $mb->build_script;
ok ! -e $mb->config_dir;
ok ! -e $mb->dist_dir;
$dist->remove;
SKIP: {
skip( 'Windows-only test', 4 ) unless $^O =~ /^MSWin/;
my $script_data = <<'---';
@echo off
echo Hello, World!
---
$dist = DistGen->new( dir => $tmp );
$dist->change_build_pl({
module_name => 'Simple',
scripts => [ 'bin/script.bat' ],
license => 'perl',
});
$dist->add_file( 'bin/script.bat', $script_data );
$dist->regen;
$dist->chdir_in;
$mb = Module::Build->new_from_context;
ok $mb;
eval{ $mb->dispatch('build') };
is $@, '';
my $script_file = File::Spec->catfile( qw(blib script), 'script.bat' );
ok -f $script_file, "Native batch file copied to 'scripts'";
my $out = slurp( $script_file );
is $out, $script_data, ' unmodified by pl2bat';
$dist->remove;
}
# cleanup
$dist->remove;
|