This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [PATCH] ExtUtils-{ParseXS,CBuilder} into bleadperl (was: Re: [Module::Build]...
[perl5.git] / lib / ExtUtils / ParseXS / t / basic.t
1 #!/usr/bin/perl
2
3 BEGIN {
4   if ($ENV{PERL_CORE}) {
5     chdir 't' if -d 't';
6     chdir '../lib/ExtUtils/ParseXS'
7       or die "Can't chdir to lib/ExtUtils/ParseXS: $!";
8     @INC = qw(../.. ../../.. .);
9   }
10 }
11 use strict;
12 use Test;
13 BEGIN { plan tests => 10 };
14 use ExtUtils::ParseXS qw(process_file);
15 use ExtUtils::CBuilder;
16 ok(1); # If we made it this far, we're loaded.
17
18 chdir 't' or die "Can't chdir to t/, $!";
19
20 use Carp; $SIG{__WARN__} = \&Carp::cluck;
21
22 #########################
23
24 # Try sending to filehandle
25 tie *FH, 'Foo';
26 process_file( filename => 'XSTest.xs', output => \*FH, prototypes => 1 );
27 ok tied(*FH)->content, '/is_even/', "Test that output contains some text";
28
29 # Try sending to file
30 process_file( filename => 'XSTest.xs', output => 'XSTest.c', prototypes => 0 );
31 ok -e 'XSTest.c', 1, "Create an output file";
32
33 # TEST doesn't like extraneous output
34 my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE};
35
36 # Try to compile the file!  Don't get too fancy, though.
37 my $b = ExtUtils::CBuilder->new(quiet => $quiet);
38 if ($b->have_compiler) {
39   my $module = 'XSTest';
40
41   my $obj_file = $b->compile( source => "$module.c" );
42   ok $obj_file;
43   ok -e $obj_file, 1, "Make sure $obj_file exists";
44
45   my $lib_file = $b->link( objects => $obj_file, module_name => $module );
46   ok $lib_file;
47   ok -e $lib_file, 1, "Make sure $lib_file exists";
48
49   eval {require XSTest};
50   ok $@, '';
51   ok  XSTest::is_even(8);
52   ok !XSTest::is_even(9);
53
54 } else {
55   skip "Skipped can't find a C compiler & linker", 1 for 1..6;
56 }
57
58 #####################################################################
59
60 sub Foo::TIEHANDLE { bless {}, 'Foo' }
61 sub Foo::PRINT { shift->{buf} .= join '', @_ }
62 sub Foo::content { shift->{buf} }