This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix ExtUtils-CBuilder tests for Perl 5.6
[perl5.git] / dist / ExtUtils-CBuilder / t / 00-have-compiler.t
CommitLineData
9015f106
DG
1#! perl -w
2
9ef43512
DG
3use File::Spec;
4my $perl;
9015f106 5BEGIN {
9ef43512 6 $perl = File::Spec->rel2abs($^X);
74d5bfab 7 $perl = qq{"$perl"}; # So it doesn't fail when there are spaces.
9015f106
DG
8}
9
10use strict;
11use Test::More;
9015f106
DG
12BEGIN {
13 if ($^O eq 'VMS') {
14 # So we can get the return value of system()
15 require vmsish;
16 import vmsish;
17 }
18}
19
06e8058f 20plan tests => 7;
9015f106
DG
21
22require_ok "ExtUtils::CBuilder";
23
24my $b = eval { ExtUtils::CBuilder->new(quiet => 1) };
25ok( $b, "got CBuilder object" ) or diag $@;
26
27# test missing compiler
47ce55cb 28{
581ae9ba
DM
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 closed before
37 # the fork
89e2d2f3 38 open(OLDERR, ">&STDERR") or die "Can't dup STDERR: $!";
581ae9ba
DM
39 close(STDERR);
40 my $res = $b1->have_compiler;
89e2d2f3
Z
41 open(STDERR, ">&OLDERR") or die "Can't restore STDERR: $!";
42 close(OLDERR);
581ae9ba
DM
43
44 is($res, 0, "have_compiler: fake missing cc" );
47ce55cb
SH
45}
46{
581ae9ba
DM
47 my $b2 = ExtUtils::CBuilder->new(quiet => 1);
48 configure_fake_missing_compilers($b2);
49
89e2d2f3 50 open(OLDERR, ">&STDERR") or die "Can't dup STDERR: $!";
581ae9ba
DM
51 close(STDERR);
52 my $res = $b2->have_cplusplus;
89e2d2f3
Z
53 open(STDERR, ">&OLDERR") or die "Can't restore STDERR: $!";
54 close(OLDERR);
581ae9ba
DM
55
56 is($res, 0, "have_cplusplus: fake missing c++" );
47ce55cb 57}
9015f106
DG
58
59# test found compiler
47ce55cb
SH
60{
61my $b3 = ExtUtils::CBuilder->new(quiet => 1);
62configure_fake_present_compilers($b3);
63is( $b3->have_compiler, 1, "have_compiler: fake present cc" );
64}
65{
66my $b4 = ExtUtils::CBuilder->new(quiet => 1);
67configure_fake_present_compilers($b4);
68is( $b4->have_cplusplus, 1, "have_cpp_compiler: fake present c++" );
69}
9015f106 70
506098d4 71# test missing cpp compiler
06e8058f
CBW
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}
47ce55cb
SH
83
84sub 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
93sub 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}