Commit | Line | Data |
55d729e4 |
1 | #!./perl -w |
2 | |
3 | # |
4 | # test auto defined() test insertion |
5 | # |
6 | |
7 | BEGIN { |
8 | chdir 't' if -d 't'; |
7e35a6a8 |
9 | @INC = qw(. ../lib); |
55d729e4 |
10 | $SIG{__WARN__} = sub { $warns++; warn $_[0] }; |
55d729e4 |
11 | } |
7e35a6a8 |
12 | require 'test.pl'; |
13 | plan( tests => 19 ); |
b2b3adea |
14 | |
15 | $wanted_filename = $^O eq 'VMS' ? '0.' : '0'; |
95e8664e |
16 | $saved_filename = $^O eq 'MacOS' ? ':0' : './0'; |
7e35a6a8 |
17 | |
18 | cmp_ok($warns,'==',0,'no warns at start'); |
55d729e4 |
19 | |
95e8664e |
20 | open(FILE,">$saved_filename"); |
7e35a6a8 |
21 | ok(defined(FILE),'created work file'); |
55d729e4 |
22 | print FILE "1\n"; |
23 | print FILE "0"; |
24 | close(FILE); |
25 | |
95e8664e |
26 | open(FILE,"<$saved_filename"); |
7e35a6a8 |
27 | ok(defined(FILE),'opened work file'); |
55d729e4 |
28 | my $seen = 0; |
29 | my $dummy; |
30 | while (my $name = <FILE>) |
31 | { |
32 | $seen++ if $name eq '0'; |
7e35a6a8 |
33 | } |
34 | cmp_ok($seen,'==',1,'seen in while()'); |
55d729e4 |
35 | |
36 | seek(FILE,0,0); |
37 | $seen = 0; |
38 | my $line = ''; |
7e35a6a8 |
39 | do |
55d729e4 |
40 | { |
41 | $seen++ if $line eq '0'; |
42 | } while ($line = <FILE>); |
7e35a6a8 |
43 | cmp_ok($seen,'==',1,'seen in do/while'); |
55d729e4 |
44 | |
45 | seek(FILE,0,0); |
7e35a6a8 |
46 | $seen = 0; |
47 | while (($seen ? $dummy : $name) = <FILE> ) |
55d729e4 |
48 | { |
49 | $seen++ if $name eq '0'; |
50 | } |
7e35a6a8 |
51 | cmp_ok($seen,'==',1,'seen in while() ternary'); |
55d729e4 |
52 | |
53 | seek(FILE,0,0); |
7e35a6a8 |
54 | $seen = 0; |
55 | my %where; |
55d729e4 |
56 | while ($where{$seen} = <FILE>) |
57 | { |
58 | $seen++ if $where{$seen} eq '0'; |
59 | } |
7e35a6a8 |
60 | cmp_ok($seen,'==',1,'seen in hash while()'); |
7120fed6 |
61 | close FILE; |
55d729e4 |
62 | |
95e8664e |
63 | opendir(DIR,($^O eq 'MacOS' ? ':' : '.')); |
7e35a6a8 |
64 | ok(defined(DIR),'opened current directory'); |
55d729e4 |
65 | $seen = 0; |
66 | while (my $name = readdir(DIR)) |
67 | { |
b2b3adea |
68 | $seen++ if $name eq $wanted_filename; |
7e35a6a8 |
69 | } |
70 | cmp_ok($seen,'==',1,'saw work file once'); |
55d729e4 |
71 | |
72 | rewinddir(DIR); |
7e35a6a8 |
73 | $seen = 0; |
55d729e4 |
74 | $dummy = ''; |
75 | while (($seen ? $dummy : $name) = readdir(DIR)) |
76 | { |
b2b3adea |
77 | $seen++ if $name eq $wanted_filename; |
55d729e4 |
78 | } |
7e35a6a8 |
79 | cmp_ok($seen,'>',0,'saw file in while() ternary'); |
55d729e4 |
80 | |
81 | rewinddir(DIR); |
7e35a6a8 |
82 | $seen = 0; |
55d729e4 |
83 | while ($where{$seen} = readdir(DIR)) |
84 | { |
b2b3adea |
85 | $seen++ if $where{$seen} eq $wanted_filename; |
55d729e4 |
86 | } |
7e35a6a8 |
87 | cmp_ok($seen,'==',1,'saw file in hash while()'); |
55d729e4 |
88 | |
89 | $seen = 0; |
90 | while (my $name = glob('*')) |
91 | { |
b2b3adea |
92 | $seen++ if $name eq $wanted_filename; |
7e35a6a8 |
93 | } |
94 | cmp_ok($seen,'==',1,'saw file in glob while()'); |
55d729e4 |
95 | |
7e35a6a8 |
96 | $seen = 0; |
55d729e4 |
97 | $dummy = ''; |
98 | while (($seen ? $dummy : $name) = glob('*')) |
99 | { |
b2b3adea |
100 | $seen++ if $name eq $wanted_filename; |
55d729e4 |
101 | } |
7e35a6a8 |
102 | cmp_ok($seen,'>',0,'saw file in glob hash while() ternary'); |
55d729e4 |
103 | |
7e35a6a8 |
104 | $seen = 0; |
55d729e4 |
105 | while ($where{$seen} = glob('*')) |
106 | { |
b2b3adea |
107 | $seen++ if $where{$seen} eq $wanted_filename; |
55d729e4 |
108 | } |
7e35a6a8 |
109 | cmp_ok($seen,'==',1,'seen in glob hash while()'); |
55d729e4 |
110 | |
95e8664e |
111 | unlink($saved_filename); |
7e35a6a8 |
112 | ok(!(-f $saved_filename),'work file unlinked'); |
55d729e4 |
113 | |
114 | my %hash = (0 => 1, 1 => 2); |
115 | |
116 | $seen = 0; |
117 | while (my $name = each %hash) |
118 | { |
119 | $seen++ if $name eq '0'; |
7e35a6a8 |
120 | } |
121 | cmp_ok($seen,'==',1,'seen in each'); |
55d729e4 |
122 | |
7e35a6a8 |
123 | $seen = 0; |
55d729e4 |
124 | $dummy = ''; |
125 | while (($seen ? $dummy : $name) = each %hash) |
126 | { |
127 | $seen++ if $name eq '0'; |
128 | } |
7e35a6a8 |
129 | cmp_ok($seen,'==',1,'seen in each ternary'); |
55d729e4 |
130 | |
7e35a6a8 |
131 | $seen = 0; |
55d729e4 |
132 | while ($where{$seen} = each %hash) |
133 | { |
134 | $seen++ if $where{$seen} eq '0'; |
135 | } |
7e35a6a8 |
136 | cmp_ok($seen,'==',1,'seen in each hash'); |
55d729e4 |
137 | |
7e35a6a8 |
138 | cmp_ok($warns,'==',0,'no warns at finish'); |