4 # test auto defined() test insertion
10 set_up_inc( qw(. ../lib) );
11 $SIG{__WARN__} = sub { $warns++; warn $_[0] };
19 # We have to know if VMS is in UNIX mode. In UNIX mode, trailing dots
20 # should not be present. There are actually two settings that control this.
25 if (eval 'require VMS::Feature') {
26 $unix_rpt = VMS::Feature::current('filename_unix_report');
27 $drop_dot = VMS::Feature::current('readdir_dropdotnotype');
29 my $unix_report = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
30 $unix_rpt = $unix_report =~ /^[ET1]/i;
31 my $drop_dot_notype = $ENV{'DECC$READDIR_DROPDOTNOTYPE'} || '';
32 $drop_dot = $drop_dot_notype =~ /^[ET1]/i;
34 $unix_mode = 1 if $drop_dot && unix_rpt;
37 # $wanted_filename should be 0 for readdir() and glob() tests.
38 # This is because it is the only valid filename that is false in a boolean test.
41 # print "hi\n" if $filename; # doesn't print
43 # In the case of VMS, '0' isn't always the filename that you get.
44 # Which makes those particular tests pointless.
46 $wanted_filename = $unix_mode ? '0' : '0.';
47 $saved_filename = './0';
49 cmp_ok($warns,'==',0,'no warns at start');
51 ok(open(FILE,">$saved_filename"),'created work file');
56 open(FILE,"<$saved_filename");
57 ok(defined(FILE),'opened work file');
60 while (my $name = <FILE>)
63 $seen++ if $name eq '0';
65 cmp_ok($seen,'==',1,'seen in while()');
73 $seen++ if $line eq '0';
74 } while ($line = <FILE>);
75 cmp_ok($seen,'==',1,'seen in do/while');
79 while (($seen ? $dummy : $name) = <FILE> )
82 $seen++ if $name eq '0';
84 cmp_ok($seen,'==',2,'seen in while() ternary');
89 while ($where{$seen} = <FILE>)
92 $seen++ if $where{$seen} eq '0';
94 cmp_ok($seen,'==',1,'seen in hash while()');
98 ok(defined(DIR),'opened current directory');
100 while (my $name = readdir(DIR))
102 $seen++ if $name eq $wanted_filename;
104 cmp_ok($seen,'==',1,'saw work file once');
109 while (($seen ? $dummy : $name) = readdir(DIR))
111 $seen++ if $name eq $wanted_filename;
113 cmp_ok($seen,'>',0,'saw file in while() ternary');
117 while ($where{$seen} = readdir(DIR))
119 $seen++ if $where{$seen} eq $wanted_filename;
121 cmp_ok($seen,'==',1,'saw file in hash while()');
128 $seen++ if $_ eq $wanted_filename;
130 cmp_ok($seen,'==',1,'saw file in bare while(readdir){...}');
136 $_ eq $wanted_filename && $seen++ while readdir(DIR);
137 cmp_ok($seen,'==',1,'saw file in bare "... while readdir"');
141 $_ = ""; # suppress uninit warning
144 $seen++ if $_ eq $wanted_filename;
145 } while (readdir(DIR));
146 cmp_ok($seen,'==',1,'saw file in bare do{...}while(readdir)');
149 while (my $name = glob('*'))
151 $seen++ if $name eq $wanted_filename;
153 cmp_ok($seen,'==',1,'saw file in glob while()');
157 while (($seen ? $dummy : $name) = glob('*'))
159 $seen++ if $name eq $wanted_filename;
161 cmp_ok($seen,'>',0,'saw file in glob hash while() ternary');
164 while ($where{$seen} = glob('*'))
166 $seen++ if $where{$seen} eq $wanted_filename;
168 cmp_ok($seen,'==',1,'seen in glob hash while()');
170 unlink($saved_filename);
171 ok(!(-f $saved_filename),'work file unlinked');
173 my %hash = (0 => 1, 1 => 2);
179 while (my $name = each %hash)
181 $neg_sum = $name - $neg_sum;
182 $seen++ if $name eq '0';
184 cmp_ok(abs($neg_sum),'==',1,'abs(neg_sum) should equal 1');
185 cmp_ok($seen,'==',1,'seen in each');
189 while (($seen ? $dummy : $name) = each %hash)
191 $seen++ if $name eq '0';
193 cmp_ok($seen,'==',$neg_sum < 0 ? 1 : 2,'seen in each ternary');
196 while ($where{$seen} = each %hash)
198 $seen++ if $where{$seen} eq '0';
200 cmp_ok($seen,'==',1,'seen in each hash');
206 $seen++ if $_ eq '0';
208 cmp_ok($seen,'==',1,'0 seen in $_ in while(each %hash)');
214 $seen++ if $_ eq '0';
216 cmp_ok($seen,'==',1,'0 seen in $_ in while(each @array)');
220 $_ eq '0' and $seen++ while each %hash;
221 cmp_ok($seen,'==',1,'0 seen in $_ in while(each %hash) as stm mod');
225 $_ eq '0' and $seen++ while each @array;
226 cmp_ok($seen,'==',1,'0 seen in $_ in while(each @array) as stm mod');
228 cmp_ok($warns,'==',0,'no warns at finish');