Add the original source packages to maemo, source lenny
[dh-make-perl] / dev / i386 / libmodule-build-perl / libmodule-build-perl-0.2808.01 / t / runthrough.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest tests => 32;
6 use Module::Build;
7 use Module::Build::ConfigData;
8
9 my $have_yaml = Module::Build::ConfigData->feature('YAML_support');
10
11 #########################
12
13 use Cwd ();
14 my $cwd = Cwd::cwd;
15 my $tmp = MBTest->tmpdir;
16
17 use DistGen;
18 my $dist = DistGen->new( dir => $tmp );
19 $dist->remove_file( 't/basic.t' );
20 $dist->change_build_pl
21 ({
22   module_name => 'Simple',
23   scripts     => [ 'script' ],
24   license     => 'perl',
25   requires    => { 'File::Spec' => 0 },
26 });
27
28 $dist->add_file( 'script', <<'---' );
29 #!perl -w
30 print "Hello, World!\n";
31 ---
32 $dist->add_file( 'test.pl', <<'---' );
33 #!/usr/bin/perl
34
35 use Test;
36 plan tests => 2;
37
38 ok 1;
39
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';
43
44 print "# Cwd: ", Module::Build->cwd, "\n";
45 print "# \@INC: (@INC)\n";
46 print "Done.\n";  # t/compat.t looks for this
47 ---
48 $dist->add_file( 'lib/Simple/Script.PL', <<'---' );
49 #!perl -w
50
51 my $filename = shift;
52 open FH, "> $filename" or die "Can't create $filename: $!";
53 print FH "Contents: $filename\n";
54 close FH;
55 ---
56 $dist->regen;
57
58 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
59
60 #########################
61
62 use Module::Build;
63 ok(1);
64
65 SKIP: {
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";
68 }
69
70 #########################
71
72 my $mb = Module::Build->new_from_context;
73 ok $mb;
74 is $mb->license, 'perl';
75
76 # Make sure cleanup files added before create_build_script() get respected
77 $mb->add_to_cleanup('before_script');
78
79 eval {$mb->create_build_script};
80 is $@, '';
81 ok -e $mb->build_script;
82
83 my $dist_dir = 'Simple-0.01';
84
85 # VMS may or may not need to modify the name, vmsify will do this if
86 # the name looks like a UNIX directory.
87 if ($^O eq 'VMS') {
88    my @dist_dirs = File::Spec->splitdir(VMS::Filespec::vmsify($dist_dir.'/'));
89    $dist_dir = $dist_dirs[0];
90 }
91
92 is $mb->dist_dir, $dist_dir;
93
94 # The 'cleanup' file doesn't exist yet
95 ok grep {$_ eq 'before_script'} $mb->cleanup;
96
97 $mb->add_to_cleanup('save_out');
98
99 # The 'cleanup' file now exists
100 ok grep {$_ eq 'before_script'} $mb->cleanup;
101 ok grep {$_ eq 'save_out'     } $mb->cleanup;
102
103 {
104   # Make sure verbose=>1 works
105   my $all_ok = 1;
106   my $output = eval {
107     stdout_of( sub { $mb->dispatch('test', verbose => 1) } )
108   };
109   $all_ok &&= is($@, '');
110   $all_ok &&= like($output, qr/all tests successful/i);
111   
112   # This is the output of lib/Simple/Script.PL
113   $all_ok &&= ok(-e $mb->localize_file_path('lib/Simple/Script'));
114
115   unless ($all_ok) {
116     # We use diag() so Test::Harness doesn't get confused.
117     diag("vvvvvvvvvvvvvvvvvvvvv Simple/test.pl output vvvvvvvvvvvvvvvvvvvvv");
118     diag($output);
119     diag("^^^^^^^^^^^^^^^^^^^^^ Simple/test.pl output ^^^^^^^^^^^^^^^^^^^^^");
120   }
121 }
122
123 SKIP: {
124   skip( 'YAML_support feature is not enabled', 7 ) unless $have_yaml;
125
126   my $output = eval {
127     stdout_of( sub { $mb->dispatch('disttest') } )
128   };
129   is $@, '';
130   
131   # After a test, the distdir should contain a blib/ directory
132   ok -e File::Spec->catdir('Simple-0.01', 'blib');
133   
134   eval {$mb->dispatch('distdir')};
135   is $@, '';
136   
137   # The 'distdir' should contain a lib/ directory
138   ok -e File::Spec->catdir('Simple-0.01', 'lib');
139   
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');
143
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;
149
150   SKIP: {
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');
154
155     $mb->add_to_cleanup($mb->dist_dir . ".tar.gz");
156     eval {$mb->dispatch('dist')};
157     is $@, '';
158   }
159
160 }
161
162 {
163   # Make sure the 'script' file was recognized as a script.
164   my $scripts = $mb->script_files;
165   ok $scripts->{script};
166   
167   # Check that a shebang line is rewritten
168   my $blib_script = File::Spec->catfile( qw( blib script script ) );
169   ok -e $blib_script;
170   
171  SKIP: {
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";
176   }
177 }
178
179 {
180   # Check PPD
181   $mb->dispatch('ppd', args => {codebase => '/path/to/codebase'});
182
183   my $ppd = slurp('Simple.ppd');
184
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
187   # best we can do.
188   is $ppd, <<'EOF';
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>
193     <IMPLEMENTATION>
194         <DEPENDENCY NAME="File-Spec" VERSION="0,0,0,0" />
195         <CODEBASE HREF="/path/to/codebase" />
196     </IMPLEMENTATION>
197 </SOFTPKG>
198 EOF
199 }
200
201
202 eval {$mb->dispatch('realclean')};
203 is $@, '';
204
205 ok ! -e $mb->build_script;
206 ok ! -e $mb->config_dir;
207 ok ! -e $mb->dist_dir;
208
209 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
210 $dist->remove;
211
212 SKIP: {
213   skip( 'Windows-only test', 4 ) unless $^O =~ /^MSWin/;
214
215   my $script_data = <<'---';
216 @echo off
217 echo Hello, World!
218 ---
219
220   $dist = DistGen->new( dir => $tmp );
221   $dist->change_build_pl({
222                           module_name => 'Simple',
223                           scripts     => [ 'bin/script.bat' ],
224                           license     => 'perl',
225                          });
226
227   $dist->add_file( 'bin/script.bat', $script_data );
228
229   $dist->regen;
230   chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
231
232   $mb = Module::Build->new_from_context;
233   ok $mb;
234
235   eval{ $mb->dispatch('build') };
236   is $@, '';
237
238   my $script_file = File::Spec->catfile( qw(blib script), 'script.bat' );
239   ok -f $script_file, "Native batch file copied to 'scripts'";
240
241   my $out = slurp( $script_file );
242   is $out, $script_data, '  unmodified by pl2bat';
243
244   chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
245   $dist->remove;
246 }
247
248 # cleanup
249 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
250 $dist->remove;
251
252 use File::Path;
253 rmtree( $tmp );