File: unlink.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (38 lines) | stat: -rw-r--r-- 1,063 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!./perl

BEGIN {
    chdir 't' if -d 't';
    require './test.pl';
    set_up_inc('../lib');
}

plan 6;

# Need to run this in a quiet private directory as it assumes that it can
# reliably delete fixed file names.
my $tempdir = tempfile;

mkdir $tempdir, 0700 or die "Can't mkdir '$tempdir': $!";
chdir $tempdir or die die "Can't chdir '$tempdir': $!";

sub make_file {
  my $file = shift;
  open my $fh, ">", $file or die "Can't open $file: $!";
  close $fh or die "Can't close $file: $!";
}

make_file('aaa');
is unlink('aaa'), 1, 'retval of unlink with one file name';
ok (!-e 'aaa', 'unlink unlinked it');
make_file($_) for 'aaa', 'bbb';
is unlink('aaa','bbb','ccc'), 2,
    'retval of unlink with list that includes nonexistent file';
ok (!-e 'aaa' && !-e 'bbb', 'unlink unlank the files it claims it unlank');
$_ = 'zzz';
make_file 'zzz';
is unlink, 1, 'retval of unlink with no args';
ok !-e 'zzz', 'unlink with no arg unlinked $_';


chdir '..' or die "Couldn't chdir .. for cleanup: $!";
rmdir $tempdir or die "Couldn't unlink tempdir '$tempdir': $!";