This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t LEAVE_with_name("evalcomp") for syntax errors
[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 my $unix_mode = 1;
16
17 if ($^O eq 'VMS') {
18     # We have to know if VMS is in UNIX mode.  In UNIX mode, trailing dots
19     # should not be present.  There are actually two settings that control this.
20
21     $unix_mode = 0;
22     my $unix_rpt = 0;
23     my $drop_dot = 0;
24     if (eval 'require VMS::Feature') {
25         $unix_rpt = VMS::Feature::current('filename_unix_report');
26         $drop_dot = VMS::Feature::current('readdir_dropdotnotype');
27     } else {
28         my $unix_report = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
29         $unix_rpt = $unix_report =~ /^[ET1]/i; 
30         my $drop_dot_notype = $ENV{'DECC$READDIR_DROPDOTNOTYPE'} || '';
31         $drop_dot = $drop_dot_notype =~ /^[ET1]/i;
32     }
33     $unix_mode = 1 if $drop_dot && unix_rpt;
34 }
35
36 $wanted_filename = $unix_mode ? '0' : '0.';
37 $saved_filename = './0';
38
39 cmp_ok($warns,'==',0,'no warns at start');
40
41 ok(open(FILE,">$saved_filename"),'created work file');
42 print FILE "1\n";
43 print FILE "0";
44 close(FILE);
45
46 open(FILE,"<$saved_filename");
47 ok(defined(FILE),'opened work file');
48 my $seen = 0;
49 my $dummy;
50 while (my $name = <FILE>)
51  {
52   $seen++ if $name eq '0';
53  }
54 cmp_ok($seen,'==',1,'seen in while()');
55
56 seek(FILE,0,0);
57 $seen = 0;
58 my $line = '';
59 do
60  {
61   $seen++ if $line eq '0';
62  } while ($line = <FILE>);
63 cmp_ok($seen,'==',1,'seen in do/while');
64
65 seek(FILE,0,0);
66 $seen = 0;
67 while (($seen ? $dummy : $name) = <FILE> )
68  {
69   $seen++ if $name eq '0';
70  }
71 cmp_ok($seen,'==',1,'seen in while() ternary');
72
73 seek(FILE,0,0);
74 $seen = 0;
75 my %where;
76 while ($where{$seen} = <FILE>)
77  {
78   $seen++ if $where{$seen} eq '0';
79  }
80 cmp_ok($seen,'==',1,'seen in hash while()');
81 close FILE;
82
83 opendir(DIR,'.');
84 ok(defined(DIR),'opened current directory');
85 $seen = 0;
86 while (my $name = readdir(DIR))
87  {
88   $seen++ if $name eq $wanted_filename;
89  }
90 cmp_ok($seen,'==',1,'saw work file once');
91
92 rewinddir(DIR);
93 $seen = 0;
94 $dummy = '';
95 while (($seen ? $dummy : $name) = readdir(DIR))
96  {
97   $seen++ if $name eq $wanted_filename;
98  }
99 cmp_ok($seen,'>',0,'saw file in while() ternary');
100
101 rewinddir(DIR);
102 $seen = 0;
103 while ($where{$seen} = readdir(DIR))
104  {
105   $seen++ if $where{$seen} eq $wanted_filename;
106  }
107 cmp_ok($seen,'==',1,'saw file in hash while()');
108
109 $seen = 0;
110 while (my $name = glob('*'))
111  {
112   $seen++ if $name eq $wanted_filename;
113  }
114 cmp_ok($seen,'==',1,'saw file in glob while()');
115
116 $seen = 0;
117 $dummy = '';
118 while (($seen ? $dummy : $name) = glob('*'))
119  {
120   $seen++ if $name eq $wanted_filename;
121  }
122 cmp_ok($seen,'>',0,'saw file in glob hash while() ternary');
123
124 $seen = 0;
125 while ($where{$seen} = glob('*'))
126  {
127   $seen++ if $where{$seen} eq $wanted_filename;
128  }
129 cmp_ok($seen,'==',1,'seen in glob hash while()');
130
131 unlink($saved_filename);
132 ok(!(-f $saved_filename),'work file unlinked');
133
134 my %hash = (0 => 1, 1 => 2);
135
136 $seen = 0;
137 while (my $name = each %hash)
138  {
139   $seen++ if $name eq '0';
140  }
141 cmp_ok($seen,'==',1,'seen in each');
142
143 $seen = 0;
144 $dummy = '';
145 while (($seen ? $dummy : $name) = each %hash)
146  {
147   $seen++ if $name eq '0';
148  }
149 cmp_ok($seen,'==',1,'seen in each ternary');
150
151 $seen = 0;
152 while ($where{$seen} = each %hash)
153  {
154   $seen++ if $where{$seen} eq '0';
155  }
156 cmp_ok($seen,'==',1,'seen in each hash');
157
158 cmp_ok($warns,'==',0,'no warns at finish');