1#! perl -w 2 3use File::Spec; 4my $perl; 5BEGIN { 6 $perl = File::Spec->rel2abs($^X); 7} 8 9use strict; 10use Test::More; 11BEGIN { 12 if ($^O eq 'VMS') { 13 # So we can get the return value of system() 14 require vmsish; 15 import vmsish; 16 } 17} 18 19plan tests => 7; 20 21require_ok "ExtUtils::CBuilder"; 22 23my $b = eval { ExtUtils::CBuilder->new(quiet => 1) }; 24ok( $b, "got CBuilder object" ) or diag $@; 25 26# test missing compiler 27{ 28my $b1 = ExtUtils::CBuilder->new(quiet => 1); 29configure_fake_missing_compilers($b1); 30is( $b1->have_compiler, 0, "have_compiler: fake missing cc" ); 31} 32{ 33my $b2 = ExtUtils::CBuilder->new(quiet => 1); 34configure_fake_missing_compilers($b2); 35is( $b2->have_cplusplus, 0, "have_cplusplus: fake missing c++" ); 36} 37 38# test found compiler 39{ 40my $b3 = ExtUtils::CBuilder->new(quiet => 1); 41configure_fake_present_compilers($b3); 42is( $b3->have_compiler, 1, "have_compiler: fake present cc" ); 43} 44{ 45my $b4 = ExtUtils::CBuilder->new(quiet => 1); 46configure_fake_present_compilers($b4); 47is( $b4->have_cplusplus, 1, "have_cpp_compiler: fake present c++" ); 48} 49 50# test missing cpp compiler 51 52# test one non-exported subroutine 53{ 54 my $type = ExtUtils::CBuilder::os_type(); 55 if ($type) { 56 pass( "OS type $type located for $^O" ); 57 } 58 else { 59 pass( "OS type not yet listed for $^O" ); 60 } 61} 62 63sub configure_fake_missing_compilers { 64 my $b = shift; 65 my $bogus_path = 'djaadjfkadjkfajdf'; 66 $b->{config}{cc} = $bogus_path; 67 $b->{config}{ld} = $bogus_path; 68 $b->{have_cc} = undef; 69 $b->{have_cxx} = undef; 70} 71 72sub configure_fake_present_compilers { 73 my $b = shift; 74 my $run_perl = "$perl -e1 --"; 75 $b->{config}{cc} = $run_perl; 76 $b->{config}{ld} = $run_perl; 77 $b->{config}{cxx} = $run_perl; 78 $b->{have_cc} = undef; 79 $b->{have_cxx} = undef; 80} 81