1#!/usr/bin/perl 2 3use strict; 4use warnings; 5use Test::More; 6use Config; 7use DynaLoader; 8use ExtUtils::CBuilder; 9use attributes; 10use overload; 11 12plan tests => 29; 13 14my ($source_file, $obj_file, $lib_file); 15 16require_ok( 'ExtUtils::ParseXS' ); 17ExtUtils::ParseXS->import('process_file'); 18 19chdir 't' if -d 't'; 20 21use Carp; $SIG{__WARN__} = \&Carp::cluck; 22 23# See the comments about this in 001-basics.t 24@INC = map { File::Spec->rel2abs($_) } @INC 25 if $^O =~ /android/; 26 27######################### 28 29$source_file = 'XSMore.c'; 30 31# Try sending to file 32ExtUtils::ParseXS->process_file( 33 filename => 'XSMore.xs', 34 output => $source_file, 35); 36ok -e $source_file, "Create an output file"; 37 38my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE}; 39my $b = ExtUtils::CBuilder->new(quiet => $quiet); 40 41SKIP: { 42 skip "no compiler available", 2 43 if ! $b->have_compiler; 44 $obj_file = $b->compile( source => $source_file ); 45 ok $obj_file, "ExtUtils::CBuilder::compile() returned true value"; 46 ok -e $obj_file, "Make sure $obj_file exists"; 47} 48 49SKIP: { 50 skip "no dynamic loading", 25 51 if !$b->have_compiler || !$Config{usedl}; 52 my $module = 'XSMore'; 53 $lib_file = $b->link( objects => $obj_file, module_name => $module ); 54 ok $lib_file, "ExtUtils::CBuilder::link() returned true value"; 55 ok -e $lib_file, "Make sure $lib_file exists"; 56 57 eval{ 58 package XSMore; 59 our $VERSION = 42; 60 our $boot_ok; 61 DynaLoader::bootstrap_inherit(__PACKAGE__, $VERSION); # VERSIONCHECK disabled 62 63 sub new{ bless {}, shift } 64 }; 65 is $@, '', "No error message recorded, as expected"; 66 is ExtUtils::ParseXS::report_error_count(), 0, 'ExtUtils::ParseXS::errors()'; 67 68 is $XSMore::boot_ok, 100, 'the BOOT keyword'; 69 70 ok XSMore::include_ok(), 'the INCLUDE keyword'; 71 is prototype(\&XSMore::include_ok), "", 'the PROTOTYPES keyword'; 72 73 is prototype(\&XSMore::prototype_ssa), '$$@', 'the PROTOTYPE keyword'; 74 75 is_deeply [attributes::get(\&XSMore::attr_method)], [qw(method)], 'the ATTRS keyword'; 76 is prototype(\&XSMore::attr_method), '$;@', 'ATTRS with prototype'; 77 78 is XSMore::return_1(), 1, 'the CASE keyword (1)'; 79 is XSMore::return_2(), 2, 'the CASE keyword (2)'; 80 is prototype(\&XSMore::return_1), "", 'ALIAS with prototype (1)'; 81 is prototype(\&XSMore::return_2), "", 'ALIAS with prototype (2)'; 82 83 is XSMore::arg_init(200), 200, 'argument init'; 84 85 ok overload::Overloaded(XSMore->new), 'the FALLBACK keyword'; 86 is abs(XSMore->new), 42, 'the OVERLOAD keyword'; 87 88 my @a; 89 XSMore::hook(\@a); 90 is_deeply \@a, [qw(INIT CODE POSTCALL CLEANUP)], 'the INIT & POSTCALL & CLEANUP keywords'; 91 92 is_deeply [XSMore::outlist()], [ord('a'), ord('b')], 'the OUTLIST keyword'; 93 94 is XSMore::len("foo"), 3, 'the length keyword'; 95 96 is XSMore::sum(5, 9), 14, 'the INCLUDE_COMMAND directive'; 97 98 # Tests for embedded typemaps 99 is XSMore::typemaptest1(), 42, 'Simple embedded typemap works'; 100 is XSMore::typemaptest2(), 42, 'Simple embedded typemap works with funny end marker'; 101 is XSMore::typemaptest3(12, 13, 14), 12, 'Simple embedded typemap works for input, too'; 102 is XSMore::typemaptest6(5), 5, '<<END; (with semicolon) matches delimiter "END"'; 103 104 # Win32 needs to close the DLL before it can unlink it, but unfortunately 105 # dl_unload_file was missing on Win32 prior to perl change #24679! 106 if ($^O eq 'MSWin32' and defined &DynaLoader::dl_unload_file) { 107 for (my $i = 0; $i < @DynaLoader::dl_modules; $i++) { 108 if ($DynaLoader::dl_modules[$i] eq $module) { 109 DynaLoader::dl_unload_file($DynaLoader::dl_librefs[$i]); 110 last; 111 } 112 } 113 } 114} 115 116unless ($ENV{PERL_NO_CLEANUP}) { 117 for ( $obj_file, $lib_file, $source_file) { 118 next unless defined $_; 119 1 while unlink $_; 120 } 121} 122