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