This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Avoid race conditions with files in /tmp, by explicitly checking dev & inode.
[perl5.git] / t / io / perlio_fail.t
CommitLineData
0cff2cf3
NIS
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require "../t/test.pl";
7 skip_all("No perlio") unless (find PerlIO::Layer 'perlio');
d96fb286 8 plan (15);
0cff2cf3
NIS
9}
10
11use warnings 'layer';
12my $warn;
13my $file = "fail$$";
14$SIG{__WARN__} = sub { $warn = shift };
15
16END { 1 while unlink($file) }
17
18ok(open(FH,">",$file),"Create works");
19close(FH);
20ok(open(FH,"<",$file),"Normal open works");
21
22$warn = ''; $! = 0;
23ok(!binmode(FH,":-)"),"All punctuation fails binmode");
d96fb286
JH
24print "# $!\n";
25isnt($!,0,"Got errno");
c4d88abd 26like($warn,qr/in PerlIO layer/,"Got warning");
0cff2cf3
NIS
27
28$warn = ''; $! = 0;
29ok(!binmode(FH,":nonesuch"),"Bad package fails binmode");
d96fb286
JH
30print "# $!\n";
31isnt($!,0,"Got errno");
0cff2cf3
NIS
32like($warn,qr/nonesuch/,"Got warning");
33close(FH);
34
35$warn = ''; $! = 0;
36ok(!open(FH,"<:-)",$file),"All punctuation fails open");
d96fb286 37print "# $!\n";
0cff2cf3 38isnt($!,"","Got errno");
c4d88abd 39like($warn,qr/in PerlIO layer/,"Got warning");
0cff2cf3
NIS
40
41$warn = ''; $! = 0;
42ok(!open(FH,"<:nonesuch",$file),"Bad package fails open");
d96fb286
JH
43print "# $!\n";
44isnt($!,0,"Got errno");
0cff2cf3
NIS
45like($warn,qr/nonesuch/,"Got warning");
46
47ok(open(FH,"<",$file),"Normal open (still) works");
48close(FH);