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