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