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