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 / 004-nolinenumbers.t
CommitLineData
84ce4b0a
JK
1#!/usr/bin/perl
2
3use strict;
4use Test::More tests => 11;
5use Config;
6use DynaLoader;
7use ExtUtils::CBuilder;
8
9my ($source_file, $obj_file, $lib_file);
10
11require_ok( 'ExtUtils::ParseXS' );
12ExtUtils::ParseXS->import('process_file');
13
14chdir 't' or die "Can't chdir to t/, $!";
15
16use Carp; $SIG{__WARN__} = \&Carp::cluck;
17
18#########################
19
20# Try sending to filehandle
21tie *FH, 'Foo';
22process_file(
23 filename => 'XSTest.xs',
24 output => \*FH,
25 prototypes => 1,
26 linenumbers => 0,
27);
28like tied(*FH)->content, '/is_even/', "Test that output contains some text";
29
30$source_file = 'XSTest.c';
31
32# Try sending to file
33process_file(
34 filename => 'XSTest.xs',
35 output => $source_file,
36 prototypes => 0,
37 linenumbers => 0,
38);
39ok -e $source_file, "Create an output file";
40
41my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE};
42my $b = ExtUtils::CBuilder->new(quiet => $quiet);
43
44SKIP: {
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
52SKIP: {
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
79my $seen = 0;
80open my $IN, '<', $source_file
81 or die "Unable to open $source_file: $!";
82while (my $l = <$IN>) {
83 $seen++ if $l =~ m/#line\s1\s/;
84}
85close $IN or die "Unable to close $source_file: $!";
86is( $seen, 0, "No linenumbers created in output file, as intended" );
87
88
89unless ($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
98sub Foo::TIEHANDLE { bless {}, 'Foo' }
99sub Foo::PRINT { shift->{buf} .= join '', @_ }
100sub Foo::content { shift->{buf} }