Various buglets shaken out by -Mutf8.
[p5sagit/p5-mst-13.2.git] / t / lib / extutils.t
CommitLineData
af6c647e 1#!./perl -w
2
3print "1..8\n";
4
5BEGIN {
6 chdir 't' if -d 't';
7 @INC = '../lib';
8}
9
10use warnings;
11use strict;
12use ExtUtils::MakeMaker;
13use ExtUtils::Constant qw (constant_types C_constant XS_constant autoload);
14use Config;
15
16my $runperl = $^X;
94b1a389 17
af6c647e 18$| = 1;
19
20my $dir = "ext-$$";
94b1a389 21
22print "# $dir being created...\n";
23mkdir $dir, 0777 or die "mkdir: $!\n";
24
25use File::Spec::Functions;
af6c647e 26
27END {
94b1a389 28 use File::Path;
29 print "# $dir being removed...\n";
30 rmtree($dir);
af6c647e 31}
32
af6c647e 33my @names = ("THREE", {name=>"OK4", type=>"PV",},
34 {name=>"OK5", type=>"PVN",
35 value=>['"not ok 5\\n\\0ok 5\\n"', 15]},
36 {name => "FARTHING", type=>"NV"},
37 {name => "NOT_ZERO", type=>"UV", value=>~0 . "u"});
38
39my @names_only = map {(ref $_) ? $_->{name} : $_} @names;
40
41my $package = "ExtTest";
42################ Header
94b1a389 43my $header = catfile($dir, "test.h");
44open FH, ">$header" or die "open >$header: $!\n";
af6c647e 45print FH <<'EOT';
46#define THREE 3
47#define OK4 "ok 4\n"
48#define OK5 1
49#define FARTHING 0.25
50#define NOT_ZERO 1
51EOT
94b1a389 52close FH or die "close $header: $!\n";
af6c647e 53
54################ XS
94b1a389 55my $xs = catfile($dir, "$package.xs");
56open FH, ">$xs" or die "open >$xs: $!\n";
af6c647e 57
58print FH <<'EOT';
59#include "EXTERN.h"
60#include "perl.h"
61#include "XSUB.h"
62EOT
63
64print FH "#include \"test.h\"\n\n";
65print FH constant_types(); # macro defs
66my $types = {};
67foreach (C_constant (undef, "IV", $types, undef, undef, @names) ) {
68 print FH $_, "\n"; # C constant subs
69}
70print FH "MODULE = $package PACKAGE = $package\n";
71print FH "PROTOTYPES: ENABLE\n";
72print FH XS_constant ($package, $types); # XS for ExtTest::constant
94b1a389 73close FH or die "close $xs: $!\n";
af6c647e 74
75################ PM
94b1a389 76my $pm = catfile($dir, "$package.pm");
77open FH, ">$pm" or die "open >$pm: $!\n";
af6c647e 78print FH "package $package;\n";
79print FH "use $];\n";
80
81print FH <<'EOT';
82
83use strict;
84use warnings;
85use Carp;
86
87require Exporter;
88require DynaLoader;
89use AutoLoader;
90use vars qw ($VERSION @ISA @EXPORT_OK);
91
92$VERSION = '0.01';
93@ISA = qw(Exporter DynaLoader);
94@EXPORT_OK = qw(
95EOT
96
97print FH "\t$_\n" foreach (@names_only);
98print FH ");\n";
99print FH autoload ($package, $]);
100print FH "bootstrap $package \$VERSION;\n1;\n__END__\n";
94b1a389 101close FH or die "close $pm: $!\n";
af6c647e 102
103################ test.pl
94b1a389 104my $testpl = catfile($dir, "test.pl");
105open FH, ">$testpl" or die "open >$testpl: $!\n";
af6c647e 106
107print FH "use $package qw(@names_only);\n";
108print FH <<'EOT';
109
110my $three = THREE;
111if ($three == 3) {
112 print "ok 3\n";
113} else {
114 print "not ok 3 # $three\n";
115}
116
117print OK4;
118
119$_ = OK5;
120s/.*\0//s;
121print;
122
123my $farthing = FARTHING;
124if ($farthing == 0.25) {
125 print "ok 6\n";
126} else {
127 print "not ok 6 # $farthing\n";
128}
129
130my $not_zero = NOT_ZERO;
131if ($not_zero > 0 && $not_zero == ~0) {
132 print "ok 7\n";
133} else {
134 print "not ok 7 # \$not_zero=$not_zero ~0=" . (~0) . "\n";
135}
136
137
138EOT
139
94b1a389 140close FH or die "close $testpl: $!\n";
af6c647e 141
142################ dummy Makefile.PL
143# Keep the dependancy in the Makefile happy
94b1a389 144my $makefilePL = catfile($dir, "Makefile.PL");
145open FH, ">$makefilePL" or die "open >$makefilePL: $!\n";
146close FH or die "close $makefilePL: $!\n";
af6c647e 147
148chdir $dir or die $!; push @INC, '../../lib';
149END {chdir ".." or warn $!};
150
94b1a389 151# Grr. MakeMaker hardwired to write its message to STDOUT.
152print "# ";
af6c647e 153WriteMakefile(
154 'NAME' => $package,
155 'VERSION_FROM' => "$package.pm", # finds $VERSION
156 ($] >= 5.005 ?
157 (#ABSTRACT_FROM => "$package.pm", # XXX add this
158 AUTHOR => $0) : ())
159 );
160if (-f "Makefile") {
161 print "ok 1\n";
162} else {
163 print "not ok 1\n";
164}
165
166my $make = $Config{make};
94b1a389 167
af6c647e 168$make = $ENV{MAKE} if exists $ENV{MAKE};
94b1a389 169
170my $makeout;
171
af6c647e 172print "# make = '$make'\n";
94b1a389 173$makeout = `$make`;
174if ($?) {
175 print "not ok 2 # $make failed: $?\n";
176 exit($?);
af6c647e 177} else {
178 print "ok 2\n";
179}
180
181$make .= ' test';
94b1a389 182print "# make = '$make'\n";
183$makeout = `$make`;
184if ($?) {
185 print "not ok 8 # $make failed: $?\n";
af6c647e 186} else {
94b1a389 187 # Perl babblings
737e87b0 188 $makeout =~ s/^\s*PERL_DL_NONLAZY=.+?\n//m;
94b1a389 189
190 # GNU make babblings
191 $makeout =~ s/^\w*?make.+?(?:entering|leaving) directory.+?\n//mig;
192
193 print $makeout;
af6c647e 194 print "ok 8\n";
195}