6 if( $ENV{PERL_CORE} ) {
17 plan( skip_all => "This is not OS/2" );
20 # for dlsyms, overridden in tests
22 package ExtUtils::MM_OS2;
23 use subs 'system', 'unlink';
29 use_ok( 'ExtUtils::MM_OS2' );
30 ok( grep( 'ExtUtils::MM_OS2', @MM::ISA),
31 'ExtUtils::MM_OS2 should be parent of MM' );
39 }, 'ExtUtils::MM_OS2');
41 is( $mm->dlsyms(), '',
42 'dlsyms() should return nothing with dynamic flag set' );
44 $mm->{BASEEXT} = 'baseext';
45 delete $mm->{SKIPHASH};
46 my $res = $mm->dlsyms();
47 like( $res, qr/baseext\.def: Makefile/,
48 '... without flag, should return make targets' );
49 like( $res, qr/"DL_FUNCS" => { }/,
50 '... should provide empty hash refs where necessary' );
51 like( $res, qr/"DL_VARS" => \[]/, '... and empty array refs too' );
53 $mm->{FUNCLIST} = 'funclist';
54 $res = $mm->dlsyms( IMPORTS => 'imports' );
55 like( $res, qr/"FUNCLIST" => .+funclist/,
56 '... should pick up values from object' );
57 like( $res, qr/"IMPORTS" => .+imports/, '... and allow parameter options too' );
62 $can_write = open(OUT, '>tmp_imp');
66 skip("Cannot write test files: $!", 7) unless $can_write;
68 $mm->{IMPORTS} = { foo => 'bar' };
71 eval { $mm->dlsyms() };
72 like( $@, qr/Can.t mkdir tmp_imp/,
73 '... should die if directory cannot be made' );
75 unlink('tmp_imp') or skip("Cannot remove test file: $!", 9);
76 eval { $mm->dlsyms() };
77 like( $@, qr/Malformed IMPORT/, 'should die from malformed import symbols');
79 $mm->{IMPORTS} = { foo => 'bar.baz' };
81 my @sysfail = ( 1, 0, 1 );
82 my ($sysargs, $unlinked);
84 *ExtUtils::MM_OS2::system = sub {
86 return shift @sysfail;
89 *ExtUtils::MM_OS2::unlink = sub {
93 eval { $mm->dlsyms() };
95 like( $sysargs, qr/^emximp/, '... should try to call system() though' );
96 like( $@, qr/Cannot make import library/,
97 '... should die if emximp syscall fails' );
99 # sysfail is 0 now, call emximp call should succeed
100 eval { $mm->dlsyms() };
101 is( $unlinked, 1, '... should attempt to unlink temp files' );
102 like( $@, qr/Cannot extract import/,
103 '... should die if other syscall fails' );
105 # make both syscalls succeed
108 eval { $mm->dlsyms() };
109 is( $@, '', '... should not die if both syscalls succeed' );
116 # avoid "used only once"
117 local *ExtUtils::MM_Unix::static_lib;
118 *ExtUtils::MM_Unix::static_lib = sub {
120 return "\n\ncalled static_lib\n\nline2\nline3\n\nline4";
123 my $args = bless({ IMPORTS => {}, }, 'MM');
125 # without IMPORTS as a populated hash, there will be no extra data
126 my $ret = ExtUtils::MM_OS2::static_lib( $args );
127 is( $called, 1, 'static_lib() should call parent method' );
128 like( $ret, qr/^called static_lib/m,
129 '... should return parent data unless IMPORTS exists' );
131 $args->{IMPORTS} = { foo => 1};
132 $ret = ExtUtils::MM_OS2::static_lib( $args );
133 is( $called, 2, '... should call parent method if extra imports passed' );
134 like( $ret, qr/^called static_lib\n\t\$\(AR\) \$\(AR_STATIC_ARGS\)/m,
135 '... should append make tags to first line from parent method' );
136 like( $ret, qr/\$@\n\n\nline2\nline3\n\nline4/m,
137 '... should include remaining data from parent method' );
141 # replace_manpage_separator
142 my $sep = '//a///b//c/de';
143 is( ExtUtils::MM_OS2->replace_manpage_separator($sep), '.a.b.c.de',
144 'replace_manpage_separator() should turn multiple slashes into periods' );
149 my ($dir, $noext, $exe, $cmd);
152 my ($curdir, $updir) = (File::Spec->curdir, File::Spec->updir);
156 # 2) an executable file with no extension
157 # 3) an executable file with the .exe extension
158 # 4) an executable file with the .cmd extension
159 # we assume there will be one somewhere in the path
160 # in addition, we need them to be unique enough they do not trip
161 # an earlier file test in maybe_command(). Portability.
163 foreach my $path (split(/:/, $ENV{PATH})) {
164 opendir(DIR, $path) or next;
165 while (defined(my $file = readdir(DIR))) {
166 next if $file eq $curdir or $file eq $updir;
167 $file = File::Spec->catfile($path, $file);
168 unless (defined $dir) {
170 next if ( -x $file . '.exe' or -x $file . '.cmd' );
178 if ($file =~ s/\.(exe|cmd)\z//) {
181 # skip executable files with names too similar
186 unless (defined $noext) {
193 unless (defined $exe) {
200 unless (defined $cmd) {
214 skip('No appropriate directory found', 1) unless defined $dir;
215 is( ExtUtils::MM_OS2->maybe_command( $dir ), undef,
216 'maybe_command() should ignore directories' );
220 skip('No non-exension command found', 1) unless defined $noext;
221 is( ExtUtils::MM_OS2->maybe_command( $noext ), $noext,
222 'maybe_command() should find executable lacking file extension' );
226 skip('No .exe command found', 1) unless defined $exe;
227 (my $noexe = $exe) =~ s/\.exe\z//;
228 is( ExtUtils::MM_OS2->maybe_command( $noexe ), $exe,
229 'maybe_command() should find .exe file lacking extension' );
233 skip('No .cmd command found', 1) unless defined $cmd;
234 (my $nocmd = $cmd) =~ s/\.cmd\z//;
235 is( ExtUtils::MM_OS2->maybe_command( $nocmd ), $cmd,
236 'maybe_command() should find .cmd file lacking extension' );
240 # file_name_is_absolute
241 ok( ExtUtils::MM_OS2->file_name_is_absolute( 's:/' ),
242 'file_name_is_absolute() should be true for paths with volume and slash' );
243 ok( ExtUtils::MM_OS2->file_name_is_absolute( '\foo' ),
244 '... and for paths with leading slash but no volume' );
245 ok( ! ExtUtils::MM_OS2->file_name_is_absolute( 'arduk' ),
246 '... but not for paths with no leading slash or volume' );
249 is( ExtUtils::MM_OS2->perl_archive(), '$(PERL_INC)/libperl$(LIB_EXT)',
250 'perl_archive() should return a static string' );
256 *OS2::is_aout = \$aout;
258 isnt( ExtUtils::MM_OS2->perl_archive_after(), '',
259 'perl_archive_after() should return string without $is_aout set' );
261 is( ExtUtils::MM_OS2->perl_archive_after(), '',
262 '... and blank string if it is set' );
266 is( ExtUtils::MM_OS2::export_list({ BASEEXT => 'foo' }), 'foo.def',
267 'export_list() should add .def to BASEEXT member' );