#!/usr/bin/perl -w
use
lib
$ENV
{PERL_CORE} ?
'../lib/Module/Build/t/lib'
:
't/lib'
;
use_ok
'Module::Build'
;
ensure_blib(
'Module::Build'
);
my
$have_yaml
= Module::Build::ConfigData->feature(
'YAML_support'
);
my
$tmp
= MBTest->tmpdir;
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'
;
$mb
->add_to_cleanup(
'before_script'
);
eval
{
$mb
->create_build_script};
is $@,
''
;
ok -e
$mb
->build_script;
my
$dist_dir
=
'Simple-0.01'
;
if
($^O eq
'VMS'
) {
my
@dist_dirs
= File::Spec->splitdir(VMS::Filespec::vmsify(
$dist_dir
.
'/'
));
$dist_dir
=
$dist_dirs
[0];
}
is
$mb
->dist_dir,
$dist_dir
;
ok
grep
{
$_
eq
'before_script'
}
$mb
->cleanup;
$mb
->add_to_cleanup(
'save_out'
);
ok
grep
{
$_
eq
'before_script'
}
$mb
->cleanup;
ok
grep
{
$_
eq
'save_out'
}
$mb
->cleanup;
{
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);
$all_ok
&&= ok(-e
$mb
->localize_file_path(
'lib/Simple/Script'
));
unless
(
$all_ok
) {
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 $@,
''
;
ok -e File::Spec->catdir(
'Simple-0.01'
,
'blib'
);
eval
{
$mb
->dispatch(
'distdir'
)};
is $@,
''
;
ok -e File::Spec->catdir(
'Simple-0.01'
,
'lib'
);
ok ! -e File::Spec->catdir(
'Simple-0.01'
,
'blib'
);
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 $@,
''
;
}
}
{
my
$scripts
=
$mb
->script_files;
ok
$scripts
->{script};
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"
;
}
}
{
$mb
->dispatch(
'ppd'
,
args
=> {
codebase
=>
'/path/to/codebase'
});
my
$ppd
= slurp(
'Simple.ppd'
);
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;
}
$dist
->remove;