This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move ExtUtils::ParseXS from cpan/ to dist/
[perl5.git] / dist / ExtUtils-ParseXS / t / basic.t
CommitLineData
6b09c160
YST
1#!/usr/bin/perl
2
6b09c160 3use strict;
6986f47f
DG
4use Test::More;
5use Config;
da2b6f33 6use DynaLoader;
6b09c160 7use ExtUtils::CBuilder;
6986f47f
DG
8
9plan tests => 10;
10
11my ($source_file, $obj_file, $lib_file);
12
13require_ok( 'ExtUtils::ParseXS' );
14ExtUtils::ParseXS->import('process_file');
6b09c160
YST
15
16chdir 't' or die "Can't chdir to t/, $!";
17
18use Carp; $SIG{__WARN__} = \&Carp::cluck;
19
20#########################
21
22# Try sending to filehandle
23tie *FH, 'Foo';
24process_file( filename => 'XSTest.xs', output => \*FH, prototypes => 1 );
6986f47f 25like tied(*FH)->content, '/is_even/', "Test that output contains some text";
6b09c160 26
6986f47f 27$source_file = 'XSTest.c';
da2b6f33 28
6b09c160 29# Try sending to file
da2b6f33 30process_file(filename => 'XSTest.xs', output => $source_file, prototypes => 0);
6986f47f 31ok -e $source_file, "Create an output file";
6b09c160 32
6b09c160 33my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE};
6b09c160 34my $b = ExtUtils::CBuilder->new(quiet => $quiet);
6b09c160 35
6986f47f
DG
36SKIP: {
37 skip "no compiler available", 2
38 if ! $b->have_compiler;
39 $obj_file = $b->compile( source => $source_file );
6b09c160 40 ok $obj_file;
6986f47f
DG
41 ok -e $obj_file, "Make sure $obj_file exists";
42}
6b09c160 43
6986f47f
DG
44SKIP: {
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 );
6b09c160 49 ok $lib_file;
6986f47f 50 ok -e $lib_file, "Make sure $lib_file exists";
6b09c160
YST
51
52 eval {require XSTest};
6986f47f 53 is $@, '';
6b09c160
YST
54 ok XSTest::is_even(8);
55 ok !XSTest::is_even(9);
56
da2b6f33
SH
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 }
6b09c160
YST
67}
68
708f9ca6 69unless ($ENV{PERL_NO_CLEANUP}) {
6986f47f
DG
70 for ( $obj_file, $lib_file, $source_file) {
71 next unless defined $_;
72 1 while unlink $_;
73 }
708f9ca6 74}
da2b6f33 75
6b09c160
YST
76#####################################################################
77
78sub Foo::TIEHANDLE { bless {}, 'Foo' }
79sub Foo::PRINT { shift->{buf} .= join '', @_ }
80sub Foo::content { shift->{buf} }