2 # Copyright (C) 2001-2009, Parrot Foundation.
7 use lib qw( . lib ../lib ../../lib );
9 use Parrot::Test tests => 16;
14 my $MSWin32 = $^O =~ m!MSWin32!;
15 my $cygwin = $^O =~ m!cygwin!;
16 my $solaris = $^O =~ m!solaris!;
17 my $MSVC = $PConfig{cc} =~ m/\bcl(?:\.exe)?/i;
21 t/pmc/os.t - Files and Dirs
34 # Clean up environment on exit
35 rmdir "xpto" if -d "xpto";
36 unlink "xpto" if -f "xpto";
40 my $cwd = File::Spec->canonpath(getcwd);
41 if (File::Spec->case_tolerant(substr($cwd,0,2))) {
43 pir_output_is( <<'CODE', <<"OUT", 'Test cwd' );
57 pir_output_is( <<'CODE', <<"OUT", 'Test cwd' );
72 my $upcwd = File::Spec->canonpath(getcwd);
75 if (File::Spec->case_tolerant(substr($cwd,0,2))) {
79 pir_output_is( <<'CODE', <<"OUT", 'Test chdir' );
105 pir_output_is( <<'CODE', <<"OUT", 'Test chdir' );
132 $xpto =~ s/src([\/\\]?)$/xpto$1/;
134 if (File::Spec->case_tolerant(substr($cwd,0,2))) {
136 pir_output_is( <<'CODE', <<"OUT", 'Test mkdir' );
164 pir_output_is( <<'CODE', <<"OUT", 'Test mkdir' );
190 # Test remove on a directory
191 mkdir "xpto" unless -d "xpto";
193 pir_output_is( <<'CODE', <<'OUT', 'Test rm call in a directory' );
208 ok( !-d $xpto, "Test that rm removed the directory" );
209 rmdir $xpto if -d $xpto; # this way next test doesn't fail if this one does
213 open my $X, '>', "xpto";
219 my $count = $MSWin32 ? 11 : 13;
220 my @s = stat('xpto');
222 # Mask inode number (fudge it)
227 $stat = sprintf("0x%08x\n" x 11, @s);
228 pir_output_is( <<'CODE', $stat, 'Test OS.stat' );
232 $P2 = $P1."stat"($S1)
234 $S1 = repeat "0x%08x\n", 11
235 $S2 = sprintf $S1, $P2
243 skip 'broken test TT #457', 1 if $solaris;
245 $stat = sprintf("0x%08x\n" x 13, @s);
246 pir_output_is( <<'CODE', $stat, 'Test OS.stat' );
250 $P2 = $P1."stat"($S1)
252 $S1 = repeat "0x%08x\n", 13
253 $S2 = sprintf $S1, $P2
264 skip 'not implemented on windows yet', 1 if ( $MSWin32 && $MSVC );
266 opendir my $IN, 'docs';
267 my @entries = readdir $IN;
269 my $entries = join( ' ', @entries ) . "\n";
270 pir_output_is( <<'CODE', $entries, 'Test OS.readdir' );
273 $P2 = $P1.'readdir'('docs')
284 open my $FILE, ">", "____some_test_file";
286 pir_output_is( <<'CODE', <<"OUT", 'Test OS.rename' );
289 $P1.'rename'('____some_test_file', '___some_other_file')
290 $I0 = stat '___some_other_file', 0
293 $P1.'rm'('___some_other_file')
305 skip 'lstat not on Win32', 1 if $MSWin32;
306 skip 'broken test TT #457', 1 if $solaris;
308 my @s = lstat('xpto');
310 # Mask inode number (fudge it)
313 $lstat = sprintf( "0x%08x\n" x 13, @s );
314 pir_output_is( <<'CODE', $lstat, "Test OS.lstat" );
318 $P2 = $P1."lstat"($S1)
320 $S1 = repeat "0x%08x\n", 13
321 $S2 = sprintf $S1, $P2
329 # Test remove on a file
330 pir_output_is( <<'CODE', <<"OUT", "Test rm call in a file" );
345 ok( !-f $xpto, "Test that rm removed file" );
346 rmdir $xpto if -f $xpto; # this way next test doesn't fail if this one does
350 skip "Symlinks not available under Windows", 2 if $MSWin32;
352 pir_output_is( <<'CODE', <<"OUT", "Test symlink" );
358 $P1."symlink"($S2, $S1)
368 ok( -l "xpto", "symlink was really created" );
369 unlink "xpto" if -f "xpto";
372 # Test link to file. May require root permissions
374 skip "Hardlinks to files not possible on Windows", 2 if $MSWin32 or $cygwin;
376 pir_output_is( <<'CODE', <<"OUT", "Test link" );
392 my $nl = [ stat("myconfig") ]->[3];
393 ok( $nl > 1, "hard link to file was really created" );
394 unlink "xpto" if -f "xpto";
398 skip "Hardlinks to files not possible on Windows", 1 if $MSWin32 or $cygwin;
400 my $prevnl = [ stat("tools") ]->[3];
401 pir_output_like( <<"CODE", <<"OUT", "Test dirlink" );
404 .local string xpto, tools
409 push_eh no_root_perms
410 os."link"(tools, xpto)
414 statvals = os.'stat'(tools)
420 gt nlink, $prevnl, is_okay
425 .local string message
428 message = e['message']
437 /link.* failed for OS PMC:/
443 # cperl-indent-level: 4
446 # vim: expandtab shiftwidth=4: