1#!/usr/bin/perl -w
2
3BEGIN {
4    if( $ENV{PERL_CORE} ) {
5        chdir 't';
6        @INC = '../lib';
7    }
8    else {
9        unshift @INC, 't/lib';
10    }
11}
12chdir 't';
13
14BEGIN {
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 => 110;
22    }
23}
24
25BEGIN { use_ok( 'ExtUtils::MM_Unix' ); }
26
27use strict;
28use File::Spec;
29
30my $class = 'ExtUtils::MM_Unix';
31
32# only one of the following can be true
33# test should be removed if MM_Unix ever stops handling other OS than Unix
34my $os =  ($ExtUtils::MM_Unix::Is_OS2 	|| 0)
35	+ ($ExtUtils::MM_Unix::Is_Win32 || 0)
36	+ ($ExtUtils::MM_Unix::Is_Dos 	|| 0)
37	+ ($ExtUtils::MM_Unix::Is_VMS   || 0);
38ok ( $os <= 1,  'There can be only one (or none)');
39
40cmp_ok ($ExtUtils::MM_Unix::VERSION, '>=', '1.12606', 'Should be at least version 1.12606');
41
42# when the following calls like canonpath, catdir etc are replaced by
43# File::Spec calls, the test's become a bit pointless
44
45foreach ( qw( xx/ ./xx/ xx/././xx xx///xx) )
46  {
47  is ($class->canonpath($_), File::Spec->canonpath($_), "canonpath $_");
48  }
49
50is ($class->catdir('xx','xx'), File::Spec->catdir('xx','xx'),
51     'catdir(xx, xx) => xx/xx');
52is ($class->catfile('xx','xx','yy'), File::Spec->catfile('xx','xx','yy'),
53     'catfile(xx, xx) => xx/xx');
54
55is ($class->file_name_is_absolute('Bombdadil'),
56    File::Spec->file_name_is_absolute('Bombdadil'),
57     'file_name_is_absolute()');
58
59is ($class->path(), File::Spec->path(), 'path() same as File::Spec->path()');
60
61foreach (qw/updir curdir rootdir/)
62  {
63  is ($class->$_(), File::Spec->$_(), $_ );
64  }
65
66foreach ( qw /
67  c_o
68  clean
69  const_cccmd
70  const_config
71  const_loadlibs
72  constants
73  depend
74  dist
75  dist_basics
76  dist_ci
77  dist_core
78  distdir
79  dist_test
80  dlsyms
81  dynamic
82  dynamic_bs
83  dynamic_lib
84  exescan
85  extliblist
86  find_perl
87  fixin
88  force
89  guess_name
90  init_dirscan
91  init_main
92  init_others
93  install
94  installbin
95  linkext
96  lsdir
97  macro
98  makeaperl
99  makefile
100  manifypods
101  needs_linking
102  pasthru
103  perldepend
104  pm_to_blib
105  ppd
106  prefixify
107  processPL
108  quote_paren
109  realclean
110  static
111  static_lib
112  staticmake
113  subdir_x
114  subdirs
115  test
116  test_via_harness
117  test_via_script
118  tool_autosplit
119  tool_xsubpp
120  tools_other
121  top_targets
122  writedoc
123  xs_c
124  xs_cpp
125  xs_o
126  / )
127  {
128      can_ok($class, $_);
129  }
130
131###############################################################################
132# some more detailed tests for the methods above
133
134ok ( join (' ', $class->dist_basics()), 'distclean :: realclean distcheck');
135
136###############################################################################
137# has_link_code tests
138
139my $t = bless { NAME => "Foo" }, $class;
140$t->{HAS_LINK_CODE} = 1;
141is ($t->has_link_code(),1,'has_link_code'); is ($t->{HAS_LINK_CODE},1);
142
143$t->{HAS_LINK_CODE} = 0;
144is ($t->has_link_code(),0); is ($t->{HAS_LINK_CODE},0);
145
146delete $t->{HAS_LINK_CODE}; delete $t->{OBJECT};
147is ($t->has_link_code(),0); is ($t->{HAS_LINK_CODE},0);
148
149delete $t->{HAS_LINK_CODE}; $t->{OBJECT} = 1;
150is ($t->has_link_code(),1); is ($t->{HAS_LINK_CODE},1);
151
152delete $t->{HAS_LINK_CODE}; delete $t->{OBJECT}; $t->{MYEXTLIB} = 1;
153is ($t->has_link_code(),1); is ($t->{HAS_LINK_CODE},1);
154
155delete $t->{HAS_LINK_CODE}; delete $t->{MYEXTLIB}; $t->{C} = [ 'Gloin' ];
156is ($t->has_link_code(),1); is ($t->{HAS_LINK_CODE},1);
157
158###############################################################################
159# libscan
160
161is ($t->libscan('foo/RCS/bar'),     '', 'libscan on RCS');
162is ($t->libscan('CVS/bar/car'),     '', 'libscan on CVS');
163is ($t->libscan('SCCS'),            '', 'libscan on SCCS');
164is ($t->libscan('.svn/something'),  '', 'libscan on Subversion');
165is ($t->libscan('foo/b~r'),         'foo/b~r',    'libscan on file with ~');
166is ($t->libscan('foo/RCS.pm'),      'foo/RCS.pm', 'libscan on file with RCS');
167
168is ($t->libscan('Fatty'), 'Fatty', 'libscan on something not a VC file' );
169
170###############################################################################
171# maybe_command
172
173open(FILE, ">command"); print FILE "foo"; close FILE;
174ok (!$t->maybe_command('command') ,"non executable file isn't a command");
175chmod 0755, "command";
176ok ($t->maybe_command('command'),        "executable file is a command");
177unlink "command";
178
179###############################################################################
180# nicetext (dummy method)
181
182is ($t->nicetext('LOTR'),'LOTR','nicetext');
183
184
185###############################################################################
186# perl_script (on unix any ordinary, readable file)
187
188my $self_name = $ENV{PERL_CORE} ? '../lib/ExtUtils/t/MM_Unix.t'
189                                 : 'MM_Unix.t';
190is ($t->perl_script($self_name),$self_name, 'we pass as a perl_script()');
191
192###############################################################################
193# perm_rw perm_rwx
194
195$t->init_PERM;
196is ($t->perm_rw(),'644', 'perm_rw() is 644');
197is ($t->perm_rwx(),'755', 'perm_rwx() is 755');
198
199###############################################################################
200# post_constants, postamble, post_initialize
201
202foreach (qw/ post_constants postamble post_initialize/)
203  {
204  is ($t->$_(),'', "$_() is an empty string");
205  }
206
207###############################################################################
208# replace_manpage_separator
209
210is ($t->replace_manpage_separator('Foo/Bar'),'Foo::Bar','manpage_separator');
211
212###############################################################################
213
214$t->init_linker;
215foreach (qw/ EXPORT_LIST PERL_ARCHIVE PERL_ARCHIVE_AFTER /)
216{
217    ok( exists $t->{$_}, "$_ was defined" );
218    is( $t->{$_}, '', "$_ is empty on Unix");
219}
220
221
222{
223    $t->{CCFLAGS} = '-DMY_THING';
224    $t->{LIBPERL_A} = 'libperl.a';
225    $t->{LIB_EXT}   = '.a';
226    local $t->{NEEDS_LINKING} = 1;
227    $t->cflags();
228
229    # Brief bug where CCFLAGS was being blown away
230    is( $t->{CCFLAGS}, '-DMY_THING',    'cflags retains CCFLAGS' );
231}
232
233