Commit | Line | Data |
bb4e9162 |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib'; |
f943a5bf |
5 | use MBTest tests => 32; |
bb4e9162 |
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 = File::Spec->catdir( $cwd, 't', '_tmp' ); |
16 | |
17 | use DistGen; |
18 | my $dist = DistGen->new( dir => $tmp ); |
19 | $dist->remove_file( 't/basic.t' ); |
20 | $dist->change_file( 'Build.PL', <<'---' ); |
21 | use Module::Build; |
22 | |
23 | my $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 |
33 | print "Hello, World!\n"; |
34 | --- |
35 | $dist->add_file( 'test.pl', <<'---' ); |
36 | #!/usr/bin/perl |
37 | |
38 | use Test; |
39 | plan tests => 2; |
40 | |
41 | ok 1; |
42 | |
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'; |
46 | |
47 | print "# Cwd: ", Module::Build->cwd, "\n"; |
48 | print "# \@INC: (@INC)\n"; |
49 | print "Done.\n"; # t/compat.t looks for this |
50 | --- |
51 | $dist->add_file( 'lib/Simple/Script.PL', <<'---' ); |
52 | #!perl -w |
53 | |
54 | my $filename = shift; |
55 | open FH, "> $filename" or die "Can't create $filename: $!"; |
56 | print FH "Contents: $filename\n"; |
57 | close FH; |
58 | --- |
59 | $dist->regen; |
60 | |
61 | chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!"; |
62 | |
63 | ######################### |
64 | |
65 | use Module::Build; |
66 | ok(1); |
67 | |
68 | SKIP: { |
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 | |
75 | my $mb = Module::Build->new_from_context; |
76 | ok $mb; |
77 | is $mb->license, 'perl'; |
78 | |
79 | # Make sure cleanup files added before create_build_script() get respected |
80 | $mb->add_to_cleanup('before_script'); |
81 | |
82 | eval {$mb->create_build_script}; |
83 | is $@, ''; |
84 | ok -e $mb->build_script; |
85 | |
d1bd4ef0 |
86 | my $dist_dir = 'Simple-0.01'; |
87 | |
88 | # VMS may or may not need to modify the name, vmsify will do this if |
89 | # the name looks like a UNIX directory. |
90 | if ($^O eq 'VMS') { |
91 | my @dist_dirs = File::Spec->splitdir(VMS::Filespec::vmsify($dist_dir.'/')); |
92 | $dist_dir = $dist_dirs[0]; |
93 | } |
94 | |
95 | is $mb->dist_dir, $dist_dir; |
bb4e9162 |
96 | |
97 | # The 'cleanup' file doesn't exist yet |
98 | ok grep {$_ eq 'before_script'} $mb->cleanup; |
99 | |
100 | $mb->add_to_cleanup('save_out'); |
101 | |
102 | # The 'cleanup' file now exists |
103 | ok grep {$_ eq 'before_script'} $mb->cleanup; |
104 | ok grep {$_ eq 'save_out' } $mb->cleanup; |
105 | |
106 | { |
107 | # Make sure verbose=>1 works |
108 | my $all_ok = 1; |
109 | my $output = eval { |
110 | stdout_of( sub { $mb->dispatch('test', verbose => 1) } ) |
111 | }; |
112 | $all_ok &&= is($@, ''); |
113 | $all_ok &&= like($output, qr/all tests successful/i); |
114 | |
115 | # This is the output of lib/Simple/Script.PL |
116 | $all_ok &&= ok(-e $mb->localize_file_path('lib/Simple/Script')); |
117 | |
118 | unless ($all_ok) { |
119 | # We use diag() so Test::Harness doesn't get confused. |
120 | diag("vvvvvvvvvvvvvvvvvvvvv Simple/test.pl output vvvvvvvvvvvvvvvvvvvvv"); |
121 | diag($output); |
122 | diag("^^^^^^^^^^^^^^^^^^^^^ Simple/test.pl output ^^^^^^^^^^^^^^^^^^^^^"); |
123 | } |
124 | } |
125 | |
126 | SKIP: { |
127 | skip( 'YAML_support feature is not enabled', 7 ) unless $have_yaml; |
128 | |
129 | my $output = eval { |
130 | stdout_of( sub { $mb->dispatch('disttest') } ) |
131 | }; |
132 | is $@, ''; |
133 | |
134 | # After a test, the distdir should contain a blib/ directory |
135 | ok -e File::Spec->catdir('Simple-0.01', 'blib'); |
136 | |
137 | eval {$mb->dispatch('distdir')}; |
138 | is $@, ''; |
139 | |
140 | # The 'distdir' should contain a lib/ directory |
141 | ok -e File::Spec->catdir('Simple-0.01', 'lib'); |
142 | |
143 | # The freshly run 'distdir' should never contain a blib/ directory, or |
144 | # else it could get into the tarball |
145 | ok ! -e File::Spec->catdir('Simple-0.01', 'blib'); |
146 | |
147 | # Make sure all of the above was done by the new version of Module::Build |
148 | my $fh = IO::File->new(File::Spec->catfile($dist->dirname, 'META.yml')); |
149 | my $contents = do {local $/; <$fh>}; |
150 | $contents =~ /Module::Build version ([0-9_.]+)/m; |
151 | cmp_ok $1, '==', $mb->VERSION, "Check version used to create META.yml: $1 == " . $mb->VERSION; |
152 | |
153 | SKIP: { |
154 | skip( "not sure if we can create a tarball on this platform", 1 ) |
155 | unless $mb->check_installed_status('Archive::Tar', 0) || |
156 | $mb->isa('Module::Build::Platform::Unix'); |
157 | |
158 | $mb->add_to_cleanup($mb->dist_dir . ".tar.gz"); |
159 | eval {$mb->dispatch('dist')}; |
160 | is $@, ''; |
161 | } |
162 | |
163 | } |
164 | |
165 | { |
166 | # Make sure the 'script' file was recognized as a script. |
167 | my $scripts = $mb->script_files; |
168 | ok $scripts->{script}; |
169 | |
170 | # Check that a shebang line is rewritten |
d1bd4ef0 |
171 | my $blib_script = File::Spec->catfile( qw( blib script script ) ); |
bb4e9162 |
172 | ok -e $blib_script; |
173 | |
d1bd4ef0 |
174 | SKIP: { |
175 | skip("We do not rewrite shebang on VMS", 1) if $^O eq 'VMS'; |
bb4e9162 |
176 | my $fh = IO::File->new($blib_script); |
177 | my $first_line = <$fh>; |
178 | isnt $first_line, "#!perl -w\n", "should rewrite the shebang line"; |
d1bd4ef0 |
179 | } |
bb4e9162 |
180 | } |
181 | |
182 | { |
183 | # Check PPD |
184 | $mb->dispatch('ppd', args => {codebase => '/path/to/codebase'}); |
185 | |
186 | my $ppd = slurp('Simple.ppd'); |
187 | |
188 | # This test is quite a hack since with XML you don't really want to |
189 | # do a strict string comparison, but absent an XML parser it's the |
190 | # best we can do. |
191 | is $ppd, <<'EOF'; |
192 | <SOFTPKG NAME="Simple" VERSION="0,01,0,0"> |
193 | <TITLE>Simple</TITLE> |
194 | <ABSTRACT>Perl extension for blah blah blah</ABSTRACT> |
195 | <AUTHOR>A. U. Thor, a.u.thor@a.galaxy.far.far.away</AUTHOR> |
196 | <IMPLEMENTATION> |
197 | <DEPENDENCY NAME="File-Spec" VERSION="0,0,0,0" /> |
198 | <CODEBASE HREF="/path/to/codebase" /> |
199 | </IMPLEMENTATION> |
200 | </SOFTPKG> |
201 | EOF |
202 | } |
203 | |
204 | |
205 | eval {$mb->dispatch('realclean')}; |
206 | is $@, ''; |
207 | |
208 | ok ! -e $mb->build_script; |
209 | ok ! -e $mb->config_dir; |
210 | ok ! -e $mb->dist_dir; |
211 | |
f943a5bf |
212 | chdir( $cwd ) or die "Can''t chdir to '$cwd': $!"; |
213 | $dist->remove; |
214 | |
215 | SKIP: { |
b3dfda33 |
216 | skip( 'Windows-only test', 4 ) unless $^O =~ /^MSWin/; |
f943a5bf |
217 | |
218 | my $script_data = <<'---'; |
219 | @echo off |
220 | echo Hello, World! |
221 | --- |
222 | |
223 | $dist = DistGen->new( dir => $tmp ); |
224 | $dist->change_file( 'Build.PL', <<'---' ); |
225 | use Module::Build; |
226 | my $build = new Module::Build( |
227 | module_name => 'Simple', |
228 | scripts => [ 'bin/script.bat' ], |
229 | license => 'perl', |
230 | ); |
231 | $build->create_build_script; |
232 | --- |
233 | $dist->add_file( 'bin/script.bat', $script_data ); |
234 | |
235 | $dist->regen; |
236 | chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!"; |
237 | |
238 | $mb = Module::Build->new_from_context; |
239 | ok $mb; |
240 | |
241 | eval{ $mb->dispatch('build') }; |
242 | is $@, ''; |
243 | |
244 | my $script_file = File::Spec->catfile( qw(blib script), 'script.bat' ); |
245 | ok -f $script_file, "Native batch file copied to 'scripts'"; |
246 | |
247 | my $out = slurp( $script_file ); |
248 | is $out, $script_data, ' unmodified by pl2bat'; |
249 | |
250 | chdir( $cwd ) or die "Can''t chdir to '$cwd': $!"; |
251 | $dist->remove; |
252 | } |
bb4e9162 |
253 | |
254 | # cleanup |
255 | chdir( $cwd ) or die "Can''t chdir to '$cwd': $!"; |
256 | $dist->remove; |
257 | |
258 | use File::Path; |
259 | rmtree( $tmp ); |