X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/8ae39f603f0f5778c160e18e08df60affbd5a620..86191aed6f092273:/t/op/defins.t diff --git a/t/op/defins.t b/t/op/defins.t index 5b26bf8..fb746d5 100644 --- a/t/op/defins.t +++ b/t/op/defins.t @@ -6,11 +6,12 @@ BEGIN { chdir 't' if -d 't'; - @INC = qw(. ../lib); + require './test.pl'; + set_up_inc( qw(. ../lib) ); $SIG{__WARN__} = sub { $warns++; warn $_[0] }; } -require 'test.pl'; -plan( tests => 23 ); + +plan( tests => 27 ); my $unix_mode = 1; @@ -33,14 +34,23 @@ if ($^O eq 'VMS') { $unix_mode = 1 if $drop_dot && unix_rpt; } +# $wanted_filename should be 0 for readdir() and glob() tests. +# This is because it is the only valid filename that is false in a boolean test. + +# $filename = '0'; +# print "hi\n" if $filename; # doesn't print + +# In the case of VMS, '0' isn't always the filename that you get. +# Which makes those particular tests pointless. + $wanted_filename = $unix_mode ? '0' : '0.'; $saved_filename = './0'; cmp_ok($warns,'==',0,'no warns at start'); ok(open(FILE,">$saved_filename"),'created work file'); +print FILE "0\n"; print FILE "1\n"; -print FILE "0"; close(FILE); open(FILE,"<$saved_filename"); @@ -49,6 +59,7 @@ my $seen = 0; my $dummy; while (my $name = ) { + chomp($name); $seen++ if $name eq '0'; } cmp_ok($seen,'==',1,'seen in while()'); @@ -58,6 +69,7 @@ $seen = 0; my $line = ''; do { + chomp($line); $seen++ if $line eq '0'; } while ($line = ); cmp_ok($seen,'==',1,'seen in do/while'); @@ -66,15 +78,17 @@ seek(FILE,0,0); $seen = 0; while (($seen ? $dummy : $name) = ) { + chomp($name); $seen++ if $name eq '0'; } -cmp_ok($seen,'==',1,'seen in while() ternary'); +cmp_ok($seen,'==',2,'seen in while() ternary'); seek(FILE,0,0); $seen = 0; my %where; while ($where{$seen} = ) { + chomp($where{$seen}); $seen++ if $where{$seen} eq '0'; } cmp_ok($seen,'==',1,'seen in hash while()'); @@ -106,6 +120,31 @@ while ($where{$seen} = readdir(DIR)) } cmp_ok($seen,'==',1,'saw file in hash while()'); +rewinddir(DIR); +$seen = 0; +$_ = 'not 0'; +while (readdir(DIR)) + { + $seen++ if $_ eq $wanted_filename; + } +cmp_ok($seen,'==',1,'saw file in bare while(readdir){...}'); + +rewinddir(DIR); +$seen = 0; +$_ = 'not 0'; + +$_ eq $wanted_filename && $seen++ while readdir(DIR); +cmp_ok($seen,'==',1,'saw file in bare "... while readdir"'); + +rewinddir(DIR); +$seen = 0; +$_ = ""; # suppress uninit warning +do + { + $seen++ if $_ eq $wanted_filename; + } while (readdir(DIR)); +cmp_ok($seen,'==',1,'saw file in bare do{...}while(readdir)'); + $seen = 0; while (my $name = glob('*')) { @@ -133,12 +172,16 @@ ok(!(-f $saved_filename),'work file unlinked'); my %hash = (0 => 1, 1 => 2); my @array = 1; +my $neg_sum= 0; $seen = 0; + while (my $name = each %hash) { + $neg_sum = $name - $neg_sum; $seen++ if $name eq '0'; } +cmp_ok(abs($neg_sum),'==',1,'abs(neg_sum) should equal 1'); cmp_ok($seen,'==',1,'seen in each'); $seen = 0; @@ -147,7 +190,7 @@ while (($seen ? $dummy : $name) = each %hash) { $seen++ if $name eq '0'; } -cmp_ok($seen,'==',1,'seen in each ternary'); +cmp_ok($seen,'==',$neg_sum < 0 ? 1 : 2,'seen in each ternary'); $seen = 0; while ($where{$seen} = each %hash)