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