Remove unused Module::Build tests
[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 6use Module::Build;
7use Module::Build::ConfigData;
8
9my $have_yaml = Module::Build::ConfigData->feature('YAML_support');
10
11#########################
12
13use Cwd ();
14my $cwd = Cwd::cwd;
15my $tmp = File::Spec->catdir( $cwd, 't', '_tmp' );
16
17use DistGen;
18my $dist = DistGen->new( dir => $tmp );
19$dist->remove_file( 't/basic.t' );
20$dist->change_file( 'Build.PL', <<'---' );
21use Module::Build;
22
23my $build = new Module::Build(
24 module_name => 'Simple',
25 scripts => [ 'script' ],
26 license => 'perl',
27 requires => { 'File::Spec' => 0 },
28);
29$build->create_build_script;
30---
31$dist->add_file( 'script', <<'---' );
32#!perl -w
33print "Hello, World!\n";
34---
35$dist->add_file( 'test.pl', <<'---' );
36#!/usr/bin/perl
37
38use Test;
39plan tests => 2;
40
41ok 1;
42
43require Module::Build;
44skip $ENV{PERL_CORE} && "no blib in core",
45 $INC{'Module/Build.pm'}, qr/blib/, 'Module::Build should be loaded from blib';
46
47print "# Cwd: ", Module::Build->cwd, "\n";
48print "# \@INC: (@INC)\n";
49print "Done.\n"; # t/compat.t looks for this
50---
51$dist->add_file( 'lib/Simple/Script.PL', <<'---' );
52#!perl -w
53
54my $filename = shift;
55open FH, "> $filename" or die "Can't create $filename: $!";
56print FH "Contents: $filename\n";
57close FH;
58---
59$dist->regen;
60
61chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
62
63#########################
64
65use Module::Build;
66ok(1);
67
68SKIP: {
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";
71}
72
73#########################
74
75my $mb = Module::Build->new_from_context;
76ok $mb;
77is $mb->license, 'perl';
78
79# Make sure cleanup files added before create_build_script() get respected
80$mb->add_to_cleanup('before_script');
81
82eval {$mb->create_build_script};
83is $@, '';
84ok -e $mb->build_script;
85
86is $mb->dist_dir, 'Simple-0.01';
87
88# The 'cleanup' file doesn't exist yet
89ok grep {$_ eq 'before_script'} $mb->cleanup;
90
91$mb->add_to_cleanup('save_out');
92
93# The 'cleanup' file now exists
94ok grep {$_ eq 'before_script'} $mb->cleanup;
95ok grep {$_ eq 'save_out' } $mb->cleanup;
96
97{
98 # Make sure verbose=>1 works
99 my $all_ok = 1;
100 my $output = eval {
101 stdout_of( sub { $mb->dispatch('test', verbose => 1) } )
102 };
103 $all_ok &&= is($@, '');
104 $all_ok &&= like($output, qr/all tests successful/i);
105
106 # This is the output of lib/Simple/Script.PL
107 $all_ok &&= ok(-e $mb->localize_file_path('lib/Simple/Script'));
108
109 unless ($all_ok) {
110 # We use diag() so Test::Harness doesn't get confused.
111 diag("vvvvvvvvvvvvvvvvvvvvv Simple/test.pl output vvvvvvvvvvvvvvvvvvvvv");
112 diag($output);
113 diag("^^^^^^^^^^^^^^^^^^^^^ Simple/test.pl output ^^^^^^^^^^^^^^^^^^^^^");
114 }
115}
116
117SKIP: {
118 skip( 'YAML_support feature is not enabled', 7 ) unless $have_yaml;
119
120 my $output = eval {
121 stdout_of( sub { $mb->dispatch('disttest') } )
122 };
123 is $@, '';
124
125 # After a test, the distdir should contain a blib/ directory
126 ok -e File::Spec->catdir('Simple-0.01', 'blib');
127
128 eval {$mb->dispatch('distdir')};
129 is $@, '';
130
131 # The 'distdir' should contain a lib/ directory
132 ok -e File::Spec->catdir('Simple-0.01', 'lib');
133
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');
137
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;
143
144 SKIP: {
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');
148
149 $mb->add_to_cleanup($mb->dist_dir . ".tar.gz");
150 eval {$mb->dispatch('dist')};
151 is $@, '';
152 }
153
154}
155
156{
157 # Make sure the 'script' file was recognized as a script.
158 my $scripts = $mb->script_files;
159 ok $scripts->{script};
160
161 # Check that a shebang line is rewritten
162 my $blib_script = File::Spec->catdir( qw( blib script script ) );
163 ok -e $blib_script;
164
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";
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 200chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
201$dist->remove;
202
203SKIP: {
b3dfda33 204 skip( 'Windows-only test', 4 ) unless $^O =~ /^MSWin/;
f943a5bf 205
206 my $script_data = <<'---';
207@echo off
208echo Hello, World!
209---
210
211 $dist = DistGen->new( dir => $tmp );
212 $dist->change_file( 'Build.PL', <<'---' );
213use Module::Build;
214my $build = new Module::Build(
215 module_name => 'Simple',
216 scripts => [ 'bin/script.bat' ],
217 license => 'perl',
218);
219$build->create_build_script;
220---
221 $dist->add_file( 'bin/script.bat', $script_data );
222
223 $dist->regen;
224 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
225
226 $mb = Module::Build->new_from_context;
227 ok $mb;
228
229 eval{ $mb->dispatch('build') };
230 is $@, '';
231
232 my $script_file = File::Spec->catfile( qw(blib script), 'script.bat' );
233 ok -f $script_file, "Native batch file copied to 'scripts'";
234
235 my $out = slurp( $script_file );
236 is $out, $script_data, ' unmodified by pl2bat';
237
238 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
239 $dist->remove;
240}
bb4e9162 241
242# cleanup
243chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
244$dist->remove;
245
246use File::Path;
247rmtree( $tmp );