This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PERL_SRC already has brackets on VMS.
[perl5.git] / ext / ExtUtils-ParseXS / t / basic.t
1 #!/usr/bin/perl
2
3 use strict;
4 use Test::More;
5 use Config;
6 use DynaLoader;
7 use ExtUtils::CBuilder;
8
9 plan tests => 10;
10
11 my ($source_file, $obj_file, $lib_file);
12
13 require_ok( 'ExtUtils::ParseXS' );
14 ExtUtils::ParseXS->import('process_file');
15
16 chdir 't' or die "Can't chdir to t/, $!";
17
18 use Carp; $SIG{__WARN__} = \&Carp::cluck;
19
20 #########################
21
22 # Try sending to filehandle
23 tie *FH, 'Foo';
24 process_file( filename => 'XSTest.xs', output => \*FH, prototypes => 1 );
25 like tied(*FH)->content, '/is_even/', "Test that output contains some text";
26
27 $source_file = 'XSTest.c';
28
29 # Try sending to file
30 process_file(filename => 'XSTest.xs', output => $source_file, prototypes => 0);
31 ok -e $source_file, "Create an output file";
32
33 my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE};
34 my $b = ExtUtils::CBuilder->new(quiet => $quiet);
35
36 SKIP: {
37   skip "no compiler available", 2
38     if ! $b->have_compiler;
39   $obj_file = $b->compile( source => $source_file );
40   ok $obj_file;
41   ok -e $obj_file, "Make sure $obj_file exists";
42 }
43
44 SKIP: {
45   skip "no dynamic loading", 5
46     if !$b->have_compiler || !$Config{usedl};
47   my $module = 'XSTest';
48   $lib_file = $b->link( objects => $obj_file, module_name => $module );
49   ok $lib_file;
50   ok -e $lib_file,  "Make sure $lib_file exists";
51
52   eval {require XSTest};
53   is $@, '';
54   ok  XSTest::is_even(8);
55   ok !XSTest::is_even(9);
56
57   # Win32 needs to close the DLL before it can unlink it, but unfortunately
58   # dl_unload_file was missing on Win32 prior to perl change #24679!
59   if ($^O eq 'MSWin32' and defined &DynaLoader::dl_unload_file) {
60     for (my $i = 0; $i < @DynaLoader::dl_modules; $i++) {
61       if ($DynaLoader::dl_modules[$i] eq $module) {
62         DynaLoader::dl_unload_file($DynaLoader::dl_librefs[$i]);
63         last;
64       }
65     }
66   }
67 }
68
69 unless ($ENV{PERL_NO_CLEANUP}) {
70   for ( $obj_file, $lib_file, $source_file) {
71     next unless defined $_;
72     1 while unlink $_;
73   }
74 }
75
76 #####################################################################
77
78 sub Foo::TIEHANDLE { bless {}, 'Foo' }
79 sub Foo::PRINT { shift->{buf} .= join '', @_ }
80 sub Foo::content { shift->{buf} }