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