tagged release 0.7.1
[parrot.git] / t / steps / auto_sizes-01.t
blob475863022a7b8e95a81a40cade9bc43a012fdff4
1 #! perl
2 # Copyright (C) 2007, The Perl Foundation.
3 # $Id$
4 # auto_sizes-01.t
6 use strict;
7 use warnings;
8 use Test::More tests => 50;
9 use Carp;
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(
25     {
26         argv => [ q{--miniparrot} ],
27         mode => q{configure},
28     }
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(
52     {
53         argv => [ ],
54         mode => q{configure},
55     }
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);
66     my $stdout;
67     my %results = (
68         ptrsize         => 1,
69         intvalsize      => 1,
70     );
71     capture(
72         sub { auto::sizes::_handle_intval_ptrsize_discrepancy(\%results); },
73         \$stdout,
74     );
75     ok(! $stdout, "As expected, no warning needed");
79     my $stdout;
80     my %results = (
81         ptrsize         => 1,
82         intvalsize      => 2,
83     );
84     capture(
85         sub { auto::sizes::_handle_intval_ptrsize_discrepancy(\%results); },
86         \$stdout,
87     );
88     like($stdout, qr/I see your chosen INTVAL/s,
89         "Got expected warning about discrepancy"
90     );
93 ########## _set_int2() ##########
96     my $stdout;
97     my %results = ( shortsize   => 2 );
98     capture(
99         sub { auto::sizes::_set_int2($conf, \%results); },
100         \$stdout,
101     );
102     is($conf->data->get( 'int2_t' ), q{short},
103         "Got expected value for int2_t");
104     ok(! $stdout, "As expected, no warning needed");
108     my $stdout;
109     my %results = ( shortsize   => 4 );
110     capture(
111         sub { auto::sizes::_set_int2($conf, \%results); },
112         \$stdout,
113     );
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() ##########
123     my $stdout;
124     my %results = ( shortsize   => 4 );
125     capture(
126         sub { auto::sizes::_set_int4($conf, \%results); },
127         \$stdout,
128     );
129     is($conf->data->get( 'int4_t' ), q{short},
130         "Got expected value for int4_t");
131     ok(! $stdout, "As expected, no warning needed");
135     my $stdout;
136     my %results = ( intsize   => 4 );
137     capture(
138         sub { auto::sizes::_set_int4($conf, \%results); },
139         \$stdout,
140     );
141     is($conf->data->get( 'int4_t' ), q{int},
142         "Got expected value for int4_t");
143     ok(! $stdout, "As expected, no warning needed");
147     my $stdout;
148     my %results = ( longsize   => 4 );
149     capture(
150         sub { auto::sizes::_set_int4($conf, \%results); },
151         \$stdout,
152     );
153     is($conf->data->get( 'int4_t' ), q{long},
154         "Got expected value for int4_t");
155     ok(! $stdout, "As expected, no warning needed");
159     my $stdout;
160     my %results = ( );
161     capture(
162         sub { auto::sizes::_set_int4($conf, \%results); },
163         \$stdout,
164     );
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() ##########
174     my $stdout;
175     my %results = ( floatsize => 4 );
176     capture(
177         sub { auto::sizes::_set_float4($conf, \%results); },
178         \$stdout,
179     );
180     is($conf->data->get( 'float4_t' ), q{float},
181         "Got expected value for float4_t");
182     ok(! $stdout, "As expected, no warning needed");
186     my $stdout;
187     my %results = ( floatsize => 8 );
188     capture(
189         sub { auto::sizes::_set_float4($conf, \%results); },
190         \$stdout,
191     );
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() ##########
201     my $stdout;
202     my %results = ( doublesize => 8 );
203     capture(
204         sub { auto::sizes::_set_float8($conf, \%results); },
205         \$stdout,
206     );
207     is($conf->data->get( 'float8_t' ), q{double},
208         "Got expected value for float8_t");
209     ok(! $stdout, "As expected, no warning needed");
213     my $stdout;
214     my %results = ( );
215     capture(
216         sub { auto::sizes::_set_float8($conf, \%results); },
217         \$stdout,
218     );
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};
233 $intvalsize = 4;
234 auto::sizes::_handle_hugeintvalsize(
235     $conf,
236     {
237         hugeintval      => \%hugeintval,
238         intval          => $intval,
239         intvalsize      => $intvalsize,
240     },
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};
253 $intvalsize = 4;
254 auto::sizes::_handle_hugeintvalsize(
255     $conf,
256     {
257         hugeintval      => \%hugeintval,
258         intval          => $intval,
259         intvalsize      => $intvalsize,
260     },
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};
273 $intvalsize = 4;
274 auto::sizes::_handle_hugeintvalsize(
275     $conf,
276     {
277         hugeintval      => \%hugeintval,
278         intval          => $intval,
279         intvalsize      => $intvalsize,
280     },
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() ##########
294 my $size = 12;
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 ###################
311 =head1 NAME
313 auto_sizes-01.t - test auto::sizes
315 =head1 SYNOPSIS
317     % prove t/steps/auto_sizes-01.t
319 =head1 DESCRIPTION
321 The files in this directory test functionality used by F<Configure.pl>.
323 The tests in this file test auto::sizes.
325 =head1 AUTHOR
327 James E Keenan
329 =head1 SEE ALSO
331 config::auto::sizes, F<Configure.pl>.
333 =cut
335 # Local Variables:
336 #   mode: cperl
337 #   cperl-indent-level: 4
338 #   fill-column: 100
339 # End:
340 # vim: expandtab shiftwidth=4: