ExtUtils::MakeMaker 6.10_08
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / MM_Unix.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     if( $ENV{PERL_CORE} ) {
5         chdir 't' if -d 't';
6         @INC = '../lib';
7     }
8     else {
9         unshift @INC, 't/lib';
10     }
11 }
12 chdir 't';
13
14 BEGIN { 
15     use Test::More; 
16
17     if( $^O =~ /^VMS|os2|MacOS|MSWin32|cygwin|beos|netware$/i ) {
18         plan skip_all => 'Non-Unix platform';
19     }
20     else {
21         plan tests => 116;
22     }
23 }
24
25 BEGIN { use_ok( 'ExtUtils::MM_Unix' ); }
26
27 use vars qw($VERSION);
28 $VERSION = '0.02';
29 use strict;
30 use File::Spec;
31
32 my $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
36 my $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); 
41 ok ( $os <= 1,  'There can be only one (or none)');
42
43 cmp_ok ($ExtUtils::MM_Unix::VERSION, '>=', '1.12606', 'Should be at least version 1.12606');
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
48 foreach ( qw( xx/ ./xx/ xx/././xx xx///xx) )
49   {
50   is ($class->canonpath($_), File::Spec->canonpath($_), "canonpath $_");
51   }
52
53 is ($class->catdir('xx','xx'), File::Spec->catdir('xx','xx'),
54      'catdir(xx, xx) => xx/xx');
55 is ($class->catfile('xx','xx','yy'), File::Spec->catfile('xx','xx','yy'),
56      'catfile(xx, xx) => xx/xx');
57
58 is ($class->file_name_is_absolute('Bombdadil'), 
59     File::Spec->file_name_is_absolute('Bombdadil'),
60      'file_name_is_absolute()');
61
62 is ($class->path(), File::Spec->path(), 'path() same as File::Spec->path()');
63
64 foreach (qw/updir curdir rootdir/)
65   {
66   is ($class->$_(), File::Spec->$_(), $_ );
67   }
68
69 foreach ( 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
82   distdir
83   dist_test
84   dlsyms
85   dynamic
86   dynamic_bs
87   dynamic_lib
88   exescan
89   extliblist
90   find_perl
91   fixin
92   force
93   guess_name
94   init_dirscan
95   init_main
96   init_others
97   install
98   installbin
99   linkext
100   lsdir
101   macro
102   makeaperl
103   makefile
104   manifypods
105   needs_linking
106   pasthru
107   perldepend
108   pm_to_blib
109   ppd
110   prefixify
111   processPL
112   quote_paren
113   realclean
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
130   xsubpp_version 
131   / )
132   {
133       can_ok($class, $_);
134   }
135
136 ###############################################################################
137 # some more detailed tests for the methods above
138
139 ok ( join (' ', $class->dist_basics()), 'distclean :: realclean distcheck');
140
141 ###############################################################################
142 # has_link_code tests
143
144 my $t = bless { NAME => "Foo" }, $class;
145 $t->{HAS_LINK_CODE} = 1; 
146 is ($t->has_link_code(),1,'has_link_code'); is ($t->{HAS_LINK_CODE},1);
147
148 $t->{HAS_LINK_CODE} = 0;
149 is ($t->has_link_code(),0); is ($t->{HAS_LINK_CODE},0);
150
151 delete $t->{HAS_LINK_CODE}; delete $t->{OBJECT};
152 is ($t->has_link_code(),0); is ($t->{HAS_LINK_CODE},0);
153
154 delete $t->{HAS_LINK_CODE}; $t->{OBJECT} = 1;
155 is ($t->has_link_code(),1); is ($t->{HAS_LINK_CODE},1);
156
157 delete $t->{HAS_LINK_CODE}; delete $t->{OBJECT}; $t->{MYEXTLIB} = 1;
158 is ($t->has_link_code(),1); is ($t->{HAS_LINK_CODE},1);
159
160 delete $t->{HAS_LINK_CODE}; delete $t->{MYEXTLIB}; $t->{C} = [ 'Gloin' ];
161 is ($t->has_link_code(),1); is ($t->{HAS_LINK_CODE},1);
162
163 ###############################################################################
164 # libscan
165
166 is ($t->libscan('foo/RCS/bar'),     '', 'libscan on RCS');
167 is ($t->libscan('CVS/bar/car'),     '', 'libscan on CVS');
168 is ($t->libscan('SCCS'),            '', 'libscan on SCCS');
169 is ($t->libscan('.svn/something'),  '', 'libscan on Subversion');
170 is ($t->libscan('foo/b~r'),         'foo/b~r',    'libscan on file with ~');
171 is ($t->libscan('foo/RCS.pm'),      'foo/RCS.pm', 'libscan on file with RCS');
172
173 is ($t->libscan('Fatty'), 'Fatty', 'libscan on something not a VC file' );
174
175 ###############################################################################
176 # maybe_command
177
178 is ($t->maybe_command('blargel'),undef,"'blargel' isn't a command");
179
180 ###############################################################################
181 # nicetext (dummy method)
182
183 is ($t->nicetext('LOTR'),'LOTR','nicetext');
184
185 ###############################################################################
186 # parse_version
187
188 my $self_name = $ENV{PERL_CORE} ? '../lib/ExtUtils/t/MM_Unix.t' 
189                                 : 'MM_Unix.t';
190
191 is( $t->parse_version($self_name), '0.02',  'parse_version on ourself');
192
193 my %versions = (
194                 '$VERSION = 0.0'    => 0.0,
195                 '$VERSION = -1.0'   => -1.0,
196                 '$VERSION = undef'  => 'undef',
197                 '$wibble  = 1.0'    => 'undef',
198                );
199
200 while( my($code, $expect) = each %versions ) {
201     open(FILE, ">VERSION.tmp") || die $!;
202     print FILE "$code\n";
203     close FILE;
204
205     is( $t->parse_version('VERSION.tmp'), $expect, $code );
206
207     unlink "VERSION.tmp";
208 }
209
210
211 ###############################################################################
212 # perl_script (on unix any ordinary, readable file)
213
214 is ($t->perl_script($self_name),$self_name, 'we pass as a perl_script()');
215
216 ###############################################################################
217 # perm_rw perm_rwx
218
219 $t->init_PERM;
220 is ($t->perm_rw(),'644', 'perm_rw() is 644');
221 is ($t->perm_rwx(),'755', 'perm_rwx() is 755');
222
223 ###############################################################################
224 # post_constants, postamble, post_initialize
225
226 foreach (qw/ post_constants postamble post_initialize/)
227   {
228   is ($t->$_(),'', "$_() is an empty string");
229   }
230
231 ###############################################################################
232 # replace_manpage_separator 
233
234 is ($t->replace_manpage_separator('Foo/Bar'),'Foo::Bar','manpage_separator'); 
235
236 ###############################################################################
237
238 $t->init_linker;
239 foreach (qw/ EXPORT_LIST PERL_ARCHIVE PERL_ARCHIVE_AFTER /)
240 {
241     ok( exists $t->{$_}, "$_ was defined" );
242     is( $t->{$_}, '', "$_ is empty on Unix"); 
243 }
244
245
246 {
247     $t->{CCFLAGS} = '-DMY_THING';
248     $t->{LIBPERL_A} = 'libperl.a';
249     $t->{LIB_EXT}   = '.a';
250     local $t->{NEEDS_LINKING} = 1;
251     $t->cflags();
252
253     # Brief bug where CCFLAGS was being blown away
254     is( $t->{CCFLAGS}, '-DMY_THING',    'cflags retains CCFLAGS' );
255 }
256