2 # Copyright (C) 2007, Parrot Foundation.
8 use Test::More tests => 53;
10 use lib qw( lib t/configure/testlib );
11 use_ok('config::auto::sizes');
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 |;
20 ########## _handle_intval_ptrsize_discrepancy() ##########
22 my ($args, $step_list_ref) = process_options(
29 my $conf = Parrot::Configure::Step::Test->new;
30 $conf->include_config_results( $args );
32 my $serialized = $conf->pcfreeze();
34 my $pkg = q{auto::sizes};
36 $conf->add_steps($pkg);
37 $conf->options->set( %{$args} );
38 my $step = test_step_constructor_and_description($conf);
46 sub { auto::sizes::_handle_intval_ptrsize_discrepancy(\%results); },
49 ok(! $stdout, "As expected, no warning needed");
59 sub { auto::sizes::_handle_intval_ptrsize_discrepancy(\%results); },
62 like($stdout, qr/I see your chosen INTVAL/s,
63 "Got expected warning about discrepancy"
67 ########## _set_int2() ##########
71 my %results = ( shortsize => 2 );
73 sub { auto::sizes::_set_int2($conf, \%results); },
76 is($conf->data->get( 'int2_t' ), q{short},
77 "Got expected value for int2_t");
78 ok(! $stdout, "As expected, no warning needed");
83 my %results = ( shortsize => 4 );
85 sub { auto::sizes::_set_int2($conf, \%results); },
88 is($conf->data->get( 'int2_t' ), q{int},
89 "Got expected value for int2_t");
90 like($stdout, qr/conversion ops might fail/s,
91 "Got expected warning");
94 ########## _set_int4() ##########
98 my %results = ( shortsize => 4 );
100 sub { auto::sizes::_set_int4($conf, \%results); },
103 is($conf->data->get( 'int4_t' ), q{short},
104 "Got expected value for int4_t");
105 ok(! $stdout, "As expected, no warning needed");
110 my %results = ( intsize => 4 );
112 sub { auto::sizes::_set_int4($conf, \%results); },
115 is($conf->data->get( 'int4_t' ), q{int},
116 "Got expected value for int4_t");
117 ok(! $stdout, "As expected, no warning needed");
122 my %results = ( longsize => 4 );
124 sub { auto::sizes::_set_int4($conf, \%results); },
127 is($conf->data->get( 'int4_t' ), q{long},
128 "Got expected value for int4_t");
129 ok(! $stdout, "As expected, no warning needed");
136 sub { auto::sizes::_set_int4($conf, \%results); },
139 is($conf->data->get( 'int4_t' ), q{int},
140 "Got expected value for int4_t");
141 like($stdout, qr/conversion ops might fail/s,
142 "Got expected warning");
145 ########## _set_float4() ##########
149 my %results = ( floatsize => 4 );
151 sub { auto::sizes::_set_float4($conf, \%results); },
154 is($conf->data->get( 'float4_t' ), q{float},
155 "Got expected value for float4_t");
156 ok(! $stdout, "As expected, no warning needed");
161 my %results = ( floatsize => 8 );
163 sub { auto::sizes::_set_float4($conf, \%results); },
166 is($conf->data->get( 'float4_t' ), q{double},
167 "Got expected value for float4_t");
168 like($stdout, qr/conversion ops might fail/s,
169 "Got expected warning");
172 ########## _set_float8() ##########
176 my %results = ( doublesize => 8 );
178 sub { auto::sizes::_set_float8($conf, \%results); },
181 is($conf->data->get( 'float8_t' ), q{double},
182 "Got expected value for float8_t");
183 ok(! $stdout, "As expected, no warning needed");
190 sub { auto::sizes::_set_float8($conf, \%results); },
193 is($conf->data->get( 'float8_t' ), q{double},
194 "Got expected value for float8_t");
195 like($stdout, qr/conversion ops might fail/s,
196 "Got expected warning");
199 ########## _handle_hugeintvalsize() ##########
201 my (%hugeintval, $intval, $intvalsize);
203 $conf->data->set( intval => undef );
204 $conf->data->set( intvalsize => undef );
205 $hugeintval{hugeintvalsize} = undef;
206 $intval = q{integer};
208 auto::sizes::_handle_hugeintvalsize(
211 hugeintval => \%hugeintval,
213 intvalsize => $intvalsize,
216 is( $conf->data->get( 'hugeintval' ), $intval,
217 "Got expected value for hugeintval");
218 is( $conf->data->get( 'hugeintvalsize' ), $intvalsize,
219 "Got expected value for hugeintvalsize");
220 $conf->data->set( hugeintval => undef );
221 $conf->data->set( hugeintvalsize => undef );
223 $conf->data->set( intval => undef );
224 $conf->data->set( intvalsize => undef );
225 $hugeintval{hugeintvalsize} = 4;
226 $intval = q{integer};
228 auto::sizes::_handle_hugeintvalsize(
231 hugeintval => \%hugeintval,
233 intvalsize => $intvalsize,
236 is( $conf->data->get( 'hugeintval' ), $intval,
237 "Got expected value for hugeintval");
238 is( $conf->data->get( 'hugeintvalsize' ), $intvalsize,
239 "Got expected value for hugeintvalsize");
240 $conf->data->set( hugeintval => undef );
241 $conf->data->set( hugeintvalsize => undef );
243 $conf->data->set( intval => undef );
244 $conf->data->set( intvalsize => undef );
245 $hugeintval{hugeintvalsize} = 8;
246 $intval = q{integer};
248 auto::sizes::_handle_hugeintvalsize(
251 hugeintval => \%hugeintval,
253 intvalsize => $intvalsize,
256 ok( ! defined $conf->data->get( 'hugeintval' ),
257 "Got expected value for hugeintval");
258 ok( ! defined $conf->data->get( 'hugeintvalsize' ),
259 "Got expected value for hugeintvalsize");
260 $conf->data->set( hugeintval => undef );
261 $conf->data->set( hugeintvalsize => undef );
263 $conf->data->set( intval => undef );
264 $conf->data->set( intvalsize => undef );
266 ########## _set_hugefloatval() ##########
269 auto::sizes::_set_hugefloatval( $conf, $size );
270 is( $conf->data->get( 'hugefloatval' ), 'long double',
271 "Got expected type for hugefloatval");
272 is( $conf->data->get( 'hugefloatvalsize' ), $size,
273 "Got expected size for hugefloatvalsize");
275 auto::sizes::_set_hugefloatval( $conf, 0 );
276 is( $conf->data->get( 'hugefloatval' ), 'double',
277 "Got expected type for hugefloatval");
278 is( $conf->data->get( 'hugefloatvalsize' ), $conf->data->get('doublesize'),
279 "Got expected size for hugefloatvalsize");
281 ########## _set_intvalmaxmin() ##########
284 $conf->data->get( 'iv' ),
285 $conf->data->get( 'intvalmin' ),
286 $conf->data->get( 'intvalmax' ),
288 $conf->data->set( iv => 'int' );
289 auto::sizes::_set_intvalmaxmin( $conf );
290 is( $conf->data->get( 'intvalmin' ), 'INT_MIN',
291 "Got expected value for 'intvalmin' when 'iv' is 'int'" );
292 is( $conf->data->get( 'intvalmax' ), 'INT_MAX',
293 "Got expected value for 'intvalmax' when 'iv' is 'int'" );
295 $conf->data->set( iv => 'long' );
296 auto::sizes::_set_intvalmaxmin( $conf );
297 is( $conf->data->get( 'intvalmin' ), 'LONG_MIN',
298 "Got expected value for 'intvalmin' when 'iv' is 'long'" );
299 is( $conf->data->get( 'intvalmax' ), 'LONG_MAX',
300 "Got expected value for 'intvalmax' when 'iv' is 'long'" );
302 $conf->data->set( iv => 'long int' );
303 auto::sizes::_set_intvalmaxmin( $conf );
304 is( $conf->data->get( 'intvalmin' ), 'LONG_MIN',
305 "Got expected value for 'intvalmin' when 'iv' is 'long int'" );
306 is( $conf->data->get( 'intvalmax' ), 'LONG_MAX',
307 "Got expected value for 'intvalmax' when 'iv' is 'long int'" );
309 $conf->data->set( iv => 'long long' );
310 auto::sizes::_set_intvalmaxmin( $conf );
311 is( $conf->data->get( 'intvalmin' ), 'LLONG_MIN',
312 "Got expected value for 'intvalmin' when 'iv' is 'long long'" );
313 is( $conf->data->get( 'intvalmax' ), 'LLONG_MAX',
314 "Got expected value for 'intvalmax' when 'iv' is 'long long'" );
316 $conf->data->set( iv => 'long long int' );
317 auto::sizes::_set_intvalmaxmin( $conf );
318 is( $conf->data->get( 'intvalmin' ), 'LLONG_MIN',
319 "Got expected value for 'intvalmin' when 'iv' is 'long long int'" );
320 is( $conf->data->get( 'intvalmax' ), 'LLONG_MAX',
321 "Got expected value for 'intvalmax' when 'iv' is 'long long int'" );
323 my $badtype = 'foobar';
324 $conf->data->set( iv => $badtype );
325 eval { auto::sizes::_set_intvalmaxmin( $conf ); };
326 like($@, qr/Configure.pl: Cannot find limits for type '$badtype'/,
327 "Got expected 'die' message for unrecognized 'iv'");
329 # Reset true values prior to subsequent tests.
330 $conf->data->set( 'iv' => $trueintvals[0] );
331 $conf->data->set( 'intvalmin' => $trueintvals[1] );
332 $conf->data->set( 'intvalmax' => $trueintvals[2] );
334 ########## _set_floatvalmaxmin() ##########
336 my @truefloatvals = (
337 $conf->data->get( 'nv' ),
338 $conf->data->get( 'floatvalmin' ),
339 $conf->data->get( 'floatvalmax' ),
342 $conf->data->set( nv => 'double' );
343 auto::sizes::_set_floatvalmaxmin( $conf );
344 is( $conf->data->get( 'floatvalmin' ), 'DBL_MIN',
345 "Got expected value for 'floatvalmin' when 'nv' is 'double'" );
346 is( $conf->data->get( 'floatvalmax' ), 'DBL_MAX',
347 "Got expected value for 'floatvalmax' when 'nv' is 'double'" );
349 $conf->data->set( nv => 'long double' );
350 auto::sizes::_set_floatvalmaxmin( $conf );
351 is( $conf->data->get( 'floatvalmin' ), 'LDBL_MIN',
352 "Got expected value for 'floatvalmin' when 'nv' is 'long double'" );
353 is( $conf->data->get( 'floatvalmax' ), 'LDBL_MAX',
354 "Got expected value for 'floatvalmax' when 'nv' is 'long double'" );
357 $conf->data->set( nv => $badtype );
358 eval { auto::sizes::_set_floatvalmaxmin( $conf ); };
359 like($@, qr/Configure.pl: Cannot find limits for type '$badtype'/,
360 "Got expected 'die' message for unrecognized 'nv'");
362 pass("Completed all tests in $0");
364 ################### DOCUMENTATION ###################
368 auto/sizes-01.t - test auto::sizes
372 % prove t/steps/auto/sizes-01.t
376 The files in this directory test functionality used by F<Configure.pl>.
378 The tests in this file test auto::sizes.
386 config::auto::sizes, F<Configure.pl>.
392 # cperl-indent-level: 4
395 # vim: expandtab shiftwidth=4: