This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In FreeBSD allow one to try using Perl's malloc with threads.
[perl5.git] / lib / ExtUtils / t / MM_Unix.t
CommitLineData
39234879 1#!/usr/bin/perl -w
c7a17d47
T
2
3BEGIN {
39234879 4 if( $ENV{PERL_CORE} ) {
64964e6d 5 chdir 't';
39234879
MS
6 @INC = '../lib';
7 }
f6d6199c
MS
8 else {
9 unshift @INC, 't/lib';
10 }
c7a17d47 11}
39234879 12chdir 't';
c7a17d47 13
87a750c3
JH
14BEGIN {
15 use Test::More;
16
85c35b1b 17 if( $^O =~ /^VMS|os2|MacOS|MSWin32|cygwin|beos|netware$/i ) {
87a750c3
JH
18 plan skip_all => 'Non-Unix platform';
19 }
20 else {
d6c6162f 21 plan tests => 117;
87a750c3
JH
22 }
23}
c7a17d47
T
24
25BEGIN { use_ok( 'ExtUtils::MM_Unix' ); }
26
57b1a898 27use vars qw($VERSION);
f2cc0c2f 28$VERSION = '0.02';
c7a17d47
T
29use strict;
30use File::Spec;
31
32my $class = 'ExtUtils::MM_Unix';
33
34# only one of the following can be true
35# test should be removed if MM_Unix ever stops handling other OS than Unix
36my $os = ($ExtUtils::MM_Unix::Is_OS2 || 0)
37 + ($ExtUtils::MM_Unix::Is_Mac || 0)
38 + ($ExtUtils::MM_Unix::Is_Win32 || 0)
39 + ($ExtUtils::MM_Unix::Is_Dos || 0)
40 + ($ExtUtils::MM_Unix::Is_VMS || 0);
41ok ( $os <= 1, 'There can be only one (or none)');
42
f2cc0c2f 43cmp_ok ($ExtUtils::MM_Unix::VERSION, '>=', '1.12606', 'Should be at least version 1.12606');
c7a17d47
T
44
45# when the following calls like canonpath, catdir etc are replaced by
46# File::Spec calls, the test's become a bit pointless
47
48foreach ( qw( xx/ ./xx/ xx/././xx xx///xx) )
49 {
50 is ($class->canonpath($_), File::Spec->canonpath($_), "canonpath $_");
51 }
52
53is ($class->catdir('xx','xx'), File::Spec->catdir('xx','xx'),
54 'catdir(xx, xx) => xx/xx');
55is ($class->catfile('xx','xx','yy'), File::Spec->catfile('xx','xx','yy'),
56 'catfile(xx, xx) => xx/xx');
57
f2cc0c2f
JH
58is ($class->file_name_is_absolute('Bombdadil'),
59 File::Spec->file_name_is_absolute('Bombdadil'),
60 'file_name_is_absolute()');
61
62is ($class->path(), File::Spec->path(), 'path() same as File::Spec->path()');
63
c7a17d47
T
64foreach (qw/updir curdir rootdir/)
65 {
66 is ($class->$_(), File::Spec->$_(), $_ );
67 }
68
69foreach ( qw /
70 c_o
71 clean
72 const_cccmd
73 const_config
74 const_loadlibs
75 constants
76 depend
77 dir_target
78 dist
79 dist_basics
80 dist_ci
81 dist_core
479d2113 82 distdir
c7a17d47
T
83 dist_test
84 dlsyms
85 dynamic
86 dynamic_bs
87 dynamic_lib
88 exescan
c7a17d47 89 extliblist
c7a17d47
T
90 find_perl
91 fixin
92 force
93 guess_name
c7a17d47
T
94 init_dirscan
95 init_main
96 init_others
97 install
98 installbin
c7a17d47
T
99 linkext
100 lsdir
101 macro
102 makeaperl
103 makefile
104 manifypods
c7a17d47 105 needs_linking
c7a17d47 106 pasthru
c7a17d47
T
107 perldepend
108 pm_to_blib
c7a17d47
T
109 ppd
110 prefixify
111 processPL
112 quote_paren
113 realclean
c7a17d47
T
114 static
115 static_lib
116 staticmake
117 subdir_x
118 subdirs
119 test
120 test_via_harness
121 test_via_script
122 tool_autosplit
123 tool_xsubpp
124 tools_other
125 top_targets
126 writedoc
127 xs_c
128 xs_cpp
129 xs_o
c7a17d47
T
130 / )
131 {
f6d6199c 132 can_ok($class, $_);
c7a17d47
T
133 }
134
f2cc0c2f
JH
135###############################################################################
136# some more detailed tests for the methods above
137
138ok ( join (' ', $class->dist_basics()), 'distclean :: realclean distcheck');
139
140###############################################################################
141# has_link_code tests
142
5c161494 143my $t = bless { NAME => "Foo" }, $class;
f2cc0c2f
JH
144$t->{HAS_LINK_CODE} = 1;
145is ($t->has_link_code(),1,'has_link_code'); is ($t->{HAS_LINK_CODE},1);
146
147$t->{HAS_LINK_CODE} = 0;
148is ($t->has_link_code(),0); is ($t->{HAS_LINK_CODE},0);
149
150delete $t->{HAS_LINK_CODE}; delete $t->{OBJECT};
151is ($t->has_link_code(),0); is ($t->{HAS_LINK_CODE},0);
152
153delete $t->{HAS_LINK_CODE}; $t->{OBJECT} = 1;
154is ($t->has_link_code(),1); is ($t->{HAS_LINK_CODE},1);
155
156delete $t->{HAS_LINK_CODE}; delete $t->{OBJECT}; $t->{MYEXTLIB} = 1;
157is ($t->has_link_code(),1); is ($t->{HAS_LINK_CODE},1);
158
159delete $t->{HAS_LINK_CODE}; delete $t->{MYEXTLIB}; $t->{C} = [ 'Gloin' ];
160is ($t->has_link_code(),1); is ($t->{HAS_LINK_CODE},1);
161
162###############################################################################
163# libscan
164
479d2113
MS
165is ($t->libscan('foo/RCS/bar'), '', 'libscan on RCS');
166is ($t->libscan('CVS/bar/car'), '', 'libscan on CVS');
167is ($t->libscan('SCCS'), '', 'libscan on SCCS');
168is ($t->libscan('.svn/something'), '', 'libscan on Subversion');
ad2f23df
JH
169is ($t->libscan('foo/b~r'), 'foo/b~r', 'libscan on file with ~');
170is ($t->libscan('foo/RCS.pm'), 'foo/RCS.pm', 'libscan on file with RCS');
479d2113
MS
171
172is ($t->libscan('Fatty'), 'Fatty', 'libscan on something not a VC file' );
f2cc0c2f
JH
173
174###############################################################################
175# maybe_command
176
177is ($t->maybe_command('blargel'),undef,"'blargel' isn't a command");
178
179###############################################################################
180# nicetext (dummy method)
181
182is ($t->nicetext('LOTR'),'LOTR','nicetext');
183
184###############################################################################
185# parse_version
186
39234879
MS
187my $self_name = $ENV{PERL_CORE} ? '../lib/ExtUtils/t/MM_Unix.t'
188 : 'MM_Unix.t';
f2cc0c2f 189
45bc4d3a
JH
190is( $t->parse_version($self_name), '0.02', 'parse_version on ourself');
191
192my %versions = (
193 '$VERSION = 0.0' => 0.0,
194 '$VERSION = -1.0' => -1.0,
195 '$VERSION = undef' => 'undef',
196 '$wibble = 1.0' => 'undef',
197 );
198
199while( my($code, $expect) = each %versions ) {
200 open(FILE, ">VERSION.tmp") || die $!;
201 print FILE "$code\n";
202 close FILE;
203
204 is( $t->parse_version('VERSION.tmp'), $expect, $code );
205
206 unlink "VERSION.tmp";
207}
208
f2cc0c2f
JH
209
210###############################################################################
211# perl_script (on unix any ordinary, readable file)
212
213is ($t->perl_script($self_name),$self_name, 'we pass as a perl_script()');
214
215###############################################################################
216# perm_rw perm_rwx
217
479d2113 218$t->init_PERM;
f2cc0c2f
JH
219is ($t->perm_rw(),'644', 'perm_rw() is 644');
220is ($t->perm_rwx(),'755', 'perm_rwx() is 755');
221
222###############################################################################
223# post_constants, postamble, post_initialize
224
225foreach (qw/ post_constants postamble post_initialize/)
226 {
227 is ($t->$_(),'', "$_() is an empty string");
228 }
229
230###############################################################################
231# replace_manpage_separator
232
233is ($t->replace_manpage_separator('Foo/Bar'),'Foo::Bar','manpage_separator');
234
235###############################################################################
f2cc0c2f 236
479d2113 237$t->init_linker;
a6ab0b5c 238foreach (qw/ EXPORT_LIST PERL_ARCHIVE PERL_ARCHIVE_AFTER LD /)
479d2113 239{
d6c6162f 240 use Config;
479d2113 241 ok( exists $t->{$_}, "$_ was defined" );
bfbb3190
JH
242 if ($_ eq 'LD' && defined $Config{ld}) {
243 like($t->{LD}, qr/^($Config{ld}|ld)$/,
244 "LD ($t->{LD}) is like in %Config ($t->{$_}) or 'ld'");
d6c6162f
JH
245 } else {
246 is($t->{$_}, '', "$_ is empty on Unix");
247 }
479d2113 248}
f2cc0c2f 249
c7a17d47 250
5c161494
MS
251{
252 $t->{CCFLAGS} = '-DMY_THING';
253 $t->{LIBPERL_A} = 'libperl.a';
254 $t->{LIB_EXT} = '.a';
255 local $t->{NEEDS_LINKING} = 1;
256 $t->cflags();
257
258 # Brief bug where CCFLAGS was being blown away
259 is( $t->{CCFLAGS}, '-DMY_THING', 'cflags retains CCFLAGS' );
260}
261