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' );
58 pir_output_is( <<'CODE', <<"OUT", 'Test cwd' );
74 my $upcwd = File::Spec->canonpath(getcwd);
77 if (File::Spec->case_tolerant(substr($cwd,0,2))) {
81 pir_output_is( <<'CODE', <<"OUT", 'Test chdir' );
108 pir_output_is( <<'CODE', <<"OUT", 'Test chdir' );
136 $xpto =~ s/src([\/\\]?)$/xpto$1/;
138 if (File::Spec->case_tolerant(substr($cwd,0,2))) {
140 pir_output_is( <<'CODE', <<"OUT", 'Test mkdir' );
169 pir_output_is( <<'CODE', <<"OUT", 'Test mkdir' );
196 # Test remove on a directory
197 mkdir "xpto" unless -d "xpto";
199 pir_output_is( <<'CODE', <<'OUT', 'Test rm call in a directory' );
215 ok( !-d $xpto, "Test that rm removed the directory" );
216 rmdir $xpto if -d $xpto; # this way next test doesn't fail if this one does
220 open my $X, '>', "xpto";
226 my $count = $MSWin32 ? 11 : 13;
227 my @s = stat('xpto');
229 # Mask inode number (fudge it)
234 $stat = sprintf("0x%08x\n" x 11, @s);
235 pir_output_is( <<'CODE', $stat, 'Test OS.stat' );
240 $P2 = $P1."stat"($S1)
242 $S1 = repeat "0x%08x\n", 11
243 $S2 = sprintf $S1, $P2
252 skip 'broken test TT #457', 1 if $solaris;
254 $stat = sprintf("0x%08x\n" x 13, @s);
255 pir_output_is( <<'CODE', $stat, 'Test OS.stat' );
260 $P2 = $P1."stat"($S1)
262 $S1 = repeat "0x%08x\n", 13
263 $S2 = sprintf $S1, $P2
274 skip 'not implemented on windows yet', 1 if ( $MSWin32 && $MSVC );
276 opendir my $IN, 'docs';
277 my @entries = readdir $IN;
279 my $entries = join( ' ', @entries ) . "\n";
280 pir_output_is( <<'CODE', $entries, 'Test OS.readdir' );
284 $P2 = $P1.'readdir'('docs')
295 open my $FILE, ">", "____some_test_file";
297 pir_output_is( <<'CODE', <<"OUT", 'Test OS.rename' );
302 $P1.'rename'('____some_test_file', '___some_other_file')
303 $I0 = stat '___some_other_file', 0
306 $P1.'rm'('___some_other_file')
318 skip 'lstat not on Win32', 1 if $MSWin32;
319 skip 'broken test TT #457', 1 if $solaris;
321 my @s = lstat('xpto');
323 # Mask inode number (fudge it)
326 $lstat = sprintf( "0x%08x\n" x 13, @s );
327 pir_output_is( <<'CODE', $lstat, "Test OS.lstat" );
332 $P2 = $P1."lstat"($S1)
334 $S1 = repeat "0x%08x\n", 13
335 $S2 = sprintf $S1, $P2
343 # Test remove on a file
344 pir_output_is( <<'CODE', <<"OUT", "Test rm call in a file" );
360 ok( !-f $xpto, "Test that rm removed file" );
361 rmdir $xpto if -f $xpto; # this way next test doesn't fail if this one does
365 skip "Symlinks not available under Windows", 2 if $MSWin32;
367 pir_output_is( <<'CODE', <<"OUT", "Test symlink" );
374 $P1."symlink"($S2, $S1)
384 ok( -l "xpto", "symlink was really created" );
385 unlink "xpto" if -f "xpto";
388 # Test link to file. May require root permissions
390 skip "Hardlinks to files not possible on Windows", 2 if $MSWin32 or $cygwin;
392 pir_output_is( <<'CODE', <<"OUT", "Test link" );
409 my $nl = [ stat("myconfig") ]->[3];
410 ok( $nl > 1, "hard link to file was really created" );
411 unlink "xpto" if -f "xpto";
415 skip "Hardlinks to files not possible on Windows", 1 if $MSWin32 or $cygwin;
417 my $prevnl = [ stat("tools") ]->[3];
418 pir_output_like( <<"CODE", <<"OUT", "Test dirlink" );
421 .local string xpto, tools
427 push_eh no_root_perms
428 os."link"(tools, xpto)
432 statvals = os.'stat'(tools)
438 gt nlink, $prevnl, is_okay
443 .local string message
446 message = e['message']
455 /link.* failed for OS PMC:/
461 # cperl-indent-level: 4
464 # vim: expandtab shiftwidth=4: