tagged release 0.6.4
[parrot.git] / t / steps / auto_icu-01.t
blob4c9e8a23e4ddd5d046eda7c6924bc3364a6c312b
1 #! perl
2 # Copyright (C) 2007, The Perl Foundation.
3 # $Id$
4 # auto_icu-01.t
6 use strict;
7 use warnings;
8 use Test::More tests => 81;
9 use Carp;
10 use Cwd;
11 use File::Path qw( mkpath );
12 use File::Temp qw( tempdir );
13 use lib qw( lib t/configure/testlib );
14 use_ok('config::init::defaults');
15 use_ok('config::auto::icu');
16 use Parrot::Configure;
17 use Parrot::Configure::Options qw( process_options );
18 use Parrot::Configure::Test qw( test_step_thru_runstep);
19 use IO::CaptureOutput qw( capture );
21 my $args = process_options(
22     {
23         argv => [ q{--without-icu}  ],
24         mode => q{configure},
25     }
28 my $conf = Parrot::Configure->new;
30 test_step_thru_runstep( $conf, q{init::defaults}, $args );
32 my $pkg = q{auto::icu};
34 $conf->add_steps($pkg);
35 $conf->options->set( %{$args} );
37 my ( $task, $step_name, $step);
38 $task        = $conf->steps->[-1];
39 $step_name   = $task->step;
41 $step = $step_name->new();
42 ok( defined $step, "$step_name constructor returned defined value" );
43 isa_ok( $step, $step_name );
44 ok( $step->description(), "$step_name has description" );
46 my $ret = $step->runstep($conf);
47 ok( $ret, "$step_name runstep() returned true value" );
49 is( $conf->data->get('has_icu'), 0,
50     "Got expected value for 'has_icu'" );
51 is( $conf->data->get('icu_shared'), q{},
52     "Got expected value for 'icu_shared'" );
53 is( $conf->data->get('icu_dir'), q{},
54     "Got expected value for 'icu_dir'" );
55 is( $step->result(), 'not requested', "Got expected result" );
56 $step->set_result(q{});  # prepare for subsequent tests
58 # Test some internal routines
59 my $icuconfig;
60 my $phony = q{/path/to/icu-config};
62 is($step->_handle_icuconfig_opt(undef), q{},
63     "Got expected value for icu-config");
64 is($step->_handle_icuconfig_opt('none'), q{},
65     "Got expected value for icu-config");
66 is($step->_handle_icuconfig_opt($phony), $phony,
67     "Got expected value for icu-config");
69 my ($autodetect, $without);
71 ($icuconfig, $autodetect, $without) =
72     $step->_handle_search_for_icu_config( {
73         icuconfig   => q{},
74         autodetect  => 1,
75         without     => 0,
76         verbose     => 0,
77         ret         => -1,
78 } );
79 ok(! defined $icuconfig, "icu-config not found, as expected");
80 is($autodetect, 0, "Autodetection cancelled, as expected");
81 is($without, 1, "Continuing to configure without ICU");
83 ($icuconfig, $autodetect, $without) =
84     $step->_handle_search_for_icu_config( {
85         icuconfig   => q{},
86         autodetect  => 1,
87         without     => 0,
88         verbose     => 0,
89         ret         => 256,
90 } );
91 ok(! defined $icuconfig, "icu-config not found, as expected");
92 is($autodetect, 0, "Autodetection cancelled, as expected");
93 is($without, 1, "Continuing to configure without ICU");
95 ($icuconfig, $autodetect, $without) =
96     $step->_handle_search_for_icu_config( {
97         icuconfig   => q{},
98         autodetect  => 1,
99         without     => 0,
100         verbose     => 0,
101         ret         => 0,
102 } );
103 is($icuconfig, q{icu-config}, "icu-config found, as expected");
104 is($autodetect, 1, "Autodetection continues, as expected");
105 is($without, 0, "Continuing to try to configure with ICU");
108     my ($stdout, $stderr);
109     capture( sub {
110             ($icuconfig, $autodetect, $without) =
111                 $step->_handle_search_for_icu_config( {
112                     icuconfig   => q{},
113                     autodetect  => 1,
114                     without     => 0,
115                     verbose     => 1,
116                     ret         => 0,
117             } );
118         },
119         \$stdout,
120         \$stderr,
121     );
122     is($icuconfig, q{icu-config}, "icu-config found, as expected");
123     is($autodetect, 1, "Autodetection continues, as expected");
124     is($without, 0, "Continuing to try to configure with ICU");
125     like($stdout, qr/icu-config found/,
126         "Got expected verbose output");
129 ($icuconfig, $autodetect, $without) =
130     $step->_handle_autodetect( {
131         icuconfig   => $phony,
132         autodetect  => 1,
133         without     => 0,
134         verbose     => 0,
135 } );
136 is($icuconfig, $phony, "icu-config unchanged, as expected");
137 is($autodetect, 1, "Autodetection still active, as expected");
138 is($without, 0, "Continuing to try to configure with ICU");
141     my ($stdout, $stderr);
142     capture( sub {
143         ($icuconfig, $autodetect, $without) =
144             $step->_handle_autodetect( {
145                 icuconfig   => $phony,
146                 autodetect  => 0,
147                 without     => 0,
148                 verbose     => 1,
149             } );
150         },
151         \$stdout,
152         \$stderr,
153     );
154     is($icuconfig, $phony, "icu-config unchanged, as expected");
155     is($autodetect, 0, "Autodetection still inactive, as expected");
156     is($without, 0, "Continuing to try to configure with ICU");
157     like($stdout, qr/ICU autodetection disabled/s,
158         "Got expected verbose output");
161 my $icushared;
163 $icushared = qq{-licui18n -lalpha\n};
164 ($icushared, $without) = $step->_handle_icushared($icushared, 0);
165 like($icushared, qr/-lalpha/, "Got expected ld flags");
166 is($without, 0, "Continuing to try to configure with ICU");
168 $icushared = qq{-licui18n\n};
169 ($icushared, $without) = $step->_handle_icushared($icushared, 0);
170 ok(! $icushared, "No icushared, as expected");
171 is($without, 1, "No longer trying to configure with ICU");
173 $icushared = undef;
174 ($icushared, $without) = $step->_handle_icushared($icushared, 0);
175 ok(! defined $icushared, "icushared remains undefined, as expected");
176 is($without, 0, "Continuing to try to configure with ICU");
178 my $icuheaders;
179 ($icuheaders, $without) =
180     $step->_handle_icuheaders($conf, undef, 0);
181 ok(! defined $icuheaders, "icuheaders path undefined, as expected");
182 is($without, 0, "Continuing to try to configure with ICU");
184 my $cwd = cwd();
186     my $tdir = tempdir();
187     chdir $tdir or croak "Unable to change to temporary directory";
188     my $expected_dir = q{alpha};
189     my $expected_include_dir =
190         $expected_dir . $conf->data->get('slash') .  q{include};
191     ($icuheaders, $without) =
192         $step->_handle_icuheaders($conf, qq{$expected_dir\n}, 0);
193     is($icuheaders, $expected_include_dir,
194         "Got expected icuheaders path value");
195     is($without, 1, "No longer trying to configure with ICU");
196     chdir $cwd or croak "Unable to change back to starting directory";
200     my $tdir = tempdir();
201     chdir $tdir or croak "Unable to change to temporary directory";
202     my $expected_dir = q{alpha};
203     my $expected_include_dir =
204         $expected_dir . $conf->data->get('slash') .  q{include};
205     mkdir $expected_dir or croak "Unable to make testing directory";
206     ($icuheaders, $without) =
207         $step->_handle_icuheaders($conf, qq{$expected_dir\n}, 0);
208     is($icuheaders, $expected_include_dir,
209         "Got expected icuheaders path value");
210     is($without, 1, "No longer trying to configure with ICU");
211     chdir $cwd or croak "Unable to change back to starting directory";
215     my $tdir = tempdir();
216     chdir $tdir or croak "Unable to change to temporary directory";
217     my $expected_dir = q{alpha};
218     my $expected_include_dir =
219         $expected_dir . $conf->data->get('slash') .  q{include};
220     mkdir $expected_dir or croak "Unable to make testing directory";
221     mkpath($expected_include_dir, 0, 755)
222         or croak "Unable to make second-level testing directory";
223     ($icuheaders, $without) =
224         $step->_handle_icuheaders($conf, qq{$expected_dir\n}, 0);
225     is($icuheaders, $expected_include_dir,
226         "Got expected icuheaders path value");
227     is($without, 0, "Continuing to try to configure with ICU");
228     chdir $cwd or croak "Unable to change back to starting directory";
231 ($without, $icushared, $icuheaders) =
232     $step->_try_icuconfig(
233         $conf,
234         {
235             without         => 1,
236             autodetect      => 1,
237             icuconfig       => 1,
238             verbose         => 0,
239         }
240     );
241 is($without, 1, "Not trying to configure with ICU");
242 ok(! defined $icushared, "icushared undefined, as expected");
243 ok(! defined $icuheaders, "icuheaders undefined, as expected");
244 is($step->result(), q{}, "result is still empty string, as expected");
246 ($without, $icushared, $icuheaders) =
247     $step->_try_icuconfig(
248         $conf,
249         {
250             without         => 0,
251             autodetect      => 0,
252             icuconfig       => 1,
253             verbose         => 0,
254         }
255     );
256 is($without, 0, "Still trying to configure with ICU");
257 ok(! defined $icushared, "icushared undefined, as expected");
258 ok(! defined $icuheaders, "icuheaders undefined, as expected");
259 is($step->result(), q{}, "result is still empty string, as expected");
261 ($without, $icushared, $icuheaders) =
262     $step->_try_icuconfig(
263         $conf,
264         {
265             without         => 0,
266             autodetect      => 1,
267             icuconfig       => q{},
268             verbose         => 0,
269         }
270     );
271 is($without, 0, "Still trying to configure with ICU");
272 ok(! defined $icushared, "icushared undefined, as expected");
273 ok(! defined $icuheaders, "icuheaders undefined, as expected");
274 is($step->result(), q{}, "result is still empty string, as expected");
276 my $die = auto::icu::_die_message();
277 like($die, qr/Something is wrong with your ICU installation/s,
278     "Got expected die message");
280 {   
281     my $phony = q{/path/to/icu-config};
282     my ($stdout, $stderr);
283     capture(
284         sub { auto::icu::_verbose_report(1, $phony, undef, undef); },
285         \$stdout,
286         \$stderr,
287     );
288     like( $stdout, qr/icuconfig:\s+$phony/s,
289         "Got expected verbose output"
290     );
293 {   
294     my $phony = q{-lalpha};
295     my ($stdout, $stderr);
296     capture(
297         sub { auto::icu::_verbose_report(1, undef, $phony, undef); },
298         \$stdout,
299         \$stderr,
300     );
301     like( $stdout, qr/icushared='$phony'/s,
302         "Got expected verbose output"
303     );
306 {   
307     my $phony = q{alpha/include};
308     my ($stdout, $stderr);
309     capture(
310         sub { auto::icu::_verbose_report(1, undef, undef, $phony); },
311         \$stdout,
312         \$stderr,
313     );
314     like( $stdout, qr/headers='$phony'/s,
315         "Got expected verbose output"
316     );
319 {   
320     my ($stdout, $stderr);
321     capture(
322         sub { auto::icu::_verbose_report(0, 'alpha', 'beta', 'gamma'); },
323         \$stdout,
324         \$stderr,
325     );
326     ok(! $stdout, "No verbose output, as expected");
330     my ($stdout, $stderr);
331     capture(
332         sub {
333             $icuheaders = $step->_handle_icuconfig_errors( {
334                 icushared   => undef,
335                 icuheaders  => undef,
336             } );
337         },
338         \$stdout,
339         \$stderr,
340     );
341     like($stderr, qr/error: icushared not defined/s,
342         "Got expected warnings");
343     like($stderr, qr/error: icuheaders not defined or invalid/s,
344         "Got expected warnings");
345     like($stderr, qr/Something is wrong with your ICU installation/s,
346         "Got expected warnings");
349 $icuheaders = q{alpha};
350 my $status = $conf->data->get( 'ccflags' );
353     my ($stdout, $stderr);
354     capture(
355         sub {
356            auto::icu::_handle_ccflags_status($conf,
357                {
358                    ccflags_status  => 1,
359                    verbose         => 1,
360                    icuheaders      => $icuheaders,
361                },
362            );
363        },
364        \$stdout,
365        \$stderr,
366    );
367    like($stdout, qr/Your compiler found the icu headers/,
368        "Got expected verbose output");
370 $conf->data->set( ccflags => $status ); # re-set for next test
373     my ($stdout, $stderr);
374     capture(
375         sub {
376            auto::icu::_handle_ccflags_status($conf,
377                {
378                    ccflags_status  => 0,
379                    verbose         => 1,
380                    icuheaders      => $icuheaders,
381                },
382            );
383        },
384        \$stdout,
385        \$stderr,
386    );
388    like($stdout, qr/Adding -I $icuheaders to ccflags for icu headers/,
389        "Got expected verbose output");
391 like($conf->data->get( 'ccflags'),
392     qr/-I $icuheaders/,
393     "ccflags augmented as expected"
395 $conf->data->set( ccflags => $status ); # re-set for next test
398     my ($stdout, $stderr);
399     capture(
400         sub {
401            auto::icu::_handle_ccflags_status($conf,
402                {
403                    ccflags_status  => 0,
404                    verbose         => 0,
405                    icuheaders      => $icuheaders,
406                },
407            );
408        },
409        \$stdout,
410        \$stderr,
411    );
413    ok(! $stdout, "No verbose output, as expected");
415 like($conf->data->get( 'ccflags'),
416     qr/-I $icuheaders/,
417     "ccflags augmented as expected"
419 $conf->data->set( ccflags => $status ); # re-set for next test
421 $conf->data->set( 'has_icu', undef );
422 $conf->data->set( 'icu_shared', undef );
423 $conf->data->set( 'icu_dir', undef );
424 my $result = q{hooray!};
425 $step->_set_no_configure_with_icu($conf, $result);
426 is($conf->data->get( 'has_icu' ), 0,
427     "Got expected value for 'has_icu'");
428 is($conf->data->get( 'icu_shared' ), q{},
429     "Got expected value for 'icu_shared'");
430 is($conf->data->get( 'icu_dir' ), q{},
431     "Got expected value for 'icu_dir'");
432 is($step->{result}, $result, "Got expected result");
433 # reset for next test
434 $conf->data->set( 'has_icu', undef );
435 $conf->data->set( 'icu_shared', undef );
436 $conf->data->set( 'icu_dir', undef );
438 pass("Completed all tests in $0");
440 ################### DOCUMENTATION ###################
442 =head1 NAME
444 auto_icu-01.t - test config::auto::icu
446 =head1 SYNOPSIS
448     % prove t/steps/auto_icu-01.t
450 =head1 DESCRIPTION
452 The files in this directory test functionality used by F<Configure.pl>.
454 The tests in this file test config::auto::icu in the case where configuration
455 without ICU is requested.  Also tested are most of the internal subroutines
456 and methods.
458 =head1 AUTHOR
460 James E Keenan
462 =head1 SEE ALSO
464 config::auto::icu, F<Configure.pl>.
466 =cut
468 # Local Variables:
469 #   mode: cperl
470 #   cperl-indent-level: 4
471 #   fill-column: 100
472 # End:
473 # vim: expandtab shiftwidth=4: