2 # Copyright (C) 2007, The Perl Foundation.
8 use Test::More tests => 81;
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(
23 argv => [ q{--without-icu} ],
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
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( {
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( {
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( {
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);
110 ($icuconfig, $autodetect, $without) =
111 $step->_handle_search_for_icu_config( {
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( {
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);
143 ($icuconfig, $autodetect, $without) =
144 $step->_handle_autodetect( {
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");
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");
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");
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");
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(
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(
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(
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");
281 my $phony = q{/path/to/icu-config};
282 my ($stdout, $stderr);
284 sub { auto::icu::_verbose_report(1, $phony, undef, undef); },
288 like( $stdout, qr/icuconfig:\s+$phony/s,
289 "Got expected verbose output"
294 my $phony = q{-lalpha};
295 my ($stdout, $stderr);
297 sub { auto::icu::_verbose_report(1, undef, $phony, undef); },
301 like( $stdout, qr/icushared='$phony'/s,
302 "Got expected verbose output"
307 my $phony = q{alpha/include};
308 my ($stdout, $stderr);
310 sub { auto::icu::_verbose_report(1, undef, undef, $phony); },
314 like( $stdout, qr/headers='$phony'/s,
315 "Got expected verbose output"
320 my ($stdout, $stderr);
322 sub { auto::icu::_verbose_report(0, 'alpha', 'beta', 'gamma'); },
326 ok(! $stdout, "No verbose output, as expected");
330 my ($stdout, $stderr);
333 $icuheaders = $step->_handle_icuconfig_errors( {
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);
356 auto::icu::_handle_ccflags_status($conf,
360 icuheaders => $icuheaders,
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);
376 auto::icu::_handle_ccflags_status($conf,
380 icuheaders => $icuheaders,
388 like($stdout, qr/Adding -I $icuheaders to ccflags for icu headers/,
389 "Got expected verbose output");
391 like($conf->data->get( 'ccflags'),
393 "ccflags augmented as expected"
395 $conf->data->set( ccflags => $status ); # re-set for next test
398 my ($stdout, $stderr);
401 auto::icu::_handle_ccflags_status($conf,
405 icuheaders => $icuheaders,
413 ok(! $stdout, "No verbose output, as expected");
415 like($conf->data->get( 'ccflags'),
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 ###################
444 auto_icu-01.t - test config::auto::icu
448 % prove t/steps/auto_icu-01.t
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
464 config::auto::icu, F<Configure.pl>.
470 # cperl-indent-level: 4
473 # vim: expandtab shiftwidth=4: