Commit | Line | Data |
---|---|---|
28892255 DG |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
2ab6dc1b | 4 | use warnings; |
28892255 DG |
5 | use Test::More; |
6 | use Config; | |
7 | use DynaLoader; | |
8 | use ExtUtils::CBuilder; | |
9 | use attributes; | |
10 | use overload; | |
11 | ||
16c87200 | 12 | plan tests => 28; |
28892255 DG |
13 | |
14 | my ($source_file, $obj_file, $lib_file); | |
15 | ||
16 | require_ok( 'ExtUtils::ParseXS' ); | |
17 | ExtUtils::ParseXS->import('process_file'); | |
18 | ||
19 | chdir 't' or die "Can't chdir to t/, $!"; | |
20 | ||
21 | use Carp; $SIG{__WARN__} = \&Carp::cluck; | |
22 | ||
23 | ######################### | |
24 | ||
25 | $source_file = 'XSMore.c'; | |
26 | ||
27 | # Try sending to file | |
28 | ExtUtils::ParseXS->process_file( | |
29 | filename => 'XSMore.xs', | |
30 | output => $source_file, | |
31 | ); | |
32 | ok -e $source_file, "Create an output file"; | |
33 | ||
34 | my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE}; | |
35 | my $b = ExtUtils::CBuilder->new(quiet => $quiet); | |
36 | ||
37 | SKIP: { | |
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 | ||
45 | SKIP: { | |
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 | ||
111 | unless ($ENV{PERL_NO_CLEANUP}) { | |
112 | for ( $obj_file, $lib_file, $source_file) { | |
113 | next unless defined $_; | |
114 | 1 while unlink $_; | |
115 | } | |
116 | } |