2 # Copyright (C) 2001-2007, Parrot Foundation.
8 use File::Temp qw( tempdir );
9 use Test::More tests => 69;
11 use lib qw( lib t/configure/testlib );
12 use_ok('config::init::defaults');
13 use_ok('config::inter::progs');
14 use_ok('config::auto::llvm');
15 use Parrot::Configure;
16 use Parrot::Configure::Options qw( process_options );
17 use Parrot::Configure::Test qw(
18 test_step_thru_runstep
19 rerun_defaults_for_testing
20 test_step_constructor_and_description
22 use IO::CaptureOutput qw( capture );
24 ########## regular ##########
26 my ($args, $step_list_ref) = process_options( {
31 my $conf = Parrot::Configure->new;
33 my $serialized = $conf->pcfreeze();
35 test_step_thru_runstep($conf, q{init::defaults}, $args);
36 test_step_thru_runstep($conf, q{inter::progs}, $args);
38 my $pkg = q{auto::llvm};
40 $conf->add_steps($pkg);
41 $conf->options->set( %{$args} );
42 my $step = test_step_constructor_and_description($conf);
43 my $ret = $step->runstep($conf);
44 ok( $ret, "runstep() returned true value" );
45 like( $step->result(), qr/yes|no/,
46 "Result was either 'yes' or 'no'" );
48 $conf->replenish($serialized);
50 ########## --verbose ##########
52 ($args, $step_list_ref) = process_options( {
53 argv => [ q{--verbose} ],
56 rerun_defaults_for_testing($conf, $args );
57 $conf->add_steps($pkg);
58 $conf->options->set( %{$args} );
59 $step = test_step_constructor_and_description($conf);
63 sub { $step->runstep($conf) },
66 ok( $ret, "runstep() returned true value" );
67 like( $step->result(), qr/yes|no/,
68 "Result was either 'yes' or 'no'" );
70 skip 'No sense testing for verbose output if LLVM not present',
71 2 unless ( $step->result() =~ /yes/ );
72 like( $stdout, qr/llvm-gcc/s,
73 "Got expected verbose output" );
74 like( $stdout, qr/Low Level Virtual Machine/s,
75 "Got expected verbose output" );
79 $step->set_result( undef );
80 $conf->data->set( 'has_llvm' => undef );
81 auto::llvm::_handle_result($step, $conf, 1);
82 is( $step->result(), 'yes', "Got expected 'yes' result" );
83 ok( $conf->data->get( 'has_llvm' ),
84 "'has_llvm' set to true value, as expected" );
86 $step->set_result( undef );
87 $conf->data->set( 'has_llvm' => undef );
88 auto::llvm::_handle_result($step, $conf, 0);
89 is( $step->result(), 'no', "Got expected 'no' result" );
90 ok( ! $conf->data->get( 'has_llvm' ),
91 "'has_llvm' set to false value, as expected" );
93 ##### _handle_component_version_output() #####
95 my ($prog, $output, $llvm_lacking, $verbose);
96 $prog = [ 'llvm-gcc' => 'llvm-gcc' ];
100 $output = 'llvm-gcc';
102 $llvm_lacking = auto::llvm::_handle_component_version_output(
103 $prog, $output, $llvm_lacking, $verbose
105 ok( ! $llvm_lacking, "llvm reported as not lacking" );
109 $llvm_lacking = auto::llvm::_handle_component_version_output(
110 $prog, $output, $llvm_lacking, $verbose
112 ok( $llvm_lacking, "llvm reported as lacking: wrong output" );
116 $llvm_lacking = auto::llvm::_handle_component_version_output(
117 $prog, $output, $llvm_lacking, $verbose
119 ok( $llvm_lacking, "llvm reported as lacking: output undefined" );
123 my ($stdout, $stderr);
124 my $exp = $prog->[0];
126 $output = 'llvm-gcc';
130 $llvm_lacking = auto::llvm::_handle_component_version_output(
131 $prog, $output, $llvm_lacking, $verbose
137 ok( ! $llvm_lacking, "llvm reported as not lacking" );
138 like( $stdout, qr/$output/, "Got expected verbose output: llvm not lacking" );
144 $llvm_lacking = auto::llvm::_handle_component_version_output(
145 $prog, $output, $llvm_lacking, $verbose
151 ok( $llvm_lacking, "llvm reported as lacking: wrong output" );
154 qr/Could not get expected '--version' output for $exp/,
155 "Got expected verbose output: llvm lacking",
162 $llvm_lacking = auto::llvm::_handle_component_version_output(
163 $prog, $output, $llvm_lacking, $verbose
169 ok( $llvm_lacking, "llvm reported as lacking: output undefined" );
172 qr/Could not get expected '--version' output for $exp/,
173 "Got expected verbose output: llvm lacking",
176 ##### _examine_llvm_gcc_version() #####
182 auto::llvm::_examine_llvm_gcc_version( $output, $llvm_lacking, $verbose );
183 ok( $llvm_lacking, "_examine_llvm_gcc_version() reported LLVM lacking" );
189 auto::llvm::_examine_llvm_gcc_version( $output, $llvm_lacking, $verbose );
190 ok( $llvm_lacking, "_examine_llvm_gcc_version() reported LLVM lacking" );
196 auto::llvm::_examine_llvm_gcc_version( $output, $llvm_lacking, $verbose );
197 ok( $llvm_lacking, "_examine_llvm_gcc_version() reported LLVM lacking" );
203 auto::llvm::_examine_llvm_gcc_version( $output, $llvm_lacking, $verbose );
204 ok( ! $llvm_lacking, "_examine_llvm_gcc_version() reported LLVM not lacking" );
210 sub { $llvm_lacking = auto::llvm::_examine_llvm_gcc_version(
211 $output, $llvm_lacking, $verbose ); },
215 ok( $llvm_lacking, "_examine_llvm_gcc_version() reported LLVM lacking" );
218 qr/Unable to extract llvm-gcc major, minor and patch versions/,
219 "Got expected verbose output from _examine_llvm_gcc_version()",
226 sub { $llvm_lacking = auto::llvm::_examine_llvm_gcc_version(
227 $output, $llvm_lacking, $verbose ); },
231 ok( $llvm_lacking, "_examine_llvm_gcc_version() reported LLVM lacking" );
234 qr/llvm-gcc must be at least major version 4/,
235 "Got expected verbose output from _examine_llvm_gcc_version()",
238 ##### 4 methods #####
241 $step->set_result( undef );
242 $step->_handle_failure_to_compile_into_bitcode( $conf, $verbose );
243 is( $step->result(), 'no', "Got expected result" );
245 $step->set_result( undef );
246 $step->_handle_failure_to_execute_bitcode( $conf, $verbose );
247 is( $step->result(), 'no', "Got expected result" );
249 $step->set_result( undef );
250 $step->_handle_failure_to_compile_to_assembly( $conf, $verbose );
251 is( $step->result(), 'no', "Got expected result" );
253 $step->set_result( undef );
254 $step->_handle_failure_to_assemble_assembly( $conf, $verbose );
255 is( $step->result(), 'no', "Got expected result" );
259 sub { $step->_handle_failure_to_compile_into_bitcode( $conf, $verbose ); },
264 qr/Unable to compile C file into LLVM bitcode file/,
265 "Got expected verbose output from _handle_failure_to_compile_into_bitcode()",
269 sub { $step->_handle_failure_to_execute_bitcode( $conf, $verbose ); },
274 qr/Unable to run LLVM bitcode file with 'lli'/,
275 "Got expected verbose output from _handle_failure_to_execute_bitcode()",
279 sub { $step->_handle_failure_to_compile_to_assembly( $conf, $verbose ); },
284 qr/Unable to compile program to native assembly using 'llc'/,
285 "Got expected verbose output from _handle_failure_to_compile_to_assembly()",
289 sub { $step->_handle_failure_to_assemble_assembly( $conf, $verbose ); },
294 qr/Unable to assemble native assembly into program/,
295 "Got expected verbose output from _handle_failure_to_assemble_assembly()",
298 ##### _handle_native_assembly_output() #####
302 $output = 'hello world';
304 ok( $step->_handle_native_assembly_output( $conf, $output, $verbose ),
305 "_handle_native_assembly_output() returned true value" );
306 is( $step->result(), 'yes', "Got expected 'yes' result" );
311 $output = 'hello world';
313 ok( $step->_handle_native_assembly_output( $conf, $output, $verbose ),
314 "_handle_native_assembly_output() returned true value" );
315 is( $step->result(), 'no', "Got expected 'no' result" );
320 $output = 'goodbye, cruel world';
322 ok( $step->_handle_native_assembly_output( $conf, $output, $verbose ),
323 "_handle_native_assembly_output() returned true value" );
324 is( $step->result(), 'no', "Got expected 'no' result" );
329 $output = 'hello world';
332 sub { $step->_handle_native_assembly_output(
333 $conf, $output, $verbose); },
337 is( $step->result(), 'no', "Got expected 'no' result" );
340 qr/Unable to execute native assembly program successfully/,
341 "Got expected verbose output: native assembly program",
347 $output = 'goodbye, cruel world';
350 sub { $step->_handle_native_assembly_output(
351 $conf, $output, $verbose); },
355 is( $step->result(), 'no', "Got expected 'no' result" );
358 qr/Unable to execute native assembly program successfully/,
359 "Got expected verbose output: native assembly program",
363 ##### _cleanup_llvm_files() #####
365 my ( $bcfile, $sfile, $nativefile );
369 auto::llvm::_cleanup_llvm_files( $bcfile, $sfile, $nativefile );
370 is( $count_unlinked, 0, "no files existed, hence none unlinked" );
372 ( $bcfile, $sfile, $nativefile ) = ( '', '', '' );
374 auto::llvm::_cleanup_llvm_files( $bcfile, $sfile, $nativefile );
375 is( $count_unlinked, 0, "no files existed, hence none unlinked" );
378 my $tdir = tempdir( CLEANUP => 1 );
379 $bcfile = qq|$tdir/bcfile|;
380 open my $FH, '>', $bcfile
381 or die "Unable to open handle for writing: $!";
382 print $FH qq|bcfile hello world\n|;
383 close $FH or die "Unable to close handle after writing: $!";
385 auto::llvm::_cleanup_llvm_files( $bcfile, $sfile, $nativefile );
386 is( $count_unlinked, 1, "one file existed, hence one unlinked" );
391 pass("Completed all tests in $0");
393 ################### DOCUMENTATION ###################
397 t/steps/auto/llvm-01.t - tests Parrot::Configure step auto::llvm
401 prove t/steps/auto/llvm-01.t
405 This file holds tests for auto::llvm.
415 # cperl-indent-level: 4
418 # vim: expandtab shiftwidth=4: