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'; |
c1d8f74e |
5 | use MBTest tests => 52; |
bb4e9162 |
6 | |
7 | use Cwd (); |
8 | my $cwd = Cwd::cwd; |
9 | my $tmp = File::Spec->catdir( $cwd, 't', '_tmp' ); |
10 | |
11 | use DistGen; |
12 | my $dist = DistGen->new( dir => $tmp ); |
13 | $dist->regen; |
14 | |
15 | chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!"; |
16 | |
17 | ######################### |
18 | |
19 | |
20 | use_ok 'Module::Build'; |
21 | |
22 | SKIP: { |
23 | skip "no blib in core", 1 if $ENV{PERL_CORE}; |
24 | like $INC{'Module/Build.pm'}, qr/\bblib\b/, "Make sure Module::Build was loaded from blib/"; |
25 | } |
26 | |
27 | |
28 | # Test object creation |
29 | { |
30 | my $mb = Module::Build->new( module_name => $dist->name ); |
31 | ok $mb; |
32 | is $mb->module_name, $dist->name; |
33 | is $mb->build_class, 'Module::Build'; |
34 | is $mb->dist_name, $dist->name; |
35 | |
36 | $mb = Module::Build->new( dist_name => $dist->name, dist_version => 7 ); |
37 | ok $mb; |
38 | ok ! $mb->module_name; # Make sure it's defined |
39 | is $mb->dist_name, $dist->name; |
40 | } |
41 | |
42 | # Make sure actions are defined, and known_actions works as class method |
43 | { |
44 | my %actions = map {$_, 1} Module::Build->known_actions; |
45 | ok $actions{clean}; |
46 | ok $actions{distdir}; |
47 | } |
48 | |
49 | # Test prerequisite checking |
50 | { |
51 | local @INC = (File::Spec->catdir( $dist->dirname, 'lib' ), @INC); |
52 | my $flagged = 0; |
53 | local $SIG{__WARN__} = sub { $flagged = 1 if $_[0] =~ /@{[$dist->name]}/}; |
54 | my $mb = Module::Build->new( |
55 | module_name => $dist->name, |
56 | requires => {$dist->name => 0}, |
57 | ); |
58 | ok ! $flagged; |
59 | ok ! $mb->prereq_failures; |
60 | $mb->dispatch('realclean'); |
61 | $dist->clean; |
62 | |
63 | $flagged = 0; |
64 | $mb = Module::Build->new( |
65 | module_name => $dist->name, |
66 | requires => {$dist->name => 3.14159265}, |
67 | ); |
68 | ok $flagged; |
69 | ok $mb->prereq_failures; |
70 | ok $mb->prereq_failures->{requires}{$dist->name}; |
71 | is $mb->prereq_failures->{requires}{$dist->name}{have}, 0.01; |
72 | is $mb->prereq_failures->{requires}{$dist->name}{need}, 3.14159265; |
73 | |
74 | $mb->dispatch('realclean'); |
75 | $dist->clean; |
76 | |
77 | # Make sure check_installed_status() works as a class method |
78 | my $info = Module::Build->check_installed_status('File::Spec', 0); |
79 | ok $info->{ok}; |
80 | is $info->{have}, $File::Spec::VERSION; |
81 | |
82 | # Make sure check_installed_status() works with an advanced spec |
83 | $info = Module::Build->check_installed_status('File::Spec', '> 0'); |
84 | ok $info->{ok}; |
85 | |
86 | # Use 2 lines for this, to avoid a "used only once" warning |
87 | local $Foo::Module::VERSION; |
88 | $Foo::Module::VERSION = '1.01_02'; |
89 | |
90 | $info = Module::Build->check_installed_status('Foo::Module', '1.01_02'); |
91 | ok $info->{ok} or diag($info->{message}); |
92 | } |
93 | |
94 | { |
95 | # Make sure the correct warning message is generated when an |
96 | # optional prereq isn't installed |
97 | my $flagged = 0; |
98 | local $SIG{__WARN__} = sub { $flagged = 1 if $_[0] =~ /ModuleBuildNonExistent is not installed/}; |
99 | |
100 | my $mb = Module::Build->new( |
101 | module_name => $dist->name, |
102 | recommends => {ModuleBuildNonExistent => 3}, |
103 | ); |
104 | ok $flagged; |
105 | $dist->clean; |
106 | } |
107 | |
108 | # Test verbosity |
109 | { |
110 | my $mb = Module::Build->new(module_name => $dist->name); |
111 | |
112 | $mb->add_to_cleanup('save_out'); |
113 | # Use uc() so we don't confuse the current test output |
114 | like uc(stdout_of( sub {$mb->dispatch('test', verbose => 1)} )), qr/^OK \d/m; |
115 | like uc(stdout_of( sub {$mb->dispatch('test', verbose => 0)} )), qr/\.\.OK/; |
116 | |
117 | $mb->dispatch('realclean'); |
118 | $dist->clean; |
119 | } |
120 | |
121 | # Make sure 'config' entries are respected on the command line, and that |
122 | # Getopt::Long specs work as expected. |
123 | { |
124 | use Config; |
125 | $dist->change_file( 'Build.PL', <<"---" ); |
126 | use Module::Build; |
127 | |
128 | my \$build = Module::Build->new( |
129 | module_name => @{[$dist->name]}, |
130 | license => 'perl', |
131 | get_options => { foo => {}, |
132 | bar => { type => '+' }, |
133 | bat => { type => '=s' }, |
134 | dee => { type => '=s', |
135 | default => 'goo' |
136 | }, |
137 | } |
138 | ); |
139 | |
140 | \$build->create_build_script; |
141 | --- |
142 | |
143 | $dist->regen; |
144 | eval {Module::Build->run_perl_script('Build.PL', [], ['--nouse-rcfile', '--config', "foocakes=barcakes", '--foo', '--bar', '--bar', '-bat=hello', 'gee=whiz', '--any', 'hey', '--destdir', 'yo', '--verbose', '1'])}; |
145 | is $@, ''; |
146 | |
147 | my $mb = Module::Build->resume; |
77e96e88 |
148 | ok $mb->valid_property('config'); |
149 | |
bb4e9162 |
150 | is $mb->config('cc'), $Config{cc}; |
151 | is $mb->config('foocakes'), 'barcakes'; |
152 | |
153 | # Test args(). |
154 | is $mb->args('foo'), 1; |
155 | is $mb->args('bar'), 2, 'bar'; |
156 | is $mb->args('bat'), 'hello', 'bat'; |
157 | is $mb->args('gee'), 'whiz'; |
158 | is $mb->args('any'), 'hey'; |
159 | is $mb->args('dee'), 'goo'; |
160 | is $mb->destdir, 'yo'; |
77e96e88 |
161 | my %runtime = $mb->runtime_params; |
162 | is_deeply \%runtime, |
163 | { |
164 | verbose => 1, |
165 | destdir => 'yo', |
166 | use_rcfile => 0, |
167 | config => { foocakes => 'barcakes' }, |
168 | }; |
bb4e9162 |
169 | |
170 | ok my $argsref = $mb->args; |
171 | is $argsref->{foo}, 1; |
172 | $argsref->{doo} = 'hee'; |
173 | is $mb->args('doo'), 'hee'; |
174 | ok my %args = $mb->args; |
175 | is $args{foo}, 1; |
176 | |
177 | # revert test distribution to pristine state because we modified a file |
178 | chdir( $cwd ) or die "Can''t chdir to '$cwd': $!"; |
179 | $dist->remove; |
180 | $dist = DistGen->new( dir => $tmp ); |
181 | $dist->regen; |
182 | chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!"; |
183 | } |
184 | |
185 | # Test author stuff |
186 | { |
187 | my $mb = Module::Build->new( |
188 | module_name => $dist->name, |
189 | dist_author => 'Foo Meister <foo@example.com>', |
190 | build_class => 'My::Big::Fat::Builder', |
191 | ); |
192 | ok $mb; |
193 | ok ref($mb->dist_author), 'dist_author converted to array if simple string'; |
194 | is $mb->dist_author->[0], 'Foo Meister <foo@example.com>'; |
195 | is $mb->build_class, 'My::Big::Fat::Builder'; |
196 | } |
197 | |
198 | # Test conversion of shell strings |
199 | { |
200 | my $mb = Module::Build->new( |
201 | module_name => $dist->name, |
202 | dist_author => 'Foo Meister <foo@example.com>', |
203 | extra_compiler_flags => '-I/foo -I/bar', |
204 | extra_linker_flags => '-L/foo -L/bar', |
205 | ); |
206 | ok $mb; |
207 | is_deeply $mb->extra_compiler_flags, ['-I/foo', '-I/bar'], "Should split shell string into list"; |
208 | is_deeply $mb->extra_linker_flags, ['-L/foo', '-L/bar'], "Should split shell string into list"; |
c1d8f74e |
209 | |
210 | # Try again with command-line args |
211 | eval {Module::Build->run_perl_script('Build.PL', [], ['--extra_compiler_flags', '-I/foo -I/bar', |
212 | '--extra_linker_flags', '-L/foo -L/bar'])}; |
213 | $mb = Module::Build->resume; |
214 | ok $mb; |
215 | is_deeply $mb->extra_compiler_flags, ['-I/foo', '-I/bar'], "Should split shell string into list"; |
216 | is_deeply $mb->extra_linker_flags, ['-L/foo', '-L/bar'], "Should split shell string into list"; |
bb4e9162 |
217 | } |
218 | |
219 | |
220 | # cleanup |
221 | chdir( $cwd ) or die "Can''t chdir to '$cwd': $!"; |
222 | $dist->remove; |
223 | |
224 | use File::Path; |
225 | rmtree( $tmp ); |