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