Move the require './test.pl' to the end of t/comp/hints.t
[p5sagit/p5-mst-13.2.git] / t / op / defins.t
CommitLineData
55d729e4 1#!./perl -w
2
3#
4# test auto defined() test insertion
5#
6
7BEGIN {
8 chdir 't' if -d 't';
7e35a6a8 9 @INC = qw(. ../lib);
55d729e4 10 $SIG{__WARN__} = sub { $warns++; warn $_[0] };
55d729e4 11}
7e35a6a8 12require 'test.pl';
13plan( tests => 19 );
b2b3adea 14
6d74d930 15my $unix_mode = 1;
16
17if ($^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.';
7b903762 37$saved_filename = './0';
7e35a6a8 38
39cmp_ok($warns,'==',0,'no warns at start');
55d729e4 40
95e8664e 41open(FILE,">$saved_filename");
7e35a6a8 42ok(defined(FILE),'created work file');
55d729e4 43print FILE "1\n";
44print FILE "0";
45close(FILE);
46
95e8664e 47open(FILE,"<$saved_filename");
7e35a6a8 48ok(defined(FILE),'opened work file');
55d729e4 49my $seen = 0;
50my $dummy;
51while (my $name = <FILE>)
52 {
53 $seen++ if $name eq '0';
7e35a6a8 54 }
55cmp_ok($seen,'==',1,'seen in while()');
55d729e4 56
57seek(FILE,0,0);
58$seen = 0;
59my $line = '';
7e35a6a8 60do
55d729e4 61 {
62 $seen++ if $line eq '0';
63 } while ($line = <FILE>);
7e35a6a8 64cmp_ok($seen,'==',1,'seen in do/while');
55d729e4 65
66seek(FILE,0,0);
7e35a6a8 67$seen = 0;
68while (($seen ? $dummy : $name) = <FILE> )
55d729e4 69 {
70 $seen++ if $name eq '0';
71 }
7e35a6a8 72cmp_ok($seen,'==',1,'seen in while() ternary');
55d729e4 73
74seek(FILE,0,0);
7e35a6a8 75$seen = 0;
76my %where;
55d729e4 77while ($where{$seen} = <FILE>)
78 {
79 $seen++ if $where{$seen} eq '0';
80 }
7e35a6a8 81cmp_ok($seen,'==',1,'seen in hash while()');
7120fed6 82close FILE;
55d729e4 83
7b903762 84opendir(DIR,'.');
7e35a6a8 85ok(defined(DIR),'opened current directory');
55d729e4 86$seen = 0;
87while (my $name = readdir(DIR))
88 {
b2b3adea 89 $seen++ if $name eq $wanted_filename;
7e35a6a8 90 }
91cmp_ok($seen,'==',1,'saw work file once');
55d729e4 92
93rewinddir(DIR);
7e35a6a8 94$seen = 0;
55d729e4 95$dummy = '';
96while (($seen ? $dummy : $name) = readdir(DIR))
97 {
b2b3adea 98 $seen++ if $name eq $wanted_filename;
55d729e4 99 }
7e35a6a8 100cmp_ok($seen,'>',0,'saw file in while() ternary');
55d729e4 101
102rewinddir(DIR);
7e35a6a8 103$seen = 0;
55d729e4 104while ($where{$seen} = readdir(DIR))
105 {
b2b3adea 106 $seen++ if $where{$seen} eq $wanted_filename;
55d729e4 107 }
7e35a6a8 108cmp_ok($seen,'==',1,'saw file in hash while()');
55d729e4 109
110$seen = 0;
111while (my $name = glob('*'))
112 {
b2b3adea 113 $seen++ if $name eq $wanted_filename;
7e35a6a8 114 }
115cmp_ok($seen,'==',1,'saw file in glob while()');
55d729e4 116
7e35a6a8 117$seen = 0;
55d729e4 118$dummy = '';
119while (($seen ? $dummy : $name) = glob('*'))
120 {
b2b3adea 121 $seen++ if $name eq $wanted_filename;
55d729e4 122 }
7e35a6a8 123cmp_ok($seen,'>',0,'saw file in glob hash while() ternary');
55d729e4 124
7e35a6a8 125$seen = 0;
55d729e4 126while ($where{$seen} = glob('*'))
127 {
b2b3adea 128 $seen++ if $where{$seen} eq $wanted_filename;
55d729e4 129 }
7e35a6a8 130cmp_ok($seen,'==',1,'seen in glob hash while()');
55d729e4 131
95e8664e 132unlink($saved_filename);
7e35a6a8 133ok(!(-f $saved_filename),'work file unlinked');
55d729e4 134
135my %hash = (0 => 1, 1 => 2);
136
137$seen = 0;
138while (my $name = each %hash)
139 {
140 $seen++ if $name eq '0';
7e35a6a8 141 }
142cmp_ok($seen,'==',1,'seen in each');
55d729e4 143
7e35a6a8 144$seen = 0;
55d729e4 145$dummy = '';
146while (($seen ? $dummy : $name) = each %hash)
147 {
148 $seen++ if $name eq '0';
149 }
7e35a6a8 150cmp_ok($seen,'==',1,'seen in each ternary');
55d729e4 151
7e35a6a8 152$seen = 0;
55d729e4 153while ($where{$seen} = each %hash)
154 {
155 $seen++ if $where{$seen} eq '0';
156 }
7e35a6a8 157cmp_ok($seen,'==',1,'seen in each hash');
55d729e4 158
7e35a6a8 159cmp_ok($warns,'==',0,'no warns at finish');