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; |
7a827510 |
9 | my $tmp = MBTest->tmpdir; |
bb4e9162 |
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; |
7a827510 |
125 | $dist->change_build_pl |
126 | ({ |
127 | module_name => @{[$dist->name]}, |
128 | license => 'perl', |
129 | get_options => { foo => {}, |
130 | bar => { type => '+' }, |
131 | bat => { type => '=s' }, |
132 | dee => { type => '=s', |
133 | default => 'goo' |
134 | }, |
135 | } |
136 | }); |
bb4e9162 |
137 | |
138 | $dist->regen; |
139 | 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'])}; |
140 | is $@, ''; |
141 | |
142 | my $mb = Module::Build->resume; |
77e96e88 |
143 | ok $mb->valid_property('config'); |
144 | |
bb4e9162 |
145 | is $mb->config('cc'), $Config{cc}; |
146 | is $mb->config('foocakes'), 'barcakes'; |
147 | |
148 | # Test args(). |
149 | is $mb->args('foo'), 1; |
150 | is $mb->args('bar'), 2, 'bar'; |
151 | is $mb->args('bat'), 'hello', 'bat'; |
152 | is $mb->args('gee'), 'whiz'; |
153 | is $mb->args('any'), 'hey'; |
154 | is $mb->args('dee'), 'goo'; |
155 | is $mb->destdir, 'yo'; |
77e96e88 |
156 | my %runtime = $mb->runtime_params; |
157 | is_deeply \%runtime, |
158 | { |
159 | verbose => 1, |
160 | destdir => 'yo', |
161 | use_rcfile => 0, |
162 | config => { foocakes => 'barcakes' }, |
163 | }; |
bb4e9162 |
164 | |
165 | ok my $argsref = $mb->args; |
166 | is $argsref->{foo}, 1; |
167 | $argsref->{doo} = 'hee'; |
168 | is $mb->args('doo'), 'hee'; |
169 | ok my %args = $mb->args; |
170 | is $args{foo}, 1; |
171 | |
172 | # revert test distribution to pristine state because we modified a file |
173 | chdir( $cwd ) or die "Can''t chdir to '$cwd': $!"; |
174 | $dist->remove; |
175 | $dist = DistGen->new( dir => $tmp ); |
176 | $dist->regen; |
177 | chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!"; |
178 | } |
179 | |
180 | # Test author stuff |
181 | { |
182 | my $mb = Module::Build->new( |
183 | module_name => $dist->name, |
184 | dist_author => 'Foo Meister <foo@example.com>', |
185 | build_class => 'My::Big::Fat::Builder', |
186 | ); |
187 | ok $mb; |
188 | ok ref($mb->dist_author), 'dist_author converted to array if simple string'; |
189 | is $mb->dist_author->[0], 'Foo Meister <foo@example.com>'; |
190 | is $mb->build_class, 'My::Big::Fat::Builder'; |
191 | } |
192 | |
193 | # Test conversion of shell strings |
194 | { |
195 | my $mb = Module::Build->new( |
196 | module_name => $dist->name, |
197 | dist_author => 'Foo Meister <foo@example.com>', |
198 | extra_compiler_flags => '-I/foo -I/bar', |
199 | extra_linker_flags => '-L/foo -L/bar', |
200 | ); |
201 | ok $mb; |
202 | is_deeply $mb->extra_compiler_flags, ['-I/foo', '-I/bar'], "Should split shell string into list"; |
203 | is_deeply $mb->extra_linker_flags, ['-L/foo', '-L/bar'], "Should split shell string into list"; |
c1d8f74e |
204 | |
205 | # Try again with command-line args |
206 | eval {Module::Build->run_perl_script('Build.PL', [], ['--extra_compiler_flags', '-I/foo -I/bar', |
207 | '--extra_linker_flags', '-L/foo -L/bar'])}; |
208 | $mb = Module::Build->resume; |
209 | ok $mb; |
210 | is_deeply $mb->extra_compiler_flags, ['-I/foo', '-I/bar'], "Should split shell string into list"; |
211 | is_deeply $mb->extra_linker_flags, ['-L/foo', '-L/bar'], "Should split shell string into list"; |
bb4e9162 |
212 | } |
213 | |
214 | |
215 | # cleanup |
216 | chdir( $cwd ) or die "Can''t chdir to '$cwd': $!"; |
217 | $dist->remove; |
218 | |
219 | use File::Path; |
220 | rmtree( $tmp ); |