Commit | Line | Data |
---|---|---|
6b09c160 YST |
1 | #!/usr/bin/perl |
2 | ||
6b09c160 | 3 | use strict; |
84ce4b0a | 4 | use Test::More tests => 11; |
6986f47f | 5 | use Config; |
da2b6f33 | 6 | use DynaLoader; |
6b09c160 | 7 | use ExtUtils::CBuilder; |
6986f47f | 8 | |
6986f47f DG |
9 | my ($source_file, $obj_file, $lib_file); |
10 | ||
11 | require_ok( 'ExtUtils::ParseXS' ); | |
12 | ExtUtils::ParseXS->import('process_file'); | |
6b09c160 YST |
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( filename => 'XSTest.xs', output => \*FH, prototypes => 1 ); | |
6986f47f | 23 | like tied(*FH)->content, '/is_even/', "Test that output contains some text"; |
6b09c160 | 24 | |
6986f47f | 25 | $source_file = 'XSTest.c'; |
da2b6f33 | 26 | |
6b09c160 | 27 | # Try sending to file |
da2b6f33 | 28 | process_file(filename => 'XSTest.xs', output => $source_file, prototypes => 0); |
6986f47f | 29 | ok -e $source_file, "Create an output file"; |
6b09c160 | 30 | |
6b09c160 | 31 | my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE}; |
6b09c160 | 32 | my $b = ExtUtils::CBuilder->new(quiet => $quiet); |
6b09c160 | 33 | |
6986f47f DG |
34 | SKIP: { |
35 | skip "no compiler available", 2 | |
36 | if ! $b->have_compiler; | |
37 | $obj_file = $b->compile( source => $source_file ); | |
84ce4b0a | 38 | ok $obj_file, "ExtUtils::CBuilder::compile() returned true value"; |
6986f47f DG |
39 | ok -e $obj_file, "Make sure $obj_file exists"; |
40 | } | |
6b09c160 | 41 | |
6986f47f DG |
42 | SKIP: { |
43 | skip "no dynamic loading", 5 | |
44 | if !$b->have_compiler || !$Config{usedl}; | |
45 | my $module = 'XSTest'; | |
46 | $lib_file = $b->link( objects => $obj_file, module_name => $module ); | |
84ce4b0a | 47 | ok $lib_file, "ExtUtils::CBuilder::link() returned true value"; |
6986f47f | 48 | ok -e $lib_file, "Make sure $lib_file exists"; |
6b09c160 YST |
49 | |
50 | eval {require XSTest}; | |
84ce4b0a JK |
51 | is $@, '', "No error message recorded, as expected"; |
52 | ok XSTest::is_even(8), | |
53 | "Function created thru XS returned expected true value"; | |
54 | ok !XSTest::is_even(9), | |
55 | "Function created thru XS returned expected false value"; | |
6b09c160 | 56 | |
da2b6f33 SH |
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 YST |
67 | } |
68 | ||
84ce4b0a JK |
69 | my $seen = 0; |
70 | open my $IN, '<', $source_file | |
71 | or die "Unable to open $source_file: $!"; | |
72 | while (my $l = <$IN>) { | |
73 | $seen++ if $l =~ m/#line\s1\s/; | |
74 | } | |
75 | close $IN or die "Unable to close $source_file: $!"; | |
76 | is( $seen, 1, "Linenumbers created in output file, as intended" ); | |
77 | ||
708f9ca6 | 78 | unless ($ENV{PERL_NO_CLEANUP}) { |
6986f47f DG |
79 | for ( $obj_file, $lib_file, $source_file) { |
80 | next unless defined $_; | |
81 | 1 while unlink $_; | |
82 | } | |
708f9ca6 | 83 | } |
da2b6f33 | 84 | |
6b09c160 YST |
85 | ##################################################################### |
86 | ||
87 | sub Foo::TIEHANDLE { bless {}, 'Foo' } | |
88 | sub Foo::PRINT { shift->{buf} .= join '', @_ } | |
89 | sub Foo::content { shift->{buf} } |