summaryrefslogtreecommitdiff
path: root/t/io/open.t
blob: 418edacf3998522df4b7ab2f95524e8a043fdefe (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!./perl

# $RCSfile$    
$|  = 1;
$^W = 1;
$Is_VMS = $^O eq 'VMS';

print "1..32\n";

# my $file tests

{
unlink("afile") if -f "afile";     
print "$!\nnot " unless open(my $f,"+>afile");
print "ok 1\n";
binmode $f;
print "not " unless -f "afile";     
print "ok 2\n";
print "not " unless print $f "SomeData\n";
print "ok 3\n";
print "not " unless tell($f) == 9;
print "ok 4\n";
print "not " unless seek($f,0,0);
print "ok 5\n";
$b = <$f>;
print "not " unless $b eq "SomeData\n";
print "ok 6\n";
print "not " unless -f $f;     
print "ok 7\n";
eval  { die "Message" };   
# warn $@;
print "not " unless $@ =~ /<\$f> line 1/;
print "ok 8\n";
print "not " unless close($f);
print "ok 9\n";
unlink("afile");     
}
{
print "# \$!='$!'\nnot " unless open(my $f,'>', 'afile');
print "ok 10\n";
print $f "a row\n";
print "not " unless close($f);
print "ok 11\n";
print "not " unless -s 'afile' < 10;
print "ok 12\n";
}
{
print "# \$!='$!'\nnot " unless open(my $f,'>>', 'afile');
print "ok 13\n";
print $f "a row\n";
print "not " unless close($f);
print "ok 14\n";
print "not " unless -s 'afile' > 10;
print "ok 15\n";
}
{
print "# \$!='$!'\nnot " unless open(my $f, '<', 'afile');
print "ok 16\n";
@rows = <$f>;
print "not " unless @rows == 2;
print "ok 17\n";
print "not " unless close($f);
print "ok 18\n";
}
{
print "not " unless -s 'afile' < 20;
print "ok 19\n";
print "# \$!='$!'\nnot " unless open(my $f, '+<', 'afile');
print "ok 20\n";
@rows = <$f>;
print "not " unless @rows == 2;
print "ok 21\n";
seek $f, 0, 1;
print $f "yet another row\n";
print "not " unless close($f);
print "ok 22\n";
print "not " unless -s 'afile' > 20;
print "ok 23\n";

unlink("afile");     
}
if ($Is_VMS) { for (24..46) { print "ok $_ # skipped: not Unix fork\n"; } }
else {
print "# \$!='$!'\nnot " unless open(my $f, '-|', <<'EOC');
./perl -e "print qq(a row\n); print qq(another row\n)"
EOC
print "ok 24\n";
@rows = <$f>;
print "not " unless @rows == 2;
print "ok 25\n";
print "not " unless close($f);
print "ok 26\n";
}
if ($Is_VMS) { for (27..30) { print "OK $_ # skipped: not Unix fork\n"; } }
else {
print "# \$!='$!'\nnot " unless open(my $f, '|-', <<'EOC');
./perl -pe "s/^not //"
EOC
print "ok 27\n";
@rows = <$f>;
print $f "not ok 28\n";
print $f "not ok 29\n";
print "#\nnot " unless close($f);
sleep 1;
print "ok 30\n";
}

eval <<'EOE' and print "not ";
open my $f, '<&', 'afile';
1;
EOE
print "ok 31\n";
$@ =~ /Unknown open\(\) mode \'<&\'/ or print "not ";
print "ok 32\n";