1#! perl 2# Copyright (C) 2008-2014, Parrot Foundation. 3 4use strict; 5use warnings; 6use Test::More tests => 23; 7use Carp; 8use lib qw( lib ); 9use_ok('config::auto::pcre'); 10use Parrot::Configure::Options qw( process_options ); 11use Parrot::Configure::Step::Test; 12use Parrot::Configure::Test qw( 13 test_step_constructor_and_description 14); 15use Parrot::Configure::Utils qw| capture |; 16 17########## --without-pcre ########## 18 19my ($args, $step_list_ref) = process_options( 20 { 21 argv => [ q{--without-pcre} ], 22 mode => q{configure}, 23 } 24); 25 26my $conf = Parrot::Configure::Step::Test->new; 27$conf->include_config_results( $args ); 28 29my $serialized = $conf->pcfreeze(); 30 31my $pkg = q{auto::pcre}; 32 33$conf->add_steps($pkg); 34$conf->options->set( %{$args} ); 35my $step = test_step_constructor_and_description($conf); 36ok( $step->runstep($conf), "runstep() returned true value"); 37is( $step->result(), 'skipped', "Got expected result" ); 38is( $conf->data->get( 'HAS_PCRE' ), 0, 39 "Got expected value for 'HAS_PCRE'"); 40 41$conf->replenish($serialized); 42 43########## _select_lib() ########## 44 45($args, $step_list_ref) = process_options( { 46 argv => [ ], 47 mode => q{configure}, 48} ); 49$conf->add_steps($pkg); 50$conf->options->set( %{$args} ); 51$step = test_step_constructor_and_description($conf); 52 53# Mock values for OS and C-compiler 54my ($osname, $cc, $initial_value); 55 56$osname = 'mswin32'; 57$cc = 'gcc'; 58$initial_value = $conf->data->get( 'libs' ); 59is($step->_select_lib( { 60 conf => $conf, 61 osname => $osname, 62 cc => $cc, 63 win32_nongcc => 'pcre.lib', 64 default => '-lpcre', 65} ), 66 '-lpcre', 67 "_select_lib() returned expected value"); 68 69$osname = 'mswin32'; 70$cc = 'cc'; 71$initial_value = $conf->data->get( 'libs' ); 72is($step->_select_lib( { 73 conf => $conf, 74 osname => $osname, 75 cc => $cc, 76 win32_nongcc => 'pcre.lib', 77 default => '-lpcre', 78} ), 79 'pcre.lib', 80 "_select_lib() returned expected value"); 81 82$osname = 'foobar'; 83$cc = 'gcc'; 84$initial_value = $conf->data->get( 'libs' ); 85is($step->_select_lib( { 86 conf => $conf, 87 osname => $osname, 88 cc => $cc, 89 win32_nongcc => 'pcre.lib', 90 default => '-lpcre', 91} ), 92 '-lpcre', 93 "_select_lib() returned expected value"); 94 95########## _evaluate_cc_run() ########## 96 97# Mock different outcomes of _evaluate_cc_run 98my ($test, $has_pcre); 99 100$test = q{pcre foobar}; 101ok(! $step->_evaluate_cc_run($conf, $test), 102 "Got expected setting for HAS_PCRE"); 103 104$test = q{pcre 4.1}; 105ok($step->_evaluate_cc_run($conf, $test), 106 "_evaluate_cc_run returned true value as expected"); 107is($step->result(), q{yes, 4.1}, "Got expected PCRE version"); 108 109$conf->replenish($serialized); 110 111########## --verbose; _evaluate_cc_run() ########## 112 113($args, $step_list_ref) = process_options( { 114 argv => [ q{--verbose} ], 115 mode => q{configure}, 116} ); 117$conf->add_steps($pkg); 118$conf->options->set( %{$args} ); 119$step = test_step_constructor_and_description($conf); 120 121# Mock different outcomes of _evaluate_cc_run 122 123$test = q{pcre 4.0}; 124{ 125 my ($stdout, $stderr); 126 capture( 127 sub { 128 $has_pcre = $step->_evaluate_cc_run($conf, $test); 129 }, 130 \$stdout, 131 ); 132 ok($has_pcre, "_evaluate_cc_run returned true value as expected"); 133 is($step->result(), q{yes, 4.0}, "Got expected PCRE version"); 134 like($stdout, qr/\(yes, 4\.0\)/, "Got expected verbose output"); 135} 136 137pass("Completed all tests in $0"); 138 139################### DOCUMENTATION ################### 140=encoding utf8 141 142=head1 NAME 143 144auto/pcre-01.t - test auto::pcre 145 146=head1 SYNOPSIS 147 148 % prove t/steps/auto/pcre-01.t 149 150=head1 DESCRIPTION 151 152The files in this directory test functionality used by F<Configure.pl>. 153 154The tests in this file test configuration step class auto::pcre. 155 156=head1 AUTHOR 157 158Alberto Simões 159 160=head1 SEE ALSO 161 162config::auto::pcre, F<Configure.pl>. 163 164=cut 165 166# Local Variables: 167# mode: cperl 168# cperl-indent-level: 4 169# fill-column: 100 170# End: 171# vim: expandtab shiftwidth=4: 172