2 # Copyright (C) 2007, Parrot Foundation.
8 use Test::More tests => 32;
10 use lib qw( lib t/configure/testlib );
11 use_ok('config::auto::gettext');
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 IO::CaptureOutput qw( capture );
19 ########## --without-gettext ##########
21 my ($args, $step_list_ref) = process_options(
23 argv => [ q{--without-gettext} ],
28 my $conf = Parrot::Configure::Step::Test->new;
29 $conf->include_config_results( $args );
31 my $pkg = q{auto::gettext};
33 $conf->add_steps($pkg);
35 my $serialized = $conf->pcfreeze();
37 $conf->options->set( %{$args} );
38 my $step = test_step_constructor_and_description($conf);
39 my $ret = $step->runstep($conf);
40 ok( $ret, "runstep() returned true value" );
41 is($conf->data->get('has_gettext'), 0,
42 "Got expected value for 'has_gettext'");
43 is($step->result(), q{no}, "Expected result was set");
45 $conf->replenish($serialized);
47 ########## _select_lib() ##########
49 ($args, $step_list_ref) = process_options( {
53 $conf->options->set( %{$args} );
54 $step = test_step_constructor_and_description($conf);
56 # Mock values for OS and C-compiler
57 my ($osname, $cc, $initial_value);
60 $initial_value = $conf->data->get( 'libs' );
61 is($step->_select_lib( {
65 win32_gcc => '-lintl',
66 win32_nongcc => 'intl.lib',
67 default => defined $conf->data->get('glibc') ? '' : '-lintl',
70 "_select_lib() returned expected value");
74 is($step->_select_lib( {
78 win32_gcc => '-lintl',
79 win32_nongcc => 'intl.lib',
80 default => defined $conf->data->get('glibc') ? '' : '-lintl',
83 "_select_lib() returned expected value");
87 $conf->data->set( glibc => 1 );
88 isnt($step->_select_lib( {
92 win32_gcc => '-lintl',
93 win32_nongcc => 'intl.lib',
94 default => defined $conf->data->get('glibc') ? '' : '-lintl',
97 "_select_lib() returned expected value");
101 $conf->data->set( glibc => undef );
102 is($step->_select_lib( {
106 win32_gcc => '-lintl',
107 win32_nongcc => 'intl.lib',
108 default => defined $conf->data->get('glibc') ? '' : '-lintl',
111 "_select_lib() returned expected value");
113 ########## _evaluate_cc_run() ##########
118 $test = "Hello, world!\n";
119 $conf->options->set(verbose => undef);
120 $has_gettext = $step->_evaluate_cc_run($conf, $test);
121 is($has_gettext, 1, "Got expected value for has_gettext");
122 is($step->result(), 'yes', "Expected result was set");
123 # Prepare for next test
124 $step->set_result(undef);
128 $test = "Hello, world!\n";
129 $conf->options->set(verbose => 1);
132 $has_gettext = $step->_evaluate_cc_run($conf, $test);
136 is($has_gettext, 1, "Got expected value for has_gettext");
137 is($step->result(), 'yes', "Expected result was set");
138 like($stdout, qr/\(yes\)/, "Got expected verbose output");
139 # Prepare for next test
140 $step->set_result(undef);
144 $conf->options->set(verbose => undef);
145 $has_gettext = $step->_evaluate_cc_run($conf, $test);
146 is($has_gettext, 0, "Got expected value for has_gettext");
147 ok(! defined $step->result(), "As expected, result is not yet defined");
149 $conf->replenish($serialized);
151 ########## --without-gettext; _handle_gettext() ##########
153 ($args, $step_list_ref) = process_options( {
154 argv => [ q{--without-gettext} ],
155 mode => q{configure},
157 $conf->options->set( %{$args} );
158 $step = test_step_constructor_and_description($conf);
160 $conf->options->set(verbose => undef);
161 $conf->data->set( ccflags => q{} );
162 $conf->data->set( libs => q{} );
163 my $libs = q{foo bar baz};
164 ok(auto::gettext::_handle_gettext($conf, $libs),
165 "_handle_gettext() returned true value");
166 like($conf->data->get( 'ccflags' ), qr/-DHAS_GETTEXT/,
167 "HAS_GETTEXT was added to 'ccflags'");
168 like($conf->data->get( 'libs' ), qr/$libs/,
169 "Values added to 'libs' as expected");
171 $conf->data->set( ccflags => q{} );
172 $conf->data->set( libs => q{} );
175 $conf->options->set(verbose => 1);
177 sub { $rv = auto::gettext::_handle_gettext($conf, $libs); },
180 ok($rv, "_handle_gettext() returned true value");
181 like($conf->data->get( 'ccflags' ), qr/-DHAS_GETTEXT/,
182 "HAS_GETTEXT was added to 'ccflags'");
183 like($conf->data->get( 'libs' ), qr/$libs/,
184 "Values added to 'libs' as expected");
186 qr/ccflags:\s.*-DHAS_GETTEXT/,
187 "Got expected verbose output"
189 $conf->options->set(verbose => undef);
192 pass("Completed all tests in $0");
194 ################### DOCUMENTATION ###################
198 auto/gettext-01.t - test auto::gettext
202 % prove t/steps/auto/gettext-01.t
206 The files in this directory test functionality used by F<Configure.pl>.
208 The tests in this file test auto::gettext.
216 config::auto::gettext, F<Configure.pl>.
222 # cperl-indent-level: 4
225 # vim: expandtab shiftwidth=4: