Commit | Line | Data |
---|---|---|
84ce4b0a JK |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use Test::More tests => 11; | |
5 | use Config; | |
6 | use DynaLoader; | |
7 | use ExtUtils::CBuilder; | |
8 | ||
9 | my ($source_file, $obj_file, $lib_file); | |
10 | ||
11 | require_ok( 'ExtUtils::ParseXS' ); | |
12 | ExtUtils::ParseXS->import('process_file'); | |
13 | ||
14 | chdir 't' or die "Can't chdir to t/, $!"; | |
15 | ||
16 | use Carp; $SIG{__WARN__} = \&Carp::cluck; | |
17 | ||
18 | ######################### | |
19 | ||
20 | # Try sending to filehandle | |
21 | tie *FH, 'Foo'; | |
22 | process_file( | |
23 | filename => 'XSTest.xs', | |
24 | output => \*FH, | |
25 | prototypes => 1, | |
26 | linenumbers => 0, | |
27 | ); | |
28 | like tied(*FH)->content, '/is_even/', "Test that output contains some text"; | |
29 | ||
30 | $source_file = 'XSTest.c'; | |
31 | ||
32 | # Try sending to file | |
33 | process_file( | |
34 | filename => 'XSTest.xs', | |
35 | output => $source_file, | |
36 | prototypes => 0, | |
37 | linenumbers => 0, | |
38 | ); | |
39 | ok -e $source_file, "Create an output file"; | |
40 | ||
41 | my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE}; | |
42 | my $b = ExtUtils::CBuilder->new(quiet => $quiet); | |
43 | ||
44 | SKIP: { | |
45 | skip "no compiler available", 2 | |
46 | if ! $b->have_compiler; | |
47 | $obj_file = $b->compile( source => $source_file ); | |
48 | ok $obj_file, "ExtUtils::CBuilder::compile() returned true value"; | |
49 | ok -e $obj_file, "Make sure $obj_file exists"; | |
50 | } | |
51 | ||
52 | SKIP: { | |
53 | skip "no dynamic loading", 5 | |
54 | if !$b->have_compiler || !$Config{usedl}; | |
55 | my $module = 'XSTest'; | |
56 | $lib_file = $b->link( objects => $obj_file, module_name => $module ); | |
57 | ok $lib_file, "ExtUtils::CBuilder::link() returned true value"; | |
58 | ok -e $lib_file, "Make sure $lib_file exists"; | |
59 | ||
60 | eval {require XSTest}; | |
61 | is $@, '', "No error message recorded, as expected"; | |
62 | ok XSTest::is_even(8), | |
63 | "Function created thru XS returned expected true value"; | |
64 | ok !XSTest::is_even(9), | |
65 | "Function created thru XS returned expected false value"; | |
66 | ||
67 | # Win32 needs to close the DLL before it can unlink it, but unfortunately | |
68 | # dl_unload_file was missing on Win32 prior to perl change #24679! | |
69 | if ($^O eq 'MSWin32' and defined &DynaLoader::dl_unload_file) { | |
70 | for (my $i = 0; $i < @DynaLoader::dl_modules; $i++) { | |
71 | if ($DynaLoader::dl_modules[$i] eq $module) { | |
72 | DynaLoader::dl_unload_file($DynaLoader::dl_librefs[$i]); | |
73 | last; | |
74 | } | |
75 | } | |
76 | } | |
77 | } | |
78 | ||
79 | my $seen = 0; | |
80 | open my $IN, '<', $source_file | |
81 | or die "Unable to open $source_file: $!"; | |
82 | while (my $l = <$IN>) { | |
83 | $seen++ if $l =~ m/#line\s1\s/; | |
84 | } | |
85 | close $IN or die "Unable to close $source_file: $!"; | |
86 | is( $seen, 0, "No linenumbers created in output file, as intended" ); | |
87 | ||
88 | ||
89 | unless ($ENV{PERL_NO_CLEANUP}) { | |
90 | for ( $obj_file, $lib_file, $source_file) { | |
91 | next unless defined $_; | |
92 | 1 while unlink $_; | |
93 | } | |
94 | } | |
95 | ||
96 | ##################################################################### | |
97 | ||
98 | sub Foo::TIEHANDLE { bless {}, 'Foo' } | |
99 | sub Foo::PRINT { shift->{buf} .= join '', @_ } | |
100 | sub Foo::content { shift->{buf} } |