2 # Copyright (C) 2001-2006, Parrot Foundation.
7 use lib qw( . lib ../lib ../../lib );
10 use Parrot::Test tests => 9;
16 use File::Spec::Functions;
18 my $tempdir = File::Temp::tempdir( CLEANUP => 1 );
20 our ( $MSWin32, $cygwin );
21 $MSWin32 = 1 if $^O =~ m!MSWin32!;
22 $cygwin = 1 if $^O =~ m!cygwin!;
26 t/pmc/file.t - Files functions
34 Tests the C<File> PMC.
38 my $xpto = catdir( $tempdir, 'xpto' );
39 mkdir $xpto unless -d $xpto;
41 my $otpx = catfile( $xpto, 'otpx' );
43 open my $fh, '>', $otpx or die $!;
48 pir_output_is( <<"CODE", <<"OUT", "Test is_dir" );
54 \$I1 = \$P1."is_dir"(\$S1)
63 \$I1 = \$P1."is_dir"(\$S1)
80 pir_error_output_like( <<"CODE", <<"OUT", "Test is_dir error" );
85 #make a filename that's long enough to cause lstat to fail
88 \$S0 = concat \$S0, "1234567890"
92 \$I1 = \$P1."is_dir"(\$S0)
97 /^[\\w \t\r\n]+current instr\.:/
101 pir_output_is( <<"CODE", <<"OUT", "Test is_file" );
103 \$P0 = loadlib 'file'
107 \$I1 = \$P1."is_file"(\$S1)
117 \$I1 = \$P1."is_file"(\$S1)
133 pir_error_output_like( <<"CODE", <<"OUT", "Test is_file error" );
135 \$P0 = loadlib 'file'
138 #make a filename that's long enough to cause lstat to fail
141 \$S0 = concat \$S0, "1234567890"
145 \$I1 = \$P1."is_file"(\$S0)
150 /^[\\w \t\r\n]+current instr\.:/
154 skip "Links not available under Windows", 1 if $MSWin32;
156 my $lotpx = catfile( $xpto, 'lotpx' );
157 symlink $otpx, $lotpx;
160 pir_output_is( <<"CODE", <<"OUT", "Test is_link with links to files" );
162 \$P0 = loadlib 'file'
166 \$I1 = \$P1."is_link"(\$S1)
174 \$I1 = \$P1."is_link"(\$S1)
190 skip "Links not available under Windows", 1 if $MSWin32;
192 my $xptol = catdir( $xpto, 'xptol' );
193 symlink $xpto, $xptol;
196 pir_output_is( <<"CODE", <<"OUT", "Test is_link with links to directories" );
198 \$P0 = loadlib 'file'
202 \$I1 = \$P1."is_link"(\$S1)
210 \$I1 = \$P1."is_link"(\$S1)
224 my $otpxcopy = catdir( $xpto, 'otpxcopy' );
227 pir_output_is( <<"CODE", <<"OUT", "Test copy for files" );
232 \$P0 = loadlib 'file'
237 \$P1."copy"(\$S1,\$S2)
240 \$P3 = \$P2."stat"(\$S1)
241 \$P4 = \$P2."stat"(\$S2)
246 if \$I1 == \$I2 goto ok
260 skip 'file exists', 1 if $MSWin32;
262 pir_output_is( <<"CODE", <<"OUT", "Test rename for files" );
267 \$P0 = loadlib 'file'
272 \$P3 = \$P2."stat"(\$S1)
275 \$P1."rename"(\$S1,\$S2)
278 \$P4 = \$P2."stat"(\$S2)
281 if \$I1 == \$I2 goto ok
294 my $bad_file = catfile( $xpto, 'not a file' );
297 pir_output_is( <<"CODE", <<"OUT", "Test rename for files" );
299 \$P0 = loadlib 'file'
301 \$I1 = \$P1.'exists'( '$otpxcopy' )
303 if \$I1 goto file_exists
307 print "ok 1 - file exists\\n"
309 \$I1 = \$P1.'exists'( '$xpto' )
311 if \$I1 goto dir_exists
315 print "ok 2 - directory exists\\n"
317 \$I1 = \$P1.'exists'( '$bad_file' )
319 if \$I1 == 0 goto file_does_not_exist
323 print "ok 3 - file does not exist\\n"
329 ok 2 - directory exists
330 ok 3 - file does not exist
335 # cperl-indent-level: 4
338 # vim: expandtab shiftwidth=4: