This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Get t/uni/cache.t working under minitest
[perl5.git] / t / op / unlink.t
1 #!./perl
2
3 BEGIN {
4     chdir 't';
5     @INC = '../lib';
6     require './test.pl';
7 }
8
9 plan 6;
10
11 # Need to run this in a quiet private directory as it assumes that it can
12 # reliably delete fixed file names.
13 my $tempdir = tempfile;
14
15 mkdir $tempdir, 0700 or die "Can't mkdir '$tempdir': $!";
16 chdir $tempdir or die die "Can't chdir '$tempdir': $!";
17
18 sub make_file {
19   my $file = shift;
20   open my $fh, ">", $file or die "Can't open $file: $!";
21   close $fh or die "Can't close $file: $!";
22 }
23
24 make_file('aaa');
25 is unlink('aaa'), 1, 'retval of unlink with one file name';
26 ok (!-e 'aaa', 'unlink unlinked it');
27 make_file($_) for 'aaa', 'bbb';
28 is unlink('aaa','bbb','ccc'), 2,
29     'retval of unlink with list that includes nonexistent file';
30 ok (!-e 'aaa' && !-e 'bbb', 'unlink unlank the files it claims it unlank');
31 $_ = 'zzz';
32 make_file 'zzz';
33 is unlink, 1, 'retval of unlink with no args';
34 ok !-e 'zzz', 'unlink with no arg unlinked $_';
35
36
37 chdir '..' or die "Couldn't chdir .. for cleanup: $!";
38 rmdir $tempdir or die "Couldn't unlink tempdir '$tempdir': $!";