14 plan( skip_all => "This does not appear to be OS/2" );
17 # for dlsyms, overridden in tests
19 package ExtUtils::MM_OS2;
20 use subs 'system', 'unlink';
26 use_ok( 'ExtUtils::MM_OS2' );
27 ok( grep( 'ExtUtils::MM_OS2', @MM::ISA),
28 'ExtUtils::MM_OS2 should be parent of MM' );
36 }, 'ExtUtils::MM_OS2');
38 is( $mm->dlsyms(), '',
39 'dlsyms() should return nothing with dynamic flag set' );
41 $mm->{BASEEXT} = 'baseext';
42 delete $mm->{SKIPHASH};
43 my $res = $mm->dlsyms();
44 like( $res, qr/baseext\.def: Makefile/,
45 '... without flag, should return make targets' );
46 like( $res, qr/"DL_FUNCS" => { }/,
47 '... should provide empty hash refs where necessary' );
48 like( $res, qr/"DL_VARS" => \[]/, '... and empty array refs too' );
50 $mm->{FUNCLIST} = 'funclist';
51 $res = $mm->dlsyms( IMPORTS => 'imports' );
52 like( $res, qr/"FUNCLIST" => .+funclist/,
53 '... should pick up values from object' );
54 like( $res, qr/"IMPORTS" => .+imports/, '... and allow parameter options too' );
59 $can_write = open(OUT, '>tmp_imp');
63 skip("Cannot write test files: $!", 7) unless $can_write;
65 $mm->{IMPORTS} = { foo => 'bar' };
68 eval { $mm->dlsyms() };
69 like( $@, qr/Can.t mkdir tmp_imp/,
70 '... should die if directory cannot be made' );
72 unlink('tmp_imp') or skip("Cannot remove test file: $!", 9);
73 eval { $mm->dlsyms() };
74 like( $@, qr/Malformed IMPORT/, 'should die from malformed import symbols');
76 $mm->{IMPORTS} = { foo => 'bar.baz' };
78 my @sysfail = ( 1, 0, 1 );
79 my ($sysargs, $unlinked);
81 *ExtUtils::MM_OS2::system = sub {
83 return shift @sysfail;
86 *ExtUtils::MM_OS2::unlink = sub {
90 eval { $mm->dlsyms() };
92 like( $sysargs, qr/^emximp/, '... should try to call system() though' );
93 like( $@, qr/Cannot make import library/,
94 '... should die if emximp syscall fails' );
96 # sysfail is 0 now, call emximp call should succeed
97 eval { $mm->dlsyms() };
98 is( $unlinked, 1, '... should attempt to unlink temp files' );
99 like( $@, qr/Cannot extract import/,
100 '... should die if other syscall fails' );
102 # make both syscalls succeed
105 eval { $mm->dlsyms() };
106 is( $@, '', '... should not die if both syscalls succeed' );
113 # avoid "used only once"
114 local *ExtUtils::MM_Unix::static_lib;
115 *ExtUtils::MM_Unix::static_lib = sub {
117 return "\n\ncalled static_lib\n\nline2\nline3\n\nline4";
120 my $args = bless({ IMPORTS => {}, }, 'MM');
122 # without IMPORTS as a populated hash, there will be no extra data
123 my $ret = ExtUtils::MM_OS2::static_lib( $args );
124 is( $called, 1, 'static_lib() should call parent method' );
125 like( $ret, qr/^called static_lib/m,
126 '... should return parent data unless IMPORTS exists' );
128 $args->{IMPORTS} = { foo => 1};
129 $ret = ExtUtils::MM_OS2::static_lib( $args );
130 is( $called, 2, '... should call parent method if extra imports passed' );
131 like( $ret, qr/^called static_lib\n\t\$\(AR\) \$\(AR_STATIC_ARGS\)/m,
132 '... should append make tags to first line from parent method' );
133 like( $ret, qr/\$@\n\n\nline2\nline3\n\nline4/m,
134 '... should include remaining data from parent method' );
138 # replace_manpage_separator
139 my $sep = '//a///b//c/de';
140 is( ExtUtils::MM_OS2->replace_manpage_separator($sep), '.a.b.c.de',
141 'replace_manpage_separator() should turn multiple slashes into periods' );
146 my ($dir, $noext, $exe, $cmd);
149 my ($curdir, $updir) = (File::Spec->curdir, File::Spec->updir);
153 # 2) an executable file with no extension
154 # 3) an executable file with the .exe extension
155 # 4) an executable file with the .cmd extension
156 # we assume there will be one somewhere in the path
157 # in addition, we need them to be unique enough they do not trip
158 # an earlier file test in maybe_command(). Portability.
160 foreach my $path (split(/:/, $ENV{PATH})) {
161 opendir(DIR, $path) or next;
162 while (defined(my $file = readdir(DIR))) {
163 next if $file eq $curdir or $file eq $updir;
164 $file = File::Spec->catfile($path, $file);
165 unless (defined $dir) {
167 next if ( -x $file . '.exe' or -x $file . '.cmd' );
175 if ($file =~ s/\.(exe|cmd)\z//) {
178 # skip executable files with names too similar
183 unless (defined $noext) {
190 unless (defined $exe) {
197 unless (defined $cmd) {
211 skip('No appropriate directory found', 1) unless defined $dir;
212 is( ExtUtils::MM_OS2->maybe_command( $dir ), undef,
213 'maybe_command() should ignore directories' );
217 skip('No non-exension command found', 1) unless defined $noext;
218 is( ExtUtils::MM_OS2->maybe_command( $noext ), $noext,
219 'maybe_command() should find executable lacking file extension' );
223 skip('No .exe command found', 1) unless defined $exe;
224 (my $noexe = $exe) =~ s/\.exe\z//;
225 is( ExtUtils::MM_OS2->maybe_command( $noexe ), $exe,
226 'maybe_command() should find .exe file lacking extension' );
230 skip('No .cmd command found', 1) unless defined $cmd;
231 (my $nocmd = $cmd) =~ s/\.cmd\z//;
232 is( ExtUtils::MM_OS2->maybe_command( $nocmd ), $cmd,
233 'maybe_command() should find .cmd file lacking extension' );
237 # file_name_is_absolute
238 ok( ExtUtils::MM_OS2->file_name_is_absolute( 's:/' ),
239 'file_name_is_absolute() should be true for paths with volume and slash' );
240 ok( ExtUtils::MM_OS2->file_name_is_absolute( '\foo' ),
241 '... and for paths with leading slash but no volume' );
242 ok( ! ExtUtils::MM_OS2->file_name_is_absolute( 'arduk' ),
243 '... but not for paths with no leading slash or volume' );
246 is( ExtUtils::MM_OS2->perl_archive(), '$(PERL_INC)/libperl$(LIB_EXT)',
247 'perl_archive() should return a static string' );
253 *OS2::is_aout = \$aout;
255 isnt( ExtUtils::MM_OS2->perl_archive_after(), '',
256 'perl_archive_after() should return string without $is_aout set' );
258 is( ExtUtils::MM_OS2->perl_archive_after(), '',
259 '... and blank string if it is set' );
263 is( ExtUtils::MM_OS2::export_list({ BASEEXT => 'foo' }), 'foo.def',
264 'export_list() should add .def to BASEEXT member' );