Commit | Line | Data |
bb4e9162 |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
10b84a45 |
4 | use lib 't/lib'; |
613f422f |
5 | use MBTest tests => 30; |
bb4e9162 |
6 | |
613f422f |
7 | blib_load('Module::Build'); |
8 | blib_load('Module::Build::ConfigData'); |
bb4e9162 |
9 | my $have_yaml = Module::Build::ConfigData->feature('YAML_support'); |
10 | |
11 | ######################### |
12 | |
7a827510 |
13 | my $tmp = MBTest->tmpdir; |
bb4e9162 |
14 | |
15 | use DistGen; |
16 | my $dist = DistGen->new( dir => $tmp ); |
7a827510 |
17 | $dist->change_build_pl |
18 | ({ |
bb4e9162 |
19 | module_name => 'Simple', |
20 | scripts => [ 'script' ], |
21 | license => 'perl', |
22 | requires => { 'File::Spec' => 0 }, |
7a827510 |
23 | }); |
24 | |
613f422f |
25 | $dist->add_file( 'MANIFEST.SKIP', <<'---' ); |
26 | ^MYMETA.yml$ |
27 | --- |
bb4e9162 |
28 | $dist->add_file( 'script', <<'---' ); |
29 | #!perl -w |
30 | print "Hello, World!\n"; |
31 | --- |
bb4e9162 |
32 | $dist->add_file( 'lib/Simple/Script.PL', <<'---' ); |
33 | #!perl -w |
34 | |
35 | my $filename = shift; |
36 | open FH, "> $filename" or die "Can't create $filename: $!"; |
37 | print FH "Contents: $filename\n"; |
38 | close FH; |
39 | --- |
40 | $dist->regen; |
41 | |
738349a8 |
42 | $dist->chdir_in; |
bb4e9162 |
43 | |
bb4e9162 |
44 | |
45 | ######################### |
46 | |
47 | my $mb = Module::Build->new_from_context; |
48 | ok $mb; |
49 | is $mb->license, 'perl'; |
50 | |
51 | # Make sure cleanup files added before create_build_script() get respected |
52 | $mb->add_to_cleanup('before_script'); |
53 | |
54 | eval {$mb->create_build_script}; |
55 | is $@, ''; |
56 | ok -e $mb->build_script; |
57 | |
d1bd4ef0 |
58 | my $dist_dir = 'Simple-0.01'; |
59 | |
94410036 |
60 | # VMS in traditional mode needs the $dist_dir name to not have a '.' in it |
61 | # as this is a directory delimiter. In extended character set mode the dot |
62 | # is permitted for Unix format file specifications. |
d1bd4ef0 |
63 | if ($^O eq 'VMS') { |
94410036 |
64 | my $Is_VMS_noefs = 1; |
65 | my $vms_efs = 0; |
66 | if (eval 'require VMS::Feature') { |
67 | $vms_efs = VMS::Feature::current("efs_charset"); |
68 | } else { |
69 | my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || ''; |
70 | $vms_efs = $efs_charset =~ /^[ET1]/i; |
71 | } |
72 | $Is_VMS_noefs = 0 if $vms_efs; |
73 | if ($Is_VMS_noefs) { |
74 | $dist_dir = 'Simple-0_01'; |
75 | } |
d1bd4ef0 |
76 | } |
77 | |
78 | is $mb->dist_dir, $dist_dir; |
bb4e9162 |
79 | |
80 | # The 'cleanup' file doesn't exist yet |
81 | ok grep {$_ eq 'before_script'} $mb->cleanup; |
82 | |
83 | $mb->add_to_cleanup('save_out'); |
84 | |
85 | # The 'cleanup' file now exists |
86 | ok grep {$_ eq 'before_script'} $mb->cleanup; |
87 | ok grep {$_ eq 'save_out' } $mb->cleanup; |
88 | |
89 | { |
90 | # Make sure verbose=>1 works |
91 | my $all_ok = 1; |
92 | my $output = eval { |
93 | stdout_of( sub { $mb->dispatch('test', verbose => 1) } ) |
94 | }; |
95 | $all_ok &&= is($@, ''); |
96 | $all_ok &&= like($output, qr/all tests successful/i); |
97 | |
98 | # This is the output of lib/Simple/Script.PL |
99 | $all_ok &&= ok(-e $mb->localize_file_path('lib/Simple/Script')); |
100 | |
101 | unless ($all_ok) { |
102 | # We use diag() so Test::Harness doesn't get confused. |
cdbde1c3 |
103 | diag("vvvvvvvvvvvvvvvvvvvvv Simple/t/basic.t output vvvvvvvvvvvvvvvvvvvvv"); |
bb4e9162 |
104 | diag($output); |
cdbde1c3 |
105 | diag("^^^^^^^^^^^^^^^^^^^^^ Simple/t/basic.t output ^^^^^^^^^^^^^^^^^^^^^"); |
bb4e9162 |
106 | } |
107 | } |
108 | |
109 | SKIP: { |
110 | skip( 'YAML_support feature is not enabled', 7 ) unless $have_yaml; |
111 | |
112 | my $output = eval { |
113 | stdout_of( sub { $mb->dispatch('disttest') } ) |
114 | }; |
115 | is $@, ''; |
116 | |
117 | # After a test, the distdir should contain a blib/ directory |
118 | ok -e File::Spec->catdir('Simple-0.01', 'blib'); |
119 | |
120 | eval {$mb->dispatch('distdir')}; |
121 | is $@, ''; |
122 | |
123 | # The 'distdir' should contain a lib/ directory |
124 | ok -e File::Spec->catdir('Simple-0.01', 'lib'); |
125 | |
126 | # The freshly run 'distdir' should never contain a blib/ directory, or |
127 | # else it could get into the tarball |
128 | ok ! -e File::Spec->catdir('Simple-0.01', 'blib'); |
129 | |
130 | # Make sure all of the above was done by the new version of Module::Build |
131 | my $fh = IO::File->new(File::Spec->catfile($dist->dirname, 'META.yml')); |
132 | my $contents = do {local $/; <$fh>}; |
133 | $contents =~ /Module::Build version ([0-9_.]+)/m; |
134 | cmp_ok $1, '==', $mb->VERSION, "Check version used to create META.yml: $1 == " . $mb->VERSION; |
135 | |
136 | SKIP: { |
cdbde1c3 |
137 | skip( "Archive::Tar 1.08+ not installed", 1 ) |
138 | unless eval { require Archive::Tar && Archive::Tar->VERSION(1.08); 1 }; |
bb4e9162 |
139 | $mb->add_to_cleanup($mb->dist_dir . ".tar.gz"); |
140 | eval {$mb->dispatch('dist')}; |
141 | is $@, ''; |
142 | } |
143 | |
144 | } |
145 | |
146 | { |
147 | # Make sure the 'script' file was recognized as a script. |
148 | my $scripts = $mb->script_files; |
149 | ok $scripts->{script}; |
150 | |
151 | # Check that a shebang line is rewritten |
d1bd4ef0 |
152 | my $blib_script = File::Spec->catfile( qw( blib script script ) ); |
bb4e9162 |
153 | ok -e $blib_script; |
154 | |
7a827510 |
155 | SKIP: { |
d1bd4ef0 |
156 | skip("We do not rewrite shebang on VMS", 1) if $^O eq 'VMS'; |
7a827510 |
157 | my $fh = IO::File->new($blib_script); |
158 | my $first_line = <$fh>; |
159 | isnt $first_line, "#!perl -w\n", "should rewrite the shebang line"; |
d1bd4ef0 |
160 | } |
bb4e9162 |
161 | } |
162 | |
163 | { |
164 | # Check PPD |
165 | $mb->dispatch('ppd', args => {codebase => '/path/to/codebase'}); |
166 | |
167 | my $ppd = slurp('Simple.ppd'); |
168 | |
169 | # This test is quite a hack since with XML you don't really want to |
170 | # do a strict string comparison, but absent an XML parser it's the |
171 | # best we can do. |
172 | is $ppd, <<'EOF'; |
613f422f |
173 | <SOFTPKG NAME="Simple" VERSION="0.01"> |
bb4e9162 |
174 | <ABSTRACT>Perl extension for blah blah blah</ABSTRACT> |
175 | <AUTHOR>A. U. Thor, a.u.thor@a.galaxy.far.far.away</AUTHOR> |
176 | <IMPLEMENTATION> |
613f422f |
177 | <REQUIRE NAME="File::Spec" VERSION="0" /> |
bb4e9162 |
178 | <CODEBASE HREF="/path/to/codebase" /> |
179 | </IMPLEMENTATION> |
180 | </SOFTPKG> |
181 | EOF |
182 | } |
183 | |
184 | |
185 | eval {$mb->dispatch('realclean')}; |
186 | is $@, ''; |
187 | |
188 | ok ! -e $mb->build_script; |
189 | ok ! -e $mb->config_dir; |
190 | ok ! -e $mb->dist_dir; |
191 | |
f943a5bf |
192 | SKIP: { |
b3dfda33 |
193 | skip( 'Windows-only test', 4 ) unless $^O =~ /^MSWin/; |
f943a5bf |
194 | |
195 | my $script_data = <<'---'; |
196 | @echo off |
197 | echo Hello, World! |
198 | --- |
199 | |
200 | $dist = DistGen->new( dir => $tmp ); |
7a827510 |
201 | $dist->change_build_pl({ |
202 | module_name => 'Simple', |
203 | scripts => [ 'bin/script.bat' ], |
204 | license => 'perl', |
205 | }); |
206 | |
f943a5bf |
207 | $dist->add_file( 'bin/script.bat', $script_data ); |
208 | |
209 | $dist->regen; |
738349a8 |
210 | $dist->chdir_in; |
f943a5bf |
211 | |
212 | $mb = Module::Build->new_from_context; |
213 | ok $mb; |
214 | |
215 | eval{ $mb->dispatch('build') }; |
216 | is $@, ''; |
217 | |
218 | my $script_file = File::Spec->catfile( qw(blib script), 'script.bat' ); |
219 | ok -f $script_file, "Native batch file copied to 'scripts'"; |
220 | |
221 | my $out = slurp( $script_file ); |
222 | is $out, $script_data, ' unmodified by pl2bat'; |
223 | |
f943a5bf |
224 | } |
bb4e9162 |
225 | |