2 # Copyright (C) 2007, Parrot Foundation.
8 use Test::More tests => 83;
10 use lib qw( lib t/configure/testlib );
11 use_ok('config::auto::arch');
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 my ($args, $step_list_ref) = process_options( {
24 my $conf = Parrot::Configure::Step::Test->new;
25 $conf->include_config_results( $args );
27 my $serialized = $conf->pcfreeze();
29 my $pkg = q{auto::arch};
31 $conf->add_steps($pkg);
32 $conf->options->set( %{$args} );
33 my $step = test_step_constructor_and_description($conf);
34 my $ret = $step->runstep($conf);
35 ok( $ret, "runstep() returned true value" );
36 is($step->result(), q{}, "Result was empty string as expected");
38 $conf->replenish($serialized);
40 ########## --verbose ##########
42 ($args, $step_list_ref) = process_options( {
43 argv => [ q{--verbose} ],
47 $conf->add_steps($pkg);
48 $conf->options->set( %{$args} );
49 $step = test_step_constructor_and_description($conf);
53 sub { $ret = $step->runstep($conf); },
56 ok( $ret, "runstep() returned true value" );
57 is($step->result(), q{}, "Result was empty string as expected");
59 qr/determining operating system and cpu architecture/s,
60 "Got expected verbose output"
64 $conf->replenish($serialized);
66 ########## mock architecture ##########
68 ($args, $step_list_ref) = process_options( {
73 $conf->add_steps($pkg);
74 $conf->options->set( %{$args} );
75 $step = test_step_constructor_and_description($conf);
76 my $pseudoarch = q{foobar};
77 $conf->data->set('archname' => $pseudoarch);
78 $ret = $step->runstep($conf);
79 ok( $ret, "runstep() returned true value: $pseudoarch" );
80 is($step->result(), q{}, "Result was empty string as expected");
81 is($conf->data->get('cpuarch'), q{},
82 "'cpuarch' was set as expected");
83 is($conf->data->get('osname'), $pseudoarch,
84 "'osname' was set as expected");
86 $conf->replenish($serialized);
88 ########## mock darwin ##########
90 ($args, $step_list_ref) = process_options( {
95 $conf->add_steps($pkg);
96 $conf->options->set( %{$args} );
97 $step = test_step_constructor_and_description($conf);
98 $step->{unamep} = 'powerpc';
99 $pseudoarch = q{darwin-thread-multi-2level};
100 $conf->data->set('archname' => $pseudoarch);
101 $ret = $step->runstep($conf);
102 ok( $ret, "runstep() returned true value: $pseudoarch" );
103 is($step->result(), q{}, "Result was empty string as expected");
104 is($conf->data->get('cpuarch'), q{ppc},
105 "'cpuarch' was set as expected");
106 is($conf->data->get('osname'), q{darwin},
107 "'osname' was set as expected");
109 $conf->replenish($serialized);
111 ######### mock darwin ##########
113 ($args, $step_list_ref) = process_options( {
115 mode => q{configure},
118 $conf->add_steps($pkg);
119 $conf->options->set( %{$args} );
120 $step = test_step_constructor_and_description($conf);
121 $step->{unamep} = 'i386';
122 $pseudoarch = q{darwin-thread-multi-2level};
123 $conf->data->set('archname' => $pseudoarch);
124 $ret = $step->runstep($conf);
125 ok( $ret, "runstep() returned true value: $pseudoarch" );
126 is($step->result(), q{}, "Result was empty string as expected");
127 is($conf->data->get('cpuarch'), q{i386},
128 "'cpuarch' was set as expected");
129 is($conf->data->get('osname'), q{darwin},
130 "'osname' was set as expected");
132 $conf->replenish($serialized);
134 ########## mock win32 ##########
136 ($args, $step_list_ref) = process_options( {
138 mode => q{configure},
141 $conf->add_steps($pkg);
142 $conf->options->set( %{$args} );
143 $step = test_step_constructor_and_description($conf);
144 $pseudoarch = q{MSWin32-x64};
145 $conf->data->set('archname' => $pseudoarch);
146 $ret = $step->runstep($conf);
147 ok( $ret, "runstep() returned true value: $pseudoarch" );
148 is($step->result(), q{}, "Result was empty string as expected");
149 is($conf->data->get('cpuarch'), q{amd64},
150 "'cpuarch' was set as expected");
151 is($conf->data->get('osname'), q{MSWin32},
152 "'osname' was set as expected");
154 $conf->replenish($serialized);
156 ########## mock win32 ##########
158 ($args, $step_list_ref) = process_options( {
160 mode => q{configure},
163 $conf->add_steps($pkg);
164 $conf->options->set( %{$args} );
165 $step = test_step_constructor_and_description($conf);
166 $pseudoarch = q{MSWin32-i386};
167 $conf->data->set('archname' => $pseudoarch);
168 $ret = $step->runstep($conf);
169 ok( $ret, "runstep() returned true value: $pseudoarch" );
170 is($step->result(), q{}, "Result was empty string as expected");
171 is($conf->data->get('cpuarch'), q{i386},
172 "'cpuarch' was set as expected");
173 is($conf->data->get('osname'), q{MSWin32},
174 "'osname' was set as expected");
176 $conf->replenish($serialized);
178 ########## mock cygwin ##########
180 ($args, $step_list_ref) = process_options( {
182 mode => q{configure},
185 $conf->add_steps($pkg);
186 $conf->options->set( %{$args} );
187 $step = test_step_constructor_and_description($conf);
188 $pseudoarch = q{cygwin};
189 $conf->data->set('archname' => $pseudoarch);
190 $ret = $step->runstep($conf);
191 ok( $ret, "runstep() returned true value: $pseudoarch" );
192 is($step->result(), q{}, "Result was empty string as expected");
193 is($conf->data->get('cpuarch'), q{i386},
194 "'cpuarch' was set as expected");
195 is($conf->data->get('osname'), q{cygwin},
196 "'osname' was set as expected");
198 $conf->replenish($serialized);
200 ########## mock powerpc-linux ##########
202 ($args, $step_list_ref) = process_options( {
204 mode => q{configure},
207 $conf->add_steps($pkg);
208 $conf->options->set( %{$args} );
209 $step = test_step_constructor_and_description($conf);
210 $pseudoarch = q{powerpc-linux};
211 $conf->data->set('archname' => $pseudoarch);
212 $ret = $step->runstep($conf);
213 ok( $ret, "runstep() returned true value: $pseudoarch" );
214 is($step->result(), q{}, "Result was empty string as expected");
215 is($conf->data->get('cpuarch'), q{ppc},
216 "'cpuarch' was set as expected");
217 is($conf->data->get('osname'), q{linux},
218 "'osname' was set as expected");
220 $conf->replenish($serialized);
222 ########## mock cygwin-i486 ##########
224 ($args, $step_list_ref) = process_options( {
226 mode => q{configure},
229 $conf->add_steps($pkg);
230 $conf->options->set( %{$args} );
231 $step = test_step_constructor_and_description($conf);
232 $pseudoarch = q{cygwin-i486};
233 $conf->data->set('archname' => $pseudoarch);
234 $ret = $step->runstep($conf);
235 ok( $ret, "runstep() returned true value: $pseudoarch" );
236 is($step->result(), q{}, "Result was empty string as expected");
237 is($conf->data->get('cpuarch'), q{i386},
238 "'cpuarch' was set as expected");
239 is($conf->data->get('osname'), q{cygwin},
240 "'osname' was set as expected");
242 ########## mock solaris i86pc ##########
244 ($args, $step_list_ref) = process_options( {
246 mode => q{configure},
249 $conf->add_steps($pkg);
250 $conf->options->set( %{$args} );
251 $step = test_step_constructor_and_description($conf);
252 $pseudoarch = q{i86pc-solaris};
253 $conf->data->set('archname' => $pseudoarch);
254 $ret = $step->runstep($conf);
255 ok( $ret, "runstep() returned true value: $pseudoarch" );
256 is($step->result(), q{}, "Result was empty string as expected");
257 # Since on this architecture we call uname -p,
258 # we cannot test 'cpuarch' easily
259 #is($conf->data->get('cpuarch'), q{},
260 # "'cpuarch' was set as expected");
261 is($conf->data->get('osname'), q{solaris},
262 "'osname' was set as expected");
264 ########## _get_platform() ##########
268 $conf->data->set( osname => 'msys' );
269 $conf->data->set( archname => 'foo' );
271 is( $step->_get_platform( $conf ), $exp,
272 "Got expected platform for $exp");
274 $conf->data->set( osname => 'mingw' );
275 $conf->data->set( archname => 'foo' );
277 is( $step->_get_platform( $conf ), $exp,
278 "Got expected platform for $exp");
280 $conf->data->set( osname => 'MSWin32' );
281 $conf->data->set( archname => 'foo' );
283 is( $step->_get_platform( $conf ), $exp,
284 "Got expected platform for $exp");
286 $conf->data->set( archname => 'ia64-bar' );
288 is( $step->_get_platform( $conf ), $exp,
289 "Got expected platform for $exp");
291 $conf->data->set( archname => 'foo-bar' );
292 $conf->data->set( osname => 'bar' );
294 is( $step->_get_platform( $conf ), $exp,
295 "Got expected platform for $exp");
297 ########## _report_verbose() ##########
299 $conf->data->set( osname => 'foo' );
300 $conf->data->set( cpuarch => 'bar' );
301 $conf->data->set( platform => 'baz' );
302 $conf->options->set( verbose => 1 );
304 my ($stdout, $stderr);
306 sub { auto::arch::_report_verbose($conf); },
310 like( $stdout, qr/osname:\s+?foo/s,
311 "Got expected verbose output" );
312 like( $stdout, qr/cpuarch:\s+?bar/s,
313 "Got expected verbose output" );
314 like( $stdout, qr/platform:\s+?baz/s,
315 "Got expected verbose output" );
317 pass("Completed all tests in $0");
319 ################### DOCUMENTATION ###################
323 auto/arch-01.t - test auto::arch
327 % prove t/steps/auto/arch-01.t
331 The files in this directory test functionality used by F<Configure.pl>.
333 The tests in this file test auto::arch.
341 config::auto::arch, F<Configure.pl>.
347 # cperl-indent-level: 4
350 # vim: expandtab shiftwidth=4: