change#4502 was missing a file
[p5sagit/p5-mst-13.2.git] / t / io / open.t
CommitLineData
3eb568f1 1#!./perl
2
3# $RCSfile$
853846ea 4$| = 1;
5$^W = 1;
821b8a23 6$Is_VMS = $^O eq 'VMS';
3eb568f1 7
6170680b 8print "1..32\n";
3eb568f1 9
853846ea 10# my $file tests
11
6170680b 12{
a6c40364 13unlink("afile") if -f "afile";
853846ea 14print "$!\nnot " unless open(my $f,"+>afile");
3eb568f1 15print "ok 1\n";
a6c40364 16binmode $f;
853846ea 17print "not " unless -f "afile";
3eb568f1 18print "ok 2\n";
853846ea 19print "not " unless print $f "SomeData\n";
3eb568f1 20print "ok 3\n";
853846ea 21print "not " unless tell($f) == 9;
3eb568f1 22print "ok 4\n";
853846ea 23print "not " unless seek($f,0,0);
3eb568f1 24print "ok 5\n";
853846ea 25$b = <$f>;
26print "not " unless $b eq "SomeData\n";
3eb568f1 27print "ok 6\n";
853846ea 28print "not " unless -f $f;
29print "ok 7\n";
30eval { die "Message" };
31# warn $@;
32print "not " unless $@ =~ /<\$f> line 1/;
33print "ok 8\n";
34print "not " unless close($f);
35print "ok 9\n";
36unlink("afile");
6170680b 37}
38{
39print "# \$!='$!'\nnot " unless open(my $f,'>', 'afile');
40print "ok 10\n";
41print $f "a row\n";
42print "not " unless close($f);
43print "ok 11\n";
44print "not " unless -s 'afile' < 10;
45print "ok 12\n";
46}
47{
48print "# \$!='$!'\nnot " unless open(my $f,'>>', 'afile');
49print "ok 13\n";
50print $f "a row\n";
51print "not " unless close($f);
52print "ok 14\n";
53print "not " unless -s 'afile' > 10;
54print "ok 15\n";
55}
56{
57print "# \$!='$!'\nnot " unless open(my $f, '<', 'afile');
58print "ok 16\n";
59@rows = <$f>;
60print "not " unless @rows == 2;
61print "ok 17\n";
62print "not " unless close($f);
63print "ok 18\n";
64}
65{
66print "not " unless -s 'afile' < 20;
67print "ok 19\n";
68print "# \$!='$!'\nnot " unless open(my $f, '+<', 'afile');
69print "ok 20\n";
70@rows = <$f>;
71print "not " unless @rows == 2;
72print "ok 21\n";
73seek $f, 0, 1;
74print $f "yet another row\n";
75print "not " unless close($f);
76print "ok 22\n";
77print "not " unless -s 'afile' > 20;
78print "ok 23\n";
79
80unlink("afile");
81}
f1612b5c 82if ($Is_VMS) { for (24..46) { print "ok $_ # skipped: not Unix fork\n"; } }
821b8a23 83else {
6170680b 84print "# \$!='$!'\nnot " unless open(my $f, '-|', <<'EOC');
bd4fc1f0 85./perl -e "print qq(a row\n); print qq(another row\n)"
6170680b 86EOC
87print "ok 24\n";
88@rows = <$f>;
89print "not " unless @rows == 2;
90print "ok 25\n";
91print "not " unless close($f);
92print "ok 26\n";
93}
f1612b5c 94if ($Is_VMS) { for (27..30) { print "OK $_ # skipped: not Unix fork\n"; } }
821b8a23 95else {
6170680b 96print "# \$!='$!'\nnot " unless open(my $f, '|-', <<'EOC');
bd4fc1f0 97./perl -pe "s/^not //"
6170680b 98EOC
99print "ok 27\n";
100@rows = <$f>;
101print $f "not ok 28\n";
102print $f "not ok 29\n";
103print "#\nnot " unless close($f);
104sleep 1;
105print "ok 30\n";
106}
3eb568f1 107
6170680b 108eval <<'EOE' and print "not ";
109open my $f, '<&', 'afile';
1101;
111EOE
112print "ok 31\n";
113$@ =~ /Unknown open\(\) mode \'<&\'/ or print "not ";
114print "ok 32\n";