1#!/usr/bin/perl 2 3use strict; 4use Test::More; 5use Config; 6use DynaLoader; 7use ExtUtils::CBuilder; 8 9if ( $] < 5.008 ) { 10 plan skip_all => "INTERFACE keyword support broken before 5.8"; 11} 12else { 13 plan tests => 24; 14} 15 16my ($source_file, $obj_file, $lib_file, $module); 17 18require_ok( 'ExtUtils::ParseXS' ); 19 20chdir('t') if -d 't'; 21 22use Carp; $SIG{__WARN__} = \&Carp::cluck; 23 24# See the comments about this in 001-basics.t 25@INC = map { File::Spec->rel2abs($_) } @INC 26 if $^O =~ /android/; 27 28######################### 29 30$source_file = 'XSUsage.c'; 31 32# Try sending to file 33ExtUtils::ParseXS->process_file(filename => 'XSUsage.xs', output => $source_file); 34ok -e $source_file, "Create an output file"; 35 36# TEST doesn't like extraneous output 37my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE}; 38 39# Try to compile the file! Don't get too fancy, though. 40my $b = ExtUtils::CBuilder->new(quiet => $quiet); 41 42SKIP: { 43 skip "no compiler available", 2 44 if ! $b->have_compiler; 45 $module = 'XSUsage'; 46 47 $obj_file = $b->compile( source => $source_file ); 48 ok $obj_file; 49 ok -e $obj_file, "Make sure $obj_file exists"; 50} 51SKIP: { 52 skip "no dynamic loading", 20 53 if !$b->have_compiler || !$Config{usedl}; 54 55 $lib_file = $b->link( objects => $obj_file, module_name => $module ); 56 ok $lib_file; 57 ok -e $lib_file, "Make sure $lib_file exists"; 58 59 eval {require XSUsage}; 60 is $@, ''; 61 62 # The real tests here - for each way of calling the functions, call with the 63 # wrong number of arguments and check the Usage line is what we expect 64 65 eval { XSUsage::one(1) }; 66 ok $@; 67 ok $@ =~ /^Usage: XSUsage::one/; 68 69 eval { XSUsage::two(1) }; 70 ok $@; 71 ok $@ =~ /^Usage: XSUsage::two/; 72 73 eval { XSUsage::two_x(1) }; 74 ok $@; 75 ok $@ =~ /^Usage: XSUsage::two_x/; 76 77 eval { FOO::two(1) }; 78 ok $@; 79 ok $@ =~ /^Usage: FOO::two/; 80 81 eval { XSUsage::three(1) }; 82 ok $@; 83 ok $@ =~ /^Usage: XSUsage::three/; 84 85 eval { XSUsage::four(1) }; 86 ok !$@; 87 88 eval { XSUsage::five() }; 89 ok $@; 90 ok $@ =~ /^Usage: XSUsage::five/; 91 92 eval { XSUsage::six() }; 93 ok !$@; 94 95 eval { XSUsage::six(1) }; 96 ok !$@; 97 98 eval { XSUsage::six(1,2) }; 99 ok $@; 100 ok $@ =~ /^Usage: XSUsage::six/; 101 102 # Win32 needs to close the DLL before it can unlink it, but unfortunately 103 # dl_unload_file was missing on Win32 prior to perl change #24679! 104 if ($^O eq 'MSWin32' and defined &DynaLoader::dl_unload_file) { 105 for (my $i = 0; $i < @DynaLoader::dl_modules; $i++) { 106 if ($DynaLoader::dl_modules[$i] eq $module) { 107 DynaLoader::dl_unload_file($DynaLoader::dl_librefs[$i]); 108 last; 109 } 110 } 111 } 112} 113 114unless ($ENV{PERL_NO_CLEANUP}) { 115 for ( $obj_file, $lib_file, $source_file) { 116 next unless defined $_; 117 1 while unlink $_; 118 } 119} 120 121