4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest tests => 32;
7 use Module::Build::ConfigData;
9 my $have_yaml = Module::Build::ConfigData->feature('YAML_support');
11 #########################
15 my $tmp = File::Spec->catdir( $cwd, 't', '_tmp' );
18 my $dist = DistGen->new( dir => $tmp );
19 $dist->remove_file( 't/basic.t' );
20 $dist->change_file( 'Build.PL', <<'---' );
23 my $build = new Module::Build(
24 module_name => 'Simple',
25 scripts => [ 'script' ],
27 requires => { 'File::Spec' => 0 },
29 $build->create_build_script;
31 $dist->add_file( 'script', <<'---' );
33 print "Hello, World!\n";
35 $dist->add_file( 'test.pl', <<'---' );
43 require Module::Build;
44 skip $ENV{PERL_CORE} && "no blib in core",
45 $INC{'Module/Build.pm'}, qr/blib/, 'Module::Build should be loaded from blib';
47 print "# Cwd: ", Module::Build->cwd, "\n";
48 print "# \@INC: (@INC)\n";
49 print "Done.\n"; # t/compat.t looks for this
51 $dist->add_file( 'lib/Simple/Script.PL', <<'---' );
55 open FH, "> $filename" or die "Can't create $filename: $!";
56 print FH "Contents: $filename\n";
61 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
63 #########################
69 skip "no blib in core", 1 if $ENV{PERL_CORE};
70 like $INC{'Module/Build.pm'}, qr/\bblib\b/, "Make sure version from blib/ is loaded";
73 #########################
75 my $mb = Module::Build->new_from_context;
77 is $mb->license, 'perl';
79 # Make sure cleanup files added before create_build_script() get respected
80 $mb->add_to_cleanup('before_script');
82 eval {$mb->create_build_script};
84 ok -e $mb->build_script;
86 is $mb->dist_dir, 'Simple-0.01';
88 # The 'cleanup' file doesn't exist yet
89 ok grep {$_ eq 'before_script'} $mb->cleanup;
91 $mb->add_to_cleanup('save_out');
93 # The 'cleanup' file now exists
94 ok grep {$_ eq 'before_script'} $mb->cleanup;
95 ok grep {$_ eq 'save_out' } $mb->cleanup;
98 # Make sure verbose=>1 works
101 stdout_of( sub { $mb->dispatch('test', verbose => 1) } )
103 $all_ok &&= is($@, '');
104 $all_ok &&= like($output, qr/all tests successful/i);
106 # This is the output of lib/Simple/Script.PL
107 $all_ok &&= ok(-e $mb->localize_file_path('lib/Simple/Script'));
110 # We use diag() so Test::Harness doesn't get confused.
111 diag("vvvvvvvvvvvvvvvvvvvvv Simple/test.pl output vvvvvvvvvvvvvvvvvvvvv");
113 diag("^^^^^^^^^^^^^^^^^^^^^ Simple/test.pl output ^^^^^^^^^^^^^^^^^^^^^");
118 skip( 'YAML_support feature is not enabled', 7 ) unless $have_yaml;
121 stdout_of( sub { $mb->dispatch('disttest') } )
125 # After a test, the distdir should contain a blib/ directory
126 ok -e File::Spec->catdir('Simple-0.01', 'blib');
128 eval {$mb->dispatch('distdir')};
131 # The 'distdir' should contain a lib/ directory
132 ok -e File::Spec->catdir('Simple-0.01', 'lib');
134 # The freshly run 'distdir' should never contain a blib/ directory, or
135 # else it could get into the tarball
136 ok ! -e File::Spec->catdir('Simple-0.01', 'blib');
138 # Make sure all of the above was done by the new version of Module::Build
139 my $fh = IO::File->new(File::Spec->catfile($dist->dirname, 'META.yml'));
140 my $contents = do {local $/; <$fh>};
141 $contents =~ /Module::Build version ([0-9_.]+)/m;
142 cmp_ok $1, '==', $mb->VERSION, "Check version used to create META.yml: $1 == " . $mb->VERSION;
145 skip( "not sure if we can create a tarball on this platform", 1 )
146 unless $mb->check_installed_status('Archive::Tar', 0) ||
147 $mb->isa('Module::Build::Platform::Unix');
149 $mb->add_to_cleanup($mb->dist_dir . ".tar.gz");
150 eval {$mb->dispatch('dist')};
157 # Make sure the 'script' file was recognized as a script.
158 my $scripts = $mb->script_files;
159 ok $scripts->{script};
161 # Check that a shebang line is rewritten
162 my $blib_script = File::Spec->catdir( qw( blib script script ) );
165 my $fh = IO::File->new($blib_script);
166 my $first_line = <$fh>;
167 isnt $first_line, "#!perl -w\n", "should rewrite the shebang line";
172 $mb->dispatch('ppd', args => {codebase => '/path/to/codebase'});
174 my $ppd = slurp('Simple.ppd');
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
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>
185 <DEPENDENCY NAME="File-Spec" VERSION="0,0,0,0" />
186 <CODEBASE HREF="/path/to/codebase" />
193 eval {$mb->dispatch('realclean')};
196 ok ! -e $mb->build_script;
197 ok ! -e $mb->config_dir;
198 ok ! -e $mb->dist_dir;
200 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
204 skip( 'Windows-only test', 4 ) unless $^O =~ /^MSWin/;
206 my $script_data = <<'---';
211 $dist = DistGen->new( dir => $tmp );
212 $dist->change_file( 'Build.PL', <<'---' );
214 my $build = new Module::Build(
215 module_name => 'Simple',
216 scripts => [ 'bin/script.bat' ],
219 $build->create_build_script;
221 $dist->add_file( 'bin/script.bat', $script_data );
224 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
226 $mb = Module::Build->new_from_context;
229 eval{ $mb->dispatch('build') };
232 my $script_file = File::Spec->catfile( qw(blib script), 'script.bat' );
233 ok -f $script_file, "Native batch file copied to 'scripts'";
235 my $out = slurp( $script_file );
236 is $out, $script_data, ' unmodified by pl2bat';
238 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
243 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";