4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest tests => 32;
7 use_ok 'Module::Build';
8 ensure_blib('Module::Build');
10 use Module::Build::ConfigData;
11 my $have_yaml = Module::Build::ConfigData->feature('YAML_support');
13 #########################
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";
61 #########################
63 my $mb = Module::Build->new_from_context;
65 is $mb->license, 'perl';
67 # Make sure cleanup files added before create_build_script() get respected
68 $mb->add_to_cleanup('before_script');
70 eval {$mb->create_build_script};
72 ok -e $mb->build_script;
74 my $dist_dir = 'Simple-0.01';
76 # VMS may or may not need to modify the name, vmsify will do this if
77 # the name looks like a UNIX directory.
79 my @dist_dirs = File::Spec->splitdir(VMS::Filespec::vmsify($dist_dir.'/'));
80 $dist_dir = $dist_dirs[0];
83 is $mb->dist_dir, $dist_dir;
85 # The 'cleanup' file doesn't exist yet
86 ok grep {$_ eq 'before_script'} $mb->cleanup;
88 $mb->add_to_cleanup('save_out');
90 # The 'cleanup' file now exists
91 ok grep {$_ eq 'before_script'} $mb->cleanup;
92 ok grep {$_ eq 'save_out' } $mb->cleanup;
95 # Make sure verbose=>1 works
98 stdout_of( sub { $mb->dispatch('test', verbose => 1) } )
100 $all_ok &&= is($@, '');
101 $all_ok &&= like($output, qr/all tests successful/i);
103 # This is the output of lib/Simple/Script.PL
104 $all_ok &&= ok(-e $mb->localize_file_path('lib/Simple/Script'));
107 # We use diag() so Test::Harness doesn't get confused.
108 diag("vvvvvvvvvvvvvvvvvvvvv Simple/test.pl output vvvvvvvvvvvvvvvvvvvvv");
110 diag("^^^^^^^^^^^^^^^^^^^^^ Simple/test.pl output ^^^^^^^^^^^^^^^^^^^^^");
115 skip( 'YAML_support feature is not enabled', 7 ) unless $have_yaml;
118 stdout_of( sub { $mb->dispatch('disttest') } )
122 # After a test, the distdir should contain a blib/ directory
123 ok -e File::Spec->catdir('Simple-0.01', 'blib');
125 eval {$mb->dispatch('distdir')};
128 # The 'distdir' should contain a lib/ directory
129 ok -e File::Spec->catdir('Simple-0.01', 'lib');
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');
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;
142 skip( "not sure if we can create a tarball on this platform", 1 )
143 unless $mb->check_installed_version('Archive::Tar', 0) ||
144 $mb->isa('Module::Build::Platform::Unix');
146 $mb->add_to_cleanup($mb->dist_dir . ".tar.gz");
147 eval {$mb->dispatch('dist')};
154 # Make sure the 'script' file was recognized as a script.
155 my $scripts = $mb->script_files;
156 ok $scripts->{script};
158 # Check that a shebang line is rewritten
159 my $blib_script = File::Spec->catfile( qw( blib script script ) );
163 skip("We do not rewrite shebang on VMS", 1) if $^O eq 'VMS';
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";
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;
203 skip( 'Windows-only test', 4 ) unless $^O =~ /^MSWin/;
205 my $script_data = <<'---';
210 $dist = DistGen->new( dir => $tmp );
211 $dist->change_build_pl({
212 module_name => 'Simple',
213 scripts => [ 'bin/script.bat' ],
217 $dist->add_file( 'bin/script.bat', $script_data );
222 $mb = Module::Build->new_from_context;
225 eval{ $mb->dispatch('build') };
228 my $script_file = File::Spec->catfile( qw(blib script), 'script.bat' );
229 ok -f $script_file, "Native batch file copied to 'scripts'";
231 my $out = slurp( $script_file );
232 is $out, $script_data, ' unmodified by pl2bat';