This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Import Encode-2.92 from CPAN
[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 closed before
37 # the fork
38 open(my $orig_err, ">&", \*STDERR) or die "Can't dup STDERR: $!";
39 close(STDERR);
40 my $res = $b1->have_compiler;
41 open(STDERR, ">&", $orig_err) or die "Can't dup \$orig_err $!";
42 close($orig_err);
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(my $orig_err, ">&", \*STDERR) or die "Can't dup STDERR: $!";
51 close(STDERR);
52 my $res = $b2->have_cplusplus;
53 open(STDERR, ">&", $orig_err) or die "Can't dup \$orig_err $!";
54 close($orig_err);
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}
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}
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
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}