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 = MBTest->tmpdir;
18 my $dist = DistGen->new( dir => $tmp );
19 $dist->remove_file( 't/basic.t' );
20 $dist->change_build_pl
22 module_name => 'Simple',
23 scripts => [ 'script' ],
25 requires => { 'File::Spec' => 0 },
28 $dist->add_file( 'script', <<'---' );
30 print "Hello, World!\n";
32 $dist->add_file( 'test.pl', <<'---' );
40 require Module::Build;
41 skip $ENV{PERL_CORE} && "no blib in core",
42 $INC{'Module/Build.pm'}, qr/blib/, 'Module::Build should be loaded from blib';
44 print "# Cwd: ", Module::Build->cwd, "\n";
45 print "# \@INC: (@INC)\n";
46 print "Done.\n"; # t/compat.t looks for this
48 $dist->add_file( 'lib/Simple/Script.PL', <<'---' );
52 open FH, "> $filename" or die "Can't create $filename: $!";
53 print FH "Contents: $filename\n";
58 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
60 #########################
66 skip "no blib in core", 1 if $ENV{PERL_CORE};
67 like $INC{'Module/Build.pm'}, qr/\bblib\b/, "Make sure version from blib/ is loaded";
70 #########################
72 my $mb = Module::Build->new_from_context;
74 is $mb->license, 'perl';
76 # Make sure cleanup files added before create_build_script() get respected
77 $mb->add_to_cleanup('before_script');
79 eval {$mb->create_build_script};
81 ok -e $mb->build_script;
83 my $dist_dir = 'Simple-0.01';
85 # VMS may or may not need to modify the name, vmsify will do this if
86 # the name looks like a UNIX directory.
88 my @dist_dirs = File::Spec->splitdir(VMS::Filespec::vmsify($dist_dir.'/'));
89 $dist_dir = $dist_dirs[0];
92 is $mb->dist_dir, $dist_dir;
94 # The 'cleanup' file doesn't exist yet
95 ok grep {$_ eq 'before_script'} $mb->cleanup;
97 $mb->add_to_cleanup('save_out');
99 # The 'cleanup' file now exists
100 ok grep {$_ eq 'before_script'} $mb->cleanup;
101 ok grep {$_ eq 'save_out' } $mb->cleanup;
104 # Make sure verbose=>1 works
107 stdout_of( sub { $mb->dispatch('test', verbose => 1) } )
109 $all_ok &&= is($@, '');
110 $all_ok &&= like($output, qr/all tests successful/i);
112 # This is the output of lib/Simple/Script.PL
113 $all_ok &&= ok(-e $mb->localize_file_path('lib/Simple/Script'));
116 # We use diag() so Test::Harness doesn't get confused.
117 diag("vvvvvvvvvvvvvvvvvvvvv Simple/test.pl output vvvvvvvvvvvvvvvvvvvvv");
119 diag("^^^^^^^^^^^^^^^^^^^^^ Simple/test.pl output ^^^^^^^^^^^^^^^^^^^^^");
124 skip( 'YAML_support feature is not enabled', 7 ) unless $have_yaml;
127 stdout_of( sub { $mb->dispatch('disttest') } )
131 # After a test, the distdir should contain a blib/ directory
132 ok -e File::Spec->catdir('Simple-0.01', 'blib');
134 eval {$mb->dispatch('distdir')};
137 # The 'distdir' should contain a lib/ directory
138 ok -e File::Spec->catdir('Simple-0.01', 'lib');
140 # The freshly run 'distdir' should never contain a blib/ directory, or
141 # else it could get into the tarball
142 ok ! -e File::Spec->catdir('Simple-0.01', 'blib');
144 # Make sure all of the above was done by the new version of Module::Build
145 my $fh = IO::File->new(File::Spec->catfile($dist->dirname, 'META.yml'));
146 my $contents = do {local $/; <$fh>};
147 $contents =~ /Module::Build version ([0-9_.]+)/m;
148 cmp_ok $1, '==', $mb->VERSION, "Check version used to create META.yml: $1 == " . $mb->VERSION;
151 skip( "not sure if we can create a tarball on this platform", 1 )
152 unless $mb->check_installed_status('Archive::Tar', 0) ||
153 $mb->isa('Module::Build::Platform::Unix');
155 $mb->add_to_cleanup($mb->dist_dir . ".tar.gz");
156 eval {$mb->dispatch('dist')};
163 # Make sure the 'script' file was recognized as a script.
164 my $scripts = $mb->script_files;
165 ok $scripts->{script};
167 # Check that a shebang line is rewritten
168 my $blib_script = File::Spec->catfile( qw( blib script script ) );
172 skip("We do not rewrite shebang on VMS", 1) if $^O eq 'VMS';
173 my $fh = IO::File->new($blib_script);
174 my $first_line = <$fh>;
175 isnt $first_line, "#!perl -w\n", "should rewrite the shebang line";
181 $mb->dispatch('ppd', args => {codebase => '/path/to/codebase'});
183 my $ppd = slurp('Simple.ppd');
185 # This test is quite a hack since with XML you don't really want to
186 # do a strict string comparison, but absent an XML parser it's the
189 <SOFTPKG NAME="Simple" VERSION="0,01,0,0">
190 <TITLE>Simple</TITLE>
191 <ABSTRACT>Perl extension for blah blah blah</ABSTRACT>
192 <AUTHOR>A. U. Thor, a.u.thor@a.galaxy.far.far.away</AUTHOR>
194 <DEPENDENCY NAME="File-Spec" VERSION="0,0,0,0" />
195 <CODEBASE HREF="/path/to/codebase" />
202 eval {$mb->dispatch('realclean')};
205 ok ! -e $mb->build_script;
206 ok ! -e $mb->config_dir;
207 ok ! -e $mb->dist_dir;
209 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
213 skip( 'Windows-only test', 4 ) unless $^O =~ /^MSWin/;
215 my $script_data = <<'---';
220 $dist = DistGen->new( dir => $tmp );
221 $dist->change_build_pl({
222 module_name => 'Simple',
223 scripts => [ 'bin/script.bat' ],
227 $dist->add_file( 'bin/script.bat', $script_data );
230 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
232 $mb = Module::Build->new_from_context;
235 eval{ $mb->dispatch('build') };
238 my $script_file = File::Spec->catfile( qw(blib script), 'script.bat' );
239 ok -f $script_file, "Native batch file copied to 'scripts'";
241 my $out = slurp( $script_file );
242 is $out, $script_data, ' unmodified by pl2bat';
244 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
249 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";