Commit | Line | Data |
6b09c160 |
1 | #!/usr/bin/perl |
2 | |
6b09c160 |
3 | use strict; |
6986f47f |
4 | use Test::More; |
5 | use Config; |
da2b6f33 |
6 | use DynaLoader; |
6b09c160 |
7 | use ExtUtils::CBuilder; |
6986f47f |
8 | |
9 | plan tests => 10; |
10 | |
11 | my ($source_file, $obj_file, $lib_file); |
12 | |
13 | require_ok( 'ExtUtils::ParseXS' ); |
14 | ExtUtils::ParseXS->import('process_file'); |
6b09c160 |
15 | |
16 | chdir 't' or die "Can't chdir to t/, $!"; |
17 | |
18 | use Carp; $SIG{__WARN__} = \&Carp::cluck; |
19 | |
20 | ######################### |
21 | |
22 | # Try sending to filehandle |
23 | tie *FH, 'Foo'; |
24 | process_file( filename => 'XSTest.xs', output => \*FH, prototypes => 1 ); |
6986f47f |
25 | like 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 |
30 | process_file(filename => 'XSTest.xs', output => $source_file, prototypes => 0); |
6986f47f |
31 | ok -e $source_file, "Create an output file"; |
6b09c160 |
32 | |
6b09c160 |
33 | my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE}; |
6b09c160 |
34 | my $b = ExtUtils::CBuilder->new(quiet => $quiet); |
6b09c160 |
35 | |
6986f47f |
36 | SKIP: { |
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 |
41 | ok -e $obj_file, "Make sure $obj_file exists"; |
42 | } |
6b09c160 |
43 | |
6986f47f |
44 | SKIP: { |
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 |
51 | |
52 | eval {require XSTest}; |
6986f47f |
53 | is $@, ''; |
6b09c160 |
54 | ok XSTest::is_even(8); |
55 | ok !XSTest::is_even(9); |
56 | |
da2b6f33 |
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 |
67 | } |
68 | |
708f9ca6 |
69 | unless ($ENV{PERL_NO_CLEANUP}) { |
6986f47f |
70 | for ( $obj_file, $lib_file, $source_file) { |
71 | next unless defined $_; |
72 | 1 while unlink $_; |
73 | } |
708f9ca6 |
74 | } |
da2b6f33 |
75 | |
6b09c160 |
76 | ##################################################################### |
77 | |
78 | sub Foo::TIEHANDLE { bless {}, 'Foo' } |
79 | sub Foo::PRINT { shift->{buf} .= join '', @_ } |
80 | sub Foo::content { shift->{buf} } |