2 # Copyright (C) 2007, Parrot Foundation.
8 use Test::More tests => 74;
10 use lib qw( lib t/configure/testlib );
11 use_ok('config::inter::libparrot');
12 use Parrot::Configure::Options qw( process_options );
13 use Parrot::Configure::Step::Test;
14 use Parrot::Configure::Test qw(
15 test_step_constructor_and_description
17 use Tie::Filehandle::Preempt::Stdin;
19 ########## no ask; no other options ##########
21 my ($args, $step_list_ref) = process_options(
28 my $conf = Parrot::Configure::Step::Test->new;
29 $conf->include_config_results( $args );
31 my $pkg = q{inter::libparrot};
33 $conf->add_steps($pkg);
35 my $serialized = $conf->pcfreeze();
37 $conf->options->set( %{$args} );
38 my $step = test_step_constructor_and_description($conf);
40 open STDOUT, '>', "/dev/null" or croak "Unable to open to myout";
41 my $ret = $step->runstep($conf);
42 close STDOUT or croak "Unable to close after myout";
43 ok( $ret, "runstep() returned true value" );
46 $conf->replenish($serialized);
48 ########## no ask; parrot_is_shared ##########
50 ($args, $step_list_ref) = process_options(
52 argv => [ q{--parrot_is_shared} ],
56 $conf->options->set( %{$args} );
57 $step = test_step_constructor_and_description($conf);
59 open STDOUT, '>', "/dev/null" or croak "Unable to open to myout";
60 my $ret = $step->runstep($conf);
61 close STDOUT or croak "Unable to close after myout";
62 ok( $ret, "runstep() returned true value" );
65 $conf->replenish($serialized);
67 ########## no ask; parrot_is_shared; has_dynamic_linking ##########
69 ($args, $step_list_ref) = process_options(
71 argv => [ q{--parrot_is_shared} ],
75 $conf->options->set( %{$args} );
76 $step = test_step_constructor_and_description($conf);
77 my $has_dynamic_linking_orig = $conf->data->get('has_dynamic_linking');
78 $conf->data->set('has_dynamic_linking' => 1);
81 open STDOUT, '>', "/dev/null" or croak "Unable to open to myout";
82 my $ret = $step->runstep($conf);
83 close STDOUT or croak "Unable to close after myout";
84 ok( $ret, "runstep() returned true value" );
86 is($step->result(), 'yes', "Expected result was set");
87 # re-set for next test
88 $step->set_result(q{});
89 $conf->data->set('has_dynamic_linking' => $has_dynamic_linking_orig);
91 $conf->replenish($serialized);
93 ########## no ask; parrot_is_shared; has_dynamic_linking; rpath ##########
95 ($args, $step_list_ref) = process_options(
97 argv => [ q{--parrot_is_shared} ],
101 $conf->options->set( %{$args} );
102 $step = test_step_constructor_and_description($conf);
103 $conf->data->set('has_dynamic_linking' => 1);
104 my $rpath_orig = $conf->data->get('rpath');
105 $conf->data->set('rpath' => q{-L});
107 open STDOUT, '>', "/dev/null" or croak "Unable to open to myout";
108 my $ret = $step->runstep($conf);
109 close STDOUT or croak "Unable to close after myout";
110 ok( $ret, "runstep() returned true value" );
112 is($step->result(), 'yes', "Expected result was set");
113 # re-set for next test
114 $step->set_result(q{});
115 $conf->data->set('has_dynamic_linking' => $has_dynamic_linking_orig);
116 $conf->data->set('rpath' => $rpath_orig);
118 $conf->replenish($serialized);
120 ########## no ask; parrot_is_shared; has_dynamic_linking; rpath ##########
122 ($args, $step_list_ref) = process_options(
124 argv => [ q{--parrot_is_shared} ],
125 mode => q{configure},
128 $conf->options->set( %{$args} );
129 $step = test_step_constructor_and_description($conf);
130 $conf->data->set('has_dynamic_linking' => 1);
131 $rpath_orig = $conf->data->get('rpath');
132 $conf->data->set('rpath' => q{-L});
134 open STDOUT, '>', "/dev/null" or croak "Unable to open to myout";
135 my $ret = $step->runstep($conf);
136 close STDOUT or croak "Unable to close after myout";
137 ok( $ret, "runstep() returned true value" );
139 is($step->result(), 'yes', "Expected result was set");
140 # re-set for next test
141 $step->set_result(q{});
142 $conf->data->set('has_dynamic_linking' => $has_dynamic_linking_orig);
143 $conf->data->set('rpath' => $rpath_orig);
145 $conf->replenish($serialized);
147 ########## no ask; libparrot_ldflags ##########
149 ($args, $step_list_ref) = process_options(
152 mode => q{configure},
155 $conf->options->set( %{$args} );
156 $step = test_step_constructor_and_description($conf);
157 my $libparrot_ldflags_orig = $conf->data->get('libparrot_ldflags');
158 $conf->data->set('libparrot_ldflags' => 'libparrot.lib');
160 open STDOUT, '>', "/dev/null" or croak "Unable to open to myout";
161 my $ret = $step->runstep($conf);
162 close STDOUT or croak "Unable to close after myout";
163 ok( $ret, "runstep() returned true value" );
165 $conf->data->set('libparrot_ldflags' => $libparrot_ldflags_orig);
167 $conf->replenish($serialized);
169 ########## ask; no has_dynamic_linking ##########
171 ($args, $step_list_ref) = process_options(
173 argv => [ q{--ask} ],
174 mode => q{configure},
177 $conf->options->set( %{$args} );
178 $step = test_step_constructor_and_description($conf);
179 $conf->data->set('has_dynamic_linking' => 0);
181 open STDOUT, '>', "/dev/null" or croak "Unable to open to myout";
182 my $ret = $step->runstep($conf);
183 close STDOUT or croak "Unable to close after myout";
184 ok( $ret, "runstep() returned true value" );
186 is($step->result(), 'no', "Expected result was set");
187 # re-set for next test
188 $step->set_result(q{});
189 $conf->data->set('has_dynamic_linking' => $has_dynamic_linking_orig);
191 $conf->replenish($serialized);
193 ########## ask; parrot_is_shared; has_dynamic_linking ##########
195 ($args, $step_list_ref) = process_options(
197 argv => [ q{--ask}, q{--parrot_is_shared} ],
198 mode => q{configure},
201 $conf->options->set( %{$args} );
202 $step = test_step_constructor_and_description($conf);
203 $conf->data->set('has_dynamic_linking' => 1);
205 my ( @prompts, $prompt, $object );
208 push @prompts, $prompt;
210 $object = tie *STDIN, 'Tie::Filehandle::Preempt::Stdin', @prompts;
211 can_ok( 'Tie::Filehandle::Preempt::Stdin', ('READLINE') );
212 isa_ok( $object, 'Tie::Filehandle::Preempt::Stdin' );
215 open STDOUT, '>', "/dev/null" or croak "Unable to open to myout";
216 my $ret = $step->runstep($conf);
217 close STDOUT or croak "Unable to close after myout";
218 ok( $ret, "runstep() returned true value" );
223 is($step->result(), 'yes', "Expected result was set");
224 # re-set for next test
225 $step->set_result(q{});
226 $conf->data->set('has_dynamic_linking' => $has_dynamic_linking_orig);
229 $conf->replenish($serialized);
231 ########## ask; has_dynamic_linking ##########
233 ($args, $step_list_ref) = process_options(
235 argv => [ q{--ask} ],
236 mode => q{configure},
239 $conf->options->set( %{$args} );
240 $step = test_step_constructor_and_description($conf);
241 $conf->data->set('has_dynamic_linking' => 1);
243 push @prompts, $prompt;
244 $object = tie *STDIN, 'Tie::Filehandle::Preempt::Stdin', @prompts;
245 can_ok( 'Tie::Filehandle::Preempt::Stdin', ('READLINE') );
246 isa_ok( $object, 'Tie::Filehandle::Preempt::Stdin' );
248 open STDOUT, '>', "/dev/null" or croak "Unable to open to myout";
249 my $ret = $step->runstep($conf);
250 close STDOUT or croak "Unable to close after myout";
251 ok( $ret, "runstep() returned true value" );
255 is($step->result(), 'no', "Expected result was set");
256 # re-set for next test
257 $step->set_result(q{});
258 $conf->data->set('has_dynamic_linking' => $has_dynamic_linking_orig);
261 ##### get_libs() #####
265 local $^O = 'foobar';
266 %seen = map { $_ => 1 } inter::libparrot::get_libs();
267 is( scalar keys %seen, 1, "Got expected number of libs: generic" );
268 ok( $seen{'libparrot.so'}, "Got expected lib" );
272 local $^O = 'MSWin32';
273 %seen = map { $_ => 1 } inter::libparrot::get_libs();
274 is( scalar keys %seen, 3, "Got expected number of libs: Win32" );
278 'libparrot.dll' => 1,
279 'libparrot.lib' => 1,
280 'libparrot.dll.a' => 1,
287 local $^O = 'cygwin';
288 %seen = map { $_ => 1 } inter::libparrot::get_libs();
289 is( scalar keys %seen, 1, "Got expected number of libs: cygwin" );
293 'libparrot.dll.a' => 1,
300 local $^O = 'darwin';
301 %seen = map { $_ => 1 } inter::libparrot::get_libs();
302 is( scalar keys %seen, 2, "Got expected number of libs: darwin" );
306 'libparrot.dylib' => 1,
313 ##### get_libpaths() #####
315 %seen = map { $_ => 1 } inter::libparrot::get_libpaths($conf);
316 ok( $seen{'/usr/local/lib'}, "Got expected lib: generic" );
317 ok( $seen{'/usr/lib'}, "Got expected lib: generic" );
320 local $^O = 'MSWin32';
321 local $ENV{PATH} = 'alpha;beta';
322 %seen = map { $_ => 1 } inter::libparrot::get_libpaths($conf);
323 ok( $seen{'/usr/local/lib'}, "Got expected lib: MSWin32" );
324 ok( $seen{'/usr/lib'}, "Got expected lib: MSWin32" );
325 ok( $seen{'alpha'}, "Got expected lib: MSWin32" );
326 ok( $seen{'beta'}, "Got expected lib: MSWin32" );
330 local $ENV{LD_LIBRARY_PATH} = 'alpha:beta';
331 %seen = map { $_ => 1 } inter::libparrot::get_libpaths($conf);
332 ok( $seen{'/usr/local/lib'}, "Got expected lib: LD_LIBRARY_PATH" );
333 ok( $seen{'/usr/lib'}, "Got expected lib: LD_LIBRARY_PATH" );
334 ok( $seen{'alpha'}, "Got expected lib: LD_LIBRARY_PATH" );
335 ok( $seen{'beta'}, "Got expected lib: LD_LIBRARY_PATH" );
339 local $ENV{LD_RUN_PATH} = 'alpha:beta';
340 %seen = map { $_ => 1 } inter::libparrot::get_libpaths($conf);
341 ok( $seen{'/usr/local/lib'}, "Got expected lib: LD_RUN_PATH" );
342 ok( $seen{'/usr/lib'}, "Got expected lib: LD_RUN_PATH" );
343 ok( $seen{'alpha'}, "Got expected lib: LD_RUN_PATH" );
344 ok( $seen{'beta'}, "Got expected lib: LD_RUN_PATH" );
348 local $ENV{DYLD_LIBRARY_PATH} = 'alpha:beta';
349 %seen = map { $_ => 1 } inter::libparrot::get_libpaths($conf);
350 ok( $seen{'/usr/local/lib'}, "Got expected lib: DYLD_LIBRARY_PATH" );
351 ok( $seen{'/usr/lib'}, "Got expected lib: DYLD_LIBRARY_PATH" );
352 ok( $seen{'alpha'}, "Got expected lib: DYLD_LIBRARY_PATH" );
353 ok( $seen{'beta'}, "Got expected lib: DYLD_LIBRARY_PATH" );
356 pass("Completed all tests in $0");
358 ################### DOCUMENTATION ###################
362 inter/libparrot-01.t - test inter::libparrot
366 % prove t/steps/inter/libparrot-01.t
370 The files in this directory test functionality used by F<Configure.pl>.
372 The tests in this file test inter::libparrot.
380 config::inter::libparrot, F<Configure.pl>.
386 # cperl-indent-level: 4
389 # vim: expandtab shiftwidth=4: