This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
new perldelta
[perl5.git] / dist / ExtUtils-CBuilder / t / 00-have-compiler.t
... / ...
CommitLineData
1#! perl -w
2
3use File::Spec;
4my $perl;
5BEGIN {
6 $perl = File::Spec->rel2abs($^X);
7 $perl = qq{"$perl"}; # So it doesn't fail when there are spaces.
8}
9
10use strict;
11use Test::More;
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
20plan tests => 7;
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
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{
61my $b3 = ExtUtils::CBuilder->new(quiet => 1);
62configure_fake_present_compilers($b3);
63is( $b3->have_compiler, 1, "have_compiler: fake present cc" );
64}
65SKIP: {
66skip 'C++ test is broken on windows', 1 if $^O eq 'MSWin32';
67my $b4 = ExtUtils::CBuilder->new(quiet => 1);
68configure_fake_present_compilers($b4);
69is( $b4->have_cplusplus, 1, "have_cpp_compiler: fake present c++" );
70}
71
72# test missing cpp compiler
73
74# test one non-exported subroutine
75{
76 my $type = ExtUtils::CBuilder::os_type();
77 if ($type) {
78 pass( "OS type $type located for $^O" );
79 }
80 else {
81 pass( "OS type not yet listed for $^O" );
82 }
83}
84
85sub configure_fake_missing_compilers {
86 my $b = shift;
87 my $bogus_path = 'djaadjfkadjkfajdf';
88 $b->{config}{cc} = $bogus_path;
89 $b->{config}{ld} = $bogus_path;
90 $b->{have_cc} = undef;
91 $b->{have_cxx} = undef;
92}
93
94sub configure_fake_present_compilers {
95 my $b = shift;
96 my $run_perl = "$perl -e1 --";
97 $b->{config}{cc} = $run_perl;
98 $b->{config}{ld} = $run_perl;
99 $b->{config}{cxx} = $run_perl;
100 $b->{have_cc} = undef;
101 $b->{have_cxx} = undef;
102}