-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path03-tempfile.t
72 lines (50 loc) · 1.54 KB
/
03-tempfile.t
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use Test;
use File::Directory::Tree;
plan(14);
my (@should-be-unlinked, @should-be-kept);
# Install this END phaser here before File::Temp has a chance to create its END phaser
# so that we can check that files are unlinked properly
END {
for @should-be-kept -> $f {
ok($f.IO ~~ :e, "file $f still exists");
if $f.IO ~~ :f
{
unlink($f);
}
elsif $f.IO ~~ :d
{
rmtree($f);
}
}
for @should-be-unlinked -> $f {
nok(($f.IO ~~ :e), "file $f was unlinked");
}
}
# TODO Remove the EVAL; this is a hack to work around improper ordering
# of END phasers in Rakudo
EVAL '
use File::Temp;
# begin tempdile tests
my ($name,$handle) = tempfile;
ok($name.IO ~~ :e, "tempfile created");
ok($handle.close, "tempfile closed");
ok($name.IO ~~ :e, "tempfile exists after closing the handle");
@should-be-unlinked.push: $name;
($name,$handle) = tempfile( :!unlink );
@should-be-kept.push: $name;
($name,$handle) = tempfile( :prefix("foo") );
@should-be-unlinked.push: $name;
ok($name ~~ /foo/, "name has foo in it");
($name,$handle) = tempfile( :suffix(".txt") );
@should-be-unlinked.push: $name;
ok($name ~~ / ".txt" $ /, "name ends in .txt");
# begin tempdir tests
my $dir_name = tempdir;
ok($dir_name.IO ~~ :e, "tempdir created");
@should-be-unlinked.push: $dir_name;
$dir_name = tempdir( :!unlink );
@should-be-kept.push: $dir_name;
$dir_name = tempdir( :prefix("foo") );
@should-be-unlinked.push: $dir_name;
ok($dir_name ~~ /foo/, "$dir_name contains foo");
'