xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/MM_Unix.t (revision eac174f2741a08d8deb8aae59a7f778ef9b5d770)
1#!/usr/bin/perl -w
2
3BEGIN {
4    unshift @INC, 't/lib';
5}
6chdir 't';
7
8BEGIN {
9    use Test::More;
10
11    if( $^O =~ /^VMS|os2|MacOS|MSWin32|cygwin|beos|netware$/i ) {
12        plan skip_all => 'Non-Unix platform';
13    }
14    else {
15        plan tests => 114;
16    }
17}
18
19BEGIN { use_ok( 'ExtUtils::MM_Unix' ); }
20
21use strict;
22use warnings;
23use File::Spec;
24
25my $class = 'ExtUtils::MM_Unix';
26
27# only one of the following can be true
28# test should be removed if MM_Unix ever stops handling other OS than Unix
29my $os =  ($ExtUtils::MM_Unix::Is{OS2}   || 0)
30        + ($ExtUtils::MM_Unix::Is{Win32} || 0)
31        + ($ExtUtils::MM_Unix::Is{Dos}   || 0)
32        + ($ExtUtils::MM_Unix::Is{VMS}   || 0);
33cmp_ok ( $os, '<=', 1,  'There can be only one (or none)');
34
35is($ExtUtils::MM_Unix::VERSION, $ExtUtils::MakeMaker::VERSION, 'MM_Unix has a $VERSION');
36
37# when the following calls like canonpath, catdir etc are replaced by
38# File::Spec calls, the test's become a bit pointless
39
40foreach ( qw( xx/ ./xx/ xx/././xx xx///xx) ) {
41    is ($class->canonpath($_), File::Spec->canonpath($_), "canonpath $_");
42}
43
44is ($class->catdir('xx','xx'), File::Spec->catdir('xx','xx'),
45     'catdir(xx, xx) => xx/xx');
46is ($class->catfile('xx','xx','yy'), File::Spec->catfile('xx','xx','yy'),
47     'catfile(xx, xx) => xx/xx');
48
49is ($class->file_name_is_absolute('Bombdadil'),
50    File::Spec->file_name_is_absolute('Bombdadil'),
51     'file_name_is_absolute()');
52
53is ($class->path(), File::Spec->path(), 'path() same as File::Spec->path()');
54
55foreach (qw/updir curdir rootdir/)
56  {
57  is ($class->$_(), File::Spec->$_(), $_ );
58  }
59
60foreach ( qw /
61  c_o
62  clean
63  const_cccmd
64  const_config
65  const_loadlibs
66  constants
67  depend
68  dist
69  dist_basics
70  dist_ci
71  dist_core
72  distdir
73  dist_test
74  dlsyms
75  dynamic
76  dynamic_bs
77  dynamic_lib
78  exescan
79  extliblist
80  find_perl
81  fixin
82  force
83  guess_name
84  init_dirscan
85  init_main
86  init_others
87  install
88  installbin
89  linkext
90  lsdir
91  macro
92  makeaperl
93  makefile
94  manifypods
95  needs_linking
96  pasthru
97  perldepend
98  pm_to_blib
99  ppd
100  prefixify
101  processPL
102  realclean
103  static
104  static_lib
105  staticmake
106  subdir_x
107  subdirs
108  test
109  test_via_harness
110  test_via_script
111  tool_autosplit
112  tool_xsubpp
113  tools_other
114  top_targets
115  writedoc
116  xs_c
117  xs_cpp
118  xs_o
119  / )
120  {
121      can_ok($class, $_);
122  }
123
124###############################################################################
125# some more detailed tests for the methods above
126
127ok ( join (' ', $class->dist_basics()), 'distclean :: realclean distcheck');
128
129###############################################################################
130# has_link_code tests
131
132my $t = bless { NAME => "Foo" }, $class;
133$t->{HAS_LINK_CODE} = 1;
134is ($t->has_link_code(),1,'has_link_code'); is ($t->{HAS_LINK_CODE},1);
135
136$t->{HAS_LINK_CODE} = 0;
137is ($t->has_link_code(),0); is ($t->{HAS_LINK_CODE},0);
138
139delete $t->{HAS_LINK_CODE}; delete $t->{OBJECT};
140is ($t->has_link_code(),0); is ($t->{HAS_LINK_CODE},0);
141
142delete $t->{HAS_LINK_CODE}; $t->{OBJECT} = 1;
143is ($t->has_link_code(),1); is ($t->{HAS_LINK_CODE},1);
144
145delete $t->{HAS_LINK_CODE}; delete $t->{OBJECT}; $t->{MYEXTLIB} = 1;
146is ($t->has_link_code(),1); is ($t->{HAS_LINK_CODE},1);
147
148delete $t->{HAS_LINK_CODE}; delete $t->{MYEXTLIB}; $t->{C} = [ 'Gloin' ];
149is ($t->has_link_code(),1); is ($t->{HAS_LINK_CODE},1);
150
151###############################################################################
152# libscan
153
154{
155    # suppress noisy & unnecessary "WARNING: Older versions of ExtUtils::MakeMaker may errantly install README.pod..."
156    my @warnings = ();
157    local $SIG{__WARN__} = sub { push @warnings, shift; };
158    is ($t->libscan('Readme.pod'),      '', 'libscan excludes base Readme.pod');
159    is ($t->libscan('README.pod'),      '', 'libscan excludes base README.pod');
160    # verify that suppressed warnings are present
161    isnt (scalar(@warnings), 0);
162    if (scalar(@warnings)) {
163        note (sprintf('suppressed warnings: [ "%s" ]', do { my $s = join(q/" , "/, @warnings); $s =~ s/([^[:print:]])/sprintf('\x{%x}', ord($1))/egmsx; $s; }));
164    }
165}
166is ($t->libscan('lib/Foo/README.pod'),      'lib/Foo/README.pod', 'libscan accepts README.pod in a subdirectory');
167is ($t->libscan('foo/RCS/bar'),     '', 'libscan on RCS');
168is ($t->libscan('CVS/bar/car'),     '', 'libscan on CVS');
169is ($t->libscan('SCCS'),            '', 'libscan on SCCS');
170is ($t->libscan('.svn/something'),  '', 'libscan on Subversion');
171is ($t->libscan('foo/b~r'),         'foo/b~r',    'libscan on file with ~');
172is ($t->libscan('foo/RCS.pm'),      'foo/RCS.pm', 'libscan on file with RCS');
173
174is ($t->libscan('Fatty'), 'Fatty', 'libscan on something not a VC file' );
175
176###############################################################################
177# maybe_command
178
179open(FILE, ">command"); print FILE "foo"; close FILE;
180SKIP: {
181    skip("no separate execute mode on VOS", 2) if $^O eq "vos";
182
183    ok !$t->maybe_command('command') ,"non executable file isn't a command";
184
185    chmod 0755, "command";
186    ok ($t->maybe_command('command'),        "executable file is a command");
187}
188unlink "command";
189
190
191###############################################################################
192# perl_script (on unix any ordinary, readable file)
193
194my $self_name = 'MM_Unix.t';
195is ($t->perl_script($self_name),$self_name, 'we pass as a perl_script()');
196
197###############################################################################
198# PERM_RW and PERM_RWX
199
200$t->init_PERM;
201is ($t->{PERM_RW},'644', 'PERM_RW is 644');
202is ($t->{PERM_RWX},'755', 'PERM_RWX is 755');
203is ($t->{PERM_DIR},'755', 'PERM_DIR is 755');
204
205
206###############################################################################
207# post_constants, postamble, post_initialize
208
209foreach (qw/ post_constants postamble post_initialize/) {
210  is ($t->$_(),'', "$_() is an empty string");
211}
212
213###############################################################################
214# replace_manpage_separator
215
216is ($t->replace_manpage_separator('Foo/Bar'),'Foo::Bar','manpage_separator');
217
218###############################################################################
219
220$t->init_linker;
221foreach (qw/ EXPORT_LIST PERL_ARCHIVE PERL_ARCHIVE_AFTER /)
222{
223    ok( exists $t->{$_}, "$_ was defined" );
224    is( $t->{$_}, '', "$_ is empty on Unix");
225}
226
227
228{
229    $t->{CCFLAGS} = '-DMY_THING';
230    $t->{LIBPERL_A} = 'libperl.a';
231    $t->{LIB_EXT}   = '.a';
232    local $t->{NEEDS_LINKING} = 1;
233    $t->cflags();
234
235    # Brief bug where CCFLAGS was being blown away
236    like( $t->{CCFLAGS}, qr/\-DMY_THING/,    'cflags retains CCFLAGS' );
237}
238
239{
240    my @targv = ("var=don't forget about spaces and single quotes");
241    local @ARGV = @targv;
242    my $t = bless { NAME => "Foo", FULLPERL => $0, DIR => [] }, $class;
243    $t->makeaperl( TARGET => "Tgt" );
244    is_deeply( \@ARGV, \@targv, 'ARGV is not polluted by makeaperl' );
245}
246