xref: /openbsd/gnu/usr.bin/perl/t/op/unlink.t (revision 73471bf0)
1#!./perl
2
3BEGIN {
4    chdir 't' if -d 't';
5    require './test.pl';
6    set_up_inc('../lib');
7}
8
9plan 6;
10
11# Need to run this in a quiet private directory as it assumes that it can
12# reliably delete fixed file names.
13my $tempdir = tempfile;
14
15mkdir $tempdir, 0700 or die "Can't mkdir '$tempdir': $!";
16chdir $tempdir or die die "Can't chdir '$tempdir': $!";
17
18sub 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
24make_file('aaa');
25is unlink('aaa'), 1, 'retval of unlink with one file name';
26ok (!-e 'aaa', 'unlink unlinked it');
27make_file($_) for 'aaa', 'bbb';
28is unlink('aaa','bbb','ccc'), 2,
29    'retval of unlink with list that includes nonexistent file';
30ok (!-e 'aaa' && !-e 'bbb', 'unlink unlank the files it claims it unlank');
31$_ = 'zzz';
32make_file 'zzz';
33is unlink, 1, 'retval of unlink with no args';
34ok !-e 'zzz', 'unlink with no arg unlinked $_';
35
36
37chdir '..' or die "Couldn't chdir .. for cleanup: $!";
38rmdir $tempdir or die "Couldn't unlink tempdir '$tempdir': $!";
39