2 # Copyright (C) 2007, The Perl Foundation.
8 use Test::More tests => 33;
10 use lib qw( lib t/configure/testlib );
11 use_ok('config::init::defaults');
12 use_ok('config::auto::pack');
13 use Parrot::BuildUtil;
14 use Parrot::Configure;
15 use Parrot::Configure::Options qw( process_options );
16 use Parrot::Configure::Test qw( test_step_thru_runstep);
17 use IO::CaptureOutput qw( capture );
19 my $args = process_options( {
24 my $conf = Parrot::Configure->new();
26 test_step_thru_runstep($conf, q{init::defaults}, $args);
28 my ($task, $step_name, $step, $ret);
29 my $pkg = q{auto::pack};
31 $conf->add_steps($pkg);
32 $conf->options->set(%{$args});
34 $task = $conf->steps->[-1];
35 $step_name = $task->step;
37 $step = $step_name->new();
38 ok(defined $step, "$step_name constructor returned defined value");
39 isa_ok($step, $step_name);
40 ok($step->description(), "$step_name has description");
42 my $longsize_orig = $conf->data->get_p5('longsize');
43 my $use64bitint_orig = $conf->data->get_p5('use64bitint');
45 ##### _set_format() #####
48 my $type = q{intvalsize};
51 $conf->data->set_p5( longsize => 8 );
52 my $format = auto::pack::_set_format( $conf, $type, $size, $longsize );
53 is( $format, q{l!}, "Got expected format size: $format" );
54 $conf->data->set_p5( longsize => $longsize_orig );
58 my $type = q{intvalsize};
61 $conf->data->set_p5( longsize => 8 );
62 my $format = auto::pack::_set_format( $conf, $type, $size, $longsize );
63 is( $format, q{l}, "Got expected format size: $format" );
64 $conf->data->set_p5( longsize => $longsize_orig );
68 my $type = q{intvalsize};
71 $conf->data->set_p5( longsize => 16 );
72 my $format = auto::pack::_set_format( $conf, $type, $size, $longsize );
73 is( $format, q{q}, "Got expected format size: $format" );
74 $conf->data->set_p5( longsize => $longsize_orig );
78 my $type = q{intvalsize};
81 $conf->data->set_p5( longsize => undef );
82 $conf->data->set_p5( use64bitint => 'define');
83 my $format = auto::pack::_set_format( $conf, $type, $size, $longsize );
84 is( $format, q{q}, "Got expected format size: $format" );
85 $conf->data->set_p5( longsize => $longsize_orig );
86 $conf->data->set_p5( use64bitint => $use64bitint_orig );
90 my ($stdout, $stderr);
91 my $type = q{intvalsize};
97 auto::pack::_set_format( $conf, $type, $size, $longsize ); },
101 ok( ! defined $format, "Format size undef, as expected");
103 qr/Configure\.pl: Unable to find a suitable packtype for $type/,
104 "Got expected warning re format size"
109 my ($stdout, $stderr);
110 my $type = q{intvalsize};
113 $conf->data->set_p5( longsize => 32 );
117 auto::pack::_set_format( $conf, $type, $size, $longsize ); },
121 ok( ! defined $format, "Format size undef, as expected");
123 qr/Configure\.pl: Unable to find a suitable packtype for $type/,
124 "Got expected warning re format size"
126 $conf->data->set_p5( longsize => $longsize_orig );
129 ##### _pack_test() #####
133 my $type = q{intvalsize};
136 my ($stdout, $stderr);
139 auto::pack::_pack_test( $format, $type, $size, $test ); },
144 qr/Configure\.pl: Unable to find a functional packtype for $type/,
145 "Got expected warning from _pack_test()"
151 my $type = q{intvalsize};
154 my ($stdout, $stderr, $ret);
156 sub { $ret = auto::pack::_pack_test( $format, $type, $size, $test ) },
160 is( $ret, $format, "Got expected format" );
161 ok(! $stderr, "Nothing on STDERR, as expected" );
166 my $type = q{intvalsize};
169 my ($stdout, $stderr, $ret);
171 sub { $ret = auto::pack::_pack_test( $format, $type, $size, $test ) },
176 qr/Configure\.pl: Unable to find a functional packtype for $type/,
177 "Got expected warning in _pack_test()."
183 my $type = q{intvalsize};
186 my ($stdout, $stderr, $ret);
188 sub { $ret = auto::pack::_pack_test( $format, $type, $size, $test ) },
192 is( $ret, q{?}, "Got expected format" );
193 ok(! $stderr, "Nothing on STDERR, as expected" );
196 ##### _set_packtypes() #####
199 my $current_numvalsize = $conf->data->get('numvalsize');
200 $conf->data->set( numvalsize => 12 );
201 auto::pack::_set_packtypes($conf);
202 is($conf->data->get('packtype_b'), 'C',
203 "Got expected value for packtype_b");
204 is($conf->data->get('packtype_n'), 'D',
205 "Got expected value for packtype_n");
207 # prepare for next test
208 $conf->data->set( numvalsize => $current_numvalsize );
209 $conf->data->set( packtype_b => undef );
210 $conf->data->set( packtype_n => undef );
214 my $current_numvalsize = $conf->data->get('numvalsize');
215 $conf->data->set( numvalsize => 72 );
216 auto::pack::_set_packtypes($conf);
217 is($conf->data->get('packtype_b'), 'C',
218 "Got expected value for packtype_b");
219 is($conf->data->get('packtype_n'), 'd',
220 "Got expected value for packtype_n");
222 # prepare for next test
223 $conf->data->set( numvalsize => $current_numvalsize );
224 $conf->data->set( packtype_b => undef );
225 $conf->data->set( packtype_n => undef );
228 ##### _set_ptrconst() #####
231 my ($ptrsize, $intsize, $longsize);
232 $ptrsize = $intsize = 2;
234 auto::pack::_set_ptrconst($conf, $ptrsize, $intsize, $longsize);
235 is($conf->data->get( 'ptrconst' ), "u",
236 "Got expected value for ptrconst" );
240 my ($ptrsize, $intsize, $longsize);
242 $ptrsize = $longsize = 4;
243 auto::pack::_set_ptrconst($conf, $ptrsize, $intsize, $longsize);
244 is($conf->data->get( 'ptrconst' ), "ul",
245 "Got expected value for ptrconst" );
246 $conf->data->set( 'ptrconst' => undef ); # prepare for next test
250 my ($ptrsize, $intsize, $longsize);
254 my ($stdout, $stderr);
256 sub { auto::pack::_set_ptrconst($conf, $ptrsize, $intsize, $longsize); },
260 ok(! defined $conf->data->get( 'ptrconst' ),
261 "ptrconst not set, as expected");
262 ok(! $stdout, "As expected, nothing on STDOUT");
263 like($stderr, qr/Unable to find an integer type/,
264 "Got expected warning");
265 $conf->data->set( 'ptrconst' => undef ); # prepare for next test
268 pass("Completed all tests in $0");
270 ################### DOCUMENTATION ###################
274 auto_pack-01.t - test config::auto::pack
278 % prove t/steps/auto_pack-01.t
282 The files in this directory test functionality used by F<Configure.pl>.
284 The tests in this file test auto::pack internal subroutines C<_set_packtypes()>
285 and C<_set_ptrcons()>.
293 config::auto::pack, F<Configure.pl>.
299 # cperl-indent-level: 4
302 # vim: expandtab shiftwidth=4: