2 # Copyright (C) 2007, The Perl Foundation.
8 use Test::More tests => 50;
10 use lib qw( lib t/configure/testlib );
11 use_ok('config::init::defaults');
12 use_ok('config::auto::sizes');
13 use Parrot::Configure;
14 use Parrot::Configure::Options qw( process_options );
15 use Parrot::Configure::Test qw(
16 test_step_thru_runstep
17 rerun_defaults_for_testing
18 test_step_constructor_and_description
20 use IO::CaptureOutput qw | capture |;
22 ########## --miniparrot ##########
24 my ($args, $step_list_ref) = process_options(
26 argv => [ q{--miniparrot} ],
31 my $conf = Parrot::Configure->new;
33 my $serialized = $conf->pcfreeze();
35 test_step_thru_runstep( $conf, q{init::defaults}, $args );
37 my $pkg = q{auto::sizes};
39 $conf->add_steps($pkg);
40 $conf->options->set( %{$args} );
41 my $step = test_step_constructor_and_description($conf);
43 my $ret = $step->runstep($conf);
44 ok( $ret, "runstep() returned true value" );
45 is($step->result(), q{using miniparrot defaults}, "Expected result was set");
47 $conf->replenish($serialized);
49 ########## _handle_intval_ptrsize_discrepancy() ##########
51 ($args, $step_list_ref) = process_options(
58 rerun_defaults_for_testing($conf, $args );
60 $pkg = q{auto::sizes};
62 $conf->add_steps($pkg);
63 $conf->options->set( %{$args} );
64 $step = test_step_constructor_and_description($conf);
72 sub { auto::sizes::_handle_intval_ptrsize_discrepancy(\%results); },
75 ok(! $stdout, "As expected, no warning needed");
85 sub { auto::sizes::_handle_intval_ptrsize_discrepancy(\%results); },
88 like($stdout, qr/I see your chosen INTVAL/s,
89 "Got expected warning about discrepancy"
93 ########## _set_int2() ##########
97 my %results = ( shortsize => 2 );
99 sub { auto::sizes::_set_int2($conf, \%results); },
102 is($conf->data->get( 'int2_t' ), q{short},
103 "Got expected value for int2_t");
104 ok(! $stdout, "As expected, no warning needed");
109 my %results = ( shortsize => 4 );
111 sub { auto::sizes::_set_int2($conf, \%results); },
114 is($conf->data->get( 'int2_t' ), q{int},
115 "Got expected value for int2_t");
116 like($stdout, qr/conversion ops might fail/s,
117 "Got expected warning");
120 ########## _set_int4() ##########
124 my %results = ( shortsize => 4 );
126 sub { auto::sizes::_set_int4($conf, \%results); },
129 is($conf->data->get( 'int4_t' ), q{short},
130 "Got expected value for int4_t");
131 ok(! $stdout, "As expected, no warning needed");
136 my %results = ( intsize => 4 );
138 sub { auto::sizes::_set_int4($conf, \%results); },
141 is($conf->data->get( 'int4_t' ), q{int},
142 "Got expected value for int4_t");
143 ok(! $stdout, "As expected, no warning needed");
148 my %results = ( longsize => 4 );
150 sub { auto::sizes::_set_int4($conf, \%results); },
153 is($conf->data->get( 'int4_t' ), q{long},
154 "Got expected value for int4_t");
155 ok(! $stdout, "As expected, no warning needed");
162 sub { auto::sizes::_set_int4($conf, \%results); },
165 is($conf->data->get( 'int4_t' ), q{int},
166 "Got expected value for int4_t");
167 like($stdout, qr/conversion ops might fail/s,
168 "Got expected warning");
171 ########## _set_float4() ##########
175 my %results = ( floatsize => 4 );
177 sub { auto::sizes::_set_float4($conf, \%results); },
180 is($conf->data->get( 'float4_t' ), q{float},
181 "Got expected value for float4_t");
182 ok(! $stdout, "As expected, no warning needed");
187 my %results = ( floatsize => 8 );
189 sub { auto::sizes::_set_float4($conf, \%results); },
192 is($conf->data->get( 'float4_t' ), q{double},
193 "Got expected value for float4_t");
194 like($stdout, qr/conversion ops might fail/s,
195 "Got expected warning");
198 ########## _set_float8() ##########
202 my %results = ( doublesize => 8 );
204 sub { auto::sizes::_set_float8($conf, \%results); },
207 is($conf->data->get( 'float8_t' ), q{double},
208 "Got expected value for float8_t");
209 ok(! $stdout, "As expected, no warning needed");
216 sub { auto::sizes::_set_float8($conf, \%results); },
219 is($conf->data->get( 'float8_t' ), q{double},
220 "Got expected value for float8_t");
221 like($stdout, qr/conversion ops might fail/s,
222 "Got expected warning");
225 ########## _handle_hugeintvalsize() ##########
227 my (%hugeintval, $intval, $intvalsize);
229 $conf->data->set( intval => undef );
230 $conf->data->set( intvalsize => undef );
231 $hugeintval{hugeintvalsize} = undef;
232 $intval = q{integer};
234 auto::sizes::_handle_hugeintvalsize(
237 hugeintval => \%hugeintval,
239 intvalsize => $intvalsize,
242 is( $conf->data->get( 'hugeintval' ), $intval,
243 "Got expected value for hugeintval");
244 is( $conf->data->get( 'hugeintvalsize' ), $intvalsize,
245 "Got expected value for hugeintvalsize");
246 $conf->data->set( hugeintval => undef );
247 $conf->data->set( hugeintvalsize => undef );
249 $conf->data->set( intval => undef );
250 $conf->data->set( intvalsize => undef );
251 $hugeintval{hugeintvalsize} = 4;
252 $intval = q{integer};
254 auto::sizes::_handle_hugeintvalsize(
257 hugeintval => \%hugeintval,
259 intvalsize => $intvalsize,
262 is( $conf->data->get( 'hugeintval' ), $intval,
263 "Got expected value for hugeintval");
264 is( $conf->data->get( 'hugeintvalsize' ), $intvalsize,
265 "Got expected value for hugeintvalsize");
266 $conf->data->set( hugeintval => undef );
267 $conf->data->set( hugeintvalsize => undef );
269 $conf->data->set( intval => undef );
270 $conf->data->set( intvalsize => undef );
271 $hugeintval{hugeintvalsize} = 8;
272 $intval = q{integer};
274 auto::sizes::_handle_hugeintvalsize(
277 hugeintval => \%hugeintval,
279 intvalsize => $intvalsize,
282 ok( ! defined $conf->data->get( 'hugeintval' ),
283 "Got expected value for hugeintval");
284 ok( ! defined $conf->data->get( 'hugeintvalsize' ),
285 "Got expected value for hugeintvalsize");
286 $conf->data->set( hugeintval => undef );
287 $conf->data->set( hugeintvalsize => undef );
289 $conf->data->set( intval => undef );
290 $conf->data->set( intvalsize => undef );
292 ########## _set_hugefloatval() ##########
295 auto::sizes::_set_hugefloatval( $conf, $size );
296 is( $conf->data->get( 'hugefloatval' ), 'long double',
297 "Got expected type for hugefloatval");
298 is( $conf->data->get( 'hugefloatvalsize' ), $size,
299 "Got expected size for hugefloatvalsize");
301 auto::sizes::_set_hugefloatval( $conf, 0 );
302 is( $conf->data->get( 'hugefloatval' ), 'double',
303 "Got expected type for hugefloatval");
304 is( $conf->data->get( 'hugefloatvalsize' ), $conf->data->get('doublesize'),
305 "Got expected size for hugefloatvalsize");
307 pass("Completed all tests in $0");
309 ################### DOCUMENTATION ###################
313 auto_sizes-01.t - test auto::sizes
317 % prove t/steps/auto_sizes-01.t
321 The files in this directory test functionality used by F<Configure.pl>.
323 The tests in this file test auto::sizes.
331 config::auto::sizes, F<Configure.pl>.
337 # cperl-indent-level: 4
340 # vim: expandtab shiftwidth=4: