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