2 # Copyright (C) 2007, Parrot Foundation.
8 use Test::More tests => 58;
10 use lib qw( lib t/configure/testlib );
11 use_ok('config::auto::memalign');
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 ########### regular ###########
21 my ($args, $step_list_ref) = process_options(
28 my $conf = Parrot::Configure::Step::Test->new;
29 $conf->include_config_results( $args );
31 my $serialized = $conf->pcfreeze();
33 my $pkg = q{auto::memalign};
35 $conf->add_steps($pkg);
36 $conf->options->set( %{$args} );
37 my $step = test_step_constructor_and_description($conf);
38 $conf->data->set( memalign => 'memalign');
39 my $ret = $step->runstep($conf);
40 ok( $ret, "runstep() returned true value" );
41 is($step->result(), q{already set}, "Expected result was set");
42 is($conf->data->get('memalign'),
44 "memalign set as expected"
47 $conf->replenish($serialized);
49 ########### _set_malloc_header() ###########
51 ($args, $step_list_ref) = process_options(
58 $conf->add_steps($pkg);
59 $conf->options->set( %{$args} );
60 $step = test_step_constructor_and_description($conf);
62 $conf->data->set('i_malloc' => 1);
63 ok(auto::memalign::_set_malloc_header($conf),
64 "_set_malloc_header() returned true value");
65 is($conf->data->get( 'malloc_header' ), 'malloc.h',
66 "malloc_header has expected value");
67 $conf->data->set('i_malloc' => undef); # reset for next test
71 $conf->data->set('i_malloc' => 0);
72 ok(auto::memalign::_set_malloc_header($conf),
73 "_set_malloc_header() returned true value");
74 is($conf->data->get( 'malloc_header' ), 'stdlib.h',
75 "malloc_header has expected value");
76 $conf->data->set('i_malloc' => undef); # reset for next test
79 ########### _set_ptrcast() ###########
82 $conf->data->set('ptrsize' => 2);
83 $conf->data->set('intsize' => 2);
84 ok(auto::memalign::_set_ptrcast($conf),
85 "_set_ptrcast() returned true value");
86 is($conf->data->get( 'ptrcast' ), 'int',
87 "ptrcast has expected value");
89 $conf->data->set('ptrsize' => undef);
90 $conf->data->set('intsize' => undef);
94 $conf->data->set('ptrsize' => 2);
95 $conf->data->set('intsize' => 4);
96 ok(auto::memalign::_set_ptrcast($conf),
97 "_set_ptrcast() returned true value");
98 is($conf->data->get( 'ptrcast' ), 'long',
99 "ptrcast has expected value");
100 # reset for next test
101 $conf->data->set('ptrsize' => undef);
102 $conf->data->set('intsize' => undef);
105 ########### _set_memalign() ###########
108 $conf->data->set( malloc_header => 'malloc.h' );
109 ok($step->_set_memalign($conf, 1, 1),
110 "_set_memalign() returned true value");
111 ok(! defined $conf->data->get( 'malloc_header' ),
112 "malloc_header now undef as expected");
113 is($conf->data->get( 'memalign' ), 'posix_memalign',
114 "Got expected value for memalign");
115 is($step->result(), q{yes}, "Got expected result");
119 $conf->data->set( malloc_header => 'malloc.h' );
120 ok($step->_set_memalign($conf, 1, 0),
121 "_set_memalign() returned true value");
122 ok(! defined $conf->data->get( 'malloc_header' ),
123 "malloc_header now undef as expected");
124 is($conf->data->get( 'memalign' ), 'memalign',
125 "Got expected value for memalign");
126 is($step->result(), q{yes}, "Got expected result");
130 $conf->data->set( malloc_header => 'malloc.h' );
131 ok($step->_set_memalign($conf, 0, 1),
132 "_set_memalign() returned true value");
133 ok(! defined $conf->data->get( 'malloc_header' ),
134 "malloc_header now undef as expected");
135 is($conf->data->get( 'memalign' ), 'posix_memalign',
136 "Got expected value for memalign");
137 is($step->result(), q{no}, "Got expected result");
141 $conf->data->set( malloc_header => 'malloc.h' );
142 ok($step->_set_memalign($conf, 0, 0),
143 "_set_memalign() returned true value");
144 ok(! defined $conf->data->get( 'malloc_header' ),
145 "malloc_header now undef as expected");
146 is($conf->data->get( 'memalign' ), '',
147 "Got expected value (empty string) for memalign");
148 is($step->result(), q{no}, "Got expected result");
151 $conf->replenish($serialized);
153 ########### --verbose; _set_memalign() ###########
155 ($args, $step_list_ref) = process_options(
157 argv => [ q{--verbose} ],
158 mode => q{configure},
162 $conf->add_steps($pkg);
163 $conf->options->set( %{$args} );
164 $step = test_step_constructor_and_description($conf);
166 $conf->data->set( malloc_header => 'malloc.h' );
167 my ($rv, $stdout, $expected);
168 $expected = 'posix_memalign';
170 sub { $rv = $step->_set_memalign($conf, 1, 1); },
173 ok($rv, "_set_memalign() returned true value");
174 ok(! defined $conf->data->get( 'malloc_header' ),
175 "malloc_header now undef as expected");
176 is($conf->data->get( 'memalign' ), $expected,
177 "Got expected value for memalign");
178 is($step->result(), q{yes}, "Got expected result");
179 like($stdout, qr/Yep:$expected/,
180 "Got expected verbose output");
184 $conf->data->set( malloc_header => 'malloc.h' );
185 my ($rv, $stdout, $expected);
186 $expected = 'memalign';
188 sub { $rv = $step->_set_memalign($conf, 1, 0); },
191 ok($rv, "_set_memalign() returned true value");
192 ok(! defined $conf->data->get( 'malloc_header' ),
193 "malloc_header now undef as expected");
194 is($conf->data->get( 'memalign' ), $expected,
195 "Got expected value for memalign");
196 is($step->result(), q{yes}, "Got expected result");
197 like($stdout, qr/Yep:$expected/,
198 "Got expected verbose output");
202 $conf->data->set( malloc_header => 'malloc.h' );
203 my ($rv, $stdout, $expected);
204 $expected = 'posix_memalign';
206 sub { $rv = $step->_set_memalign($conf, 0, 1); },
209 ok($rv, "_set_memalign() returned true value");
210 ok(! defined $conf->data->get( 'malloc_header' ),
211 "malloc_header now undef as expected");
212 is($conf->data->get( 'memalign' ), $expected,
213 "Got expected value for memalign");
214 is($step->result(), q{no}, "Got expected result");
215 like($stdout, qr/no/,
216 "Got expected verbose output");
220 $conf->data->set( malloc_header => 'malloc.h' );
221 my ($rv, $stdout, $expected);
224 sub { $rv = $step->_set_memalign($conf, 0, 0); },
227 ok($rv, "_set_memalign() returned true value");
228 ok(! defined $conf->data->get( 'malloc_header' ),
229 "malloc_header now undef as expected");
230 is($conf->data->get( 'memalign' ), $expected,
231 "Got expected value (empty string) for memalign");
232 is($step->result(), q{no}, "Got expected result");
233 like($stdout, qr/no/,
234 "Got expected verbose output");
237 pass("Completed all tests in $0");
239 ################### DOCUMENTATION ###################
243 auto/memalign-01.t - test auto::memalign
247 % prove t/steps/auto/memalign-01.t
251 The files in this directory test functionality used by F<Configure.pl>.
253 The tests in this file test subroutines exported by
254 config::auto::memalign.
262 config::auto::memalign, F<Configure.pl>.
268 # cperl-indent-level: 4
271 # vim: expandtab shiftwidth=4: