"Fossies" - the Fresh Open Source Software Archive

Member "perl-5.32.1/dist/ExtUtils-CBuilder/t/00-have-compiler.t" (18 Dec 2020, 2567 Bytes) of package /linux/misc/perl-5.32.1.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #! perl -w
    2 
    3 use File::Spec;
    4 my $perl;
    5 BEGIN {
    6   $perl = File::Spec->rel2abs($^X);
    7   $perl = qq{"$perl"}; # So it doesn't fail when there are spaces.
    8 }
    9 
   10 use strict;
   11 use Test::More;
   12 BEGIN { 
   13   if ($^O eq 'VMS') {
   14     # So we can get the return value of system()
   15     require vmsish;
   16     import vmsish;
   17   }
   18 }
   19 
   20 plan tests => 7;
   21 
   22 require_ok "ExtUtils::CBuilder";
   23 
   24 my $b = eval { ExtUtils::CBuilder->new(quiet => 1) };
   25 ok( $b, "got CBuilder object" ) or diag $@;
   26 
   27 # test missing compiler
   28 {
   29 
   30     my $b1 = ExtUtils::CBuilder->new(quiet => 1);
   31 
   32     configure_fake_missing_compilers($b1);
   33 
   34     # This will fork a child that will print
   35     #    'Can't exec "djaadjfkadjkfajdf"'
   36     # or similar on STDERR; so make sure fd2 is temporarily redirected to
   37     # oblivion before the fork
   38     open(OLDERR, ">&STDERR") or die "Can't dup STDERR: $!";
   39     open(STDERR, ">", File::Spec->devnull()) or die "Can't redirect STDERR: $!";
   40     my $res = $b1->have_compiler;
   41     open(STDERR, ">&OLDERR") or die "Can't restore STDERR: $!";
   42     close(OLDERR);
   43 
   44     is($res, 0, "have_compiler: fake missing cc" );
   45 }
   46 {
   47     my $b2 = ExtUtils::CBuilder->new(quiet => 1);
   48     configure_fake_missing_compilers($b2);
   49 
   50     open(OLDERR, ">&STDERR") or die "Can't dup STDERR: $!";
   51     open(STDERR, ">", File::Spec->devnull()) or die "Can't redirect STDERR: $!";
   52     my $res = $b2->have_cplusplus;
   53     open(STDERR, ">&OLDERR") or die "Can't restore STDERR: $!";
   54     close(OLDERR);
   55 
   56     is($res, 0, "have_cplusplus: fake missing c++" );
   57 }
   58 
   59 # test found compiler
   60 {
   61 my $b3 = ExtUtils::CBuilder->new(quiet => 1);
   62 configure_fake_present_compilers($b3);
   63 is( $b3->have_compiler, 1, "have_compiler: fake present cc" );
   64 }
   65 {
   66 my $b4 = ExtUtils::CBuilder->new(quiet => 1);
   67 configure_fake_present_compilers($b4);
   68 is( $b4->have_cplusplus, 1, "have_cpp_compiler: fake present c++" );
   69 }
   70 
   71 # test missing cpp compiler
   72 
   73 # test one non-exported subroutine
   74 {
   75     my $type = ExtUtils::CBuilder::os_type();
   76     if ($type) {
   77         pass( "OS type $type located for $^O" );
   78     }
   79     else {
   80         pass( "OS type not yet listed for $^O" );
   81     }
   82 }
   83 
   84 sub configure_fake_missing_compilers {
   85     my $b = shift;
   86     my $bogus_path = 'djaadjfkadjkfajdf';
   87     $b->{config}{cc} = $bogus_path;
   88     $b->{config}{ld} = $bogus_path;
   89     $b->{have_cc} = undef;
   90     $b->{have_cxx} = undef;
   91 }
   92 
   93 sub configure_fake_present_compilers {
   94     my $b = shift;
   95     my $run_perl = "$perl -e1 --";
   96     $b->{config}{cc} = $run_perl;
   97     $b->{config}{ld} = $run_perl;
   98     $b->{config}{cxx} = $run_perl;
   99     $b->{have_cc} = undef;
  100     $b->{have_cxx} = undef;
  101 }