X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/1e2e7acc9e622f0a712d5ea988401aac71ff8c16..5b279f8b9f38ac6332e7ddbcac2b8bf949abe47c:/lib/vmsish.t diff --git a/lib/vmsish.t b/lib/vmsish.t index 24e3b04..71ca3b5 100644 --- a/lib/vmsish.t +++ b/lib/vmsish.t @@ -112,17 +112,32 @@ is($?,0,"outer lex scope of vmsish [POSIX status]"); eval "END { \$ENV{'SYS\$TIMEZONE_DIFFERENTIAL'} = $oldtz; }"; gmtime(0); # Force reset of tz offset } + + # Unless we are prepared to parse the timezone rules here and figure out + # what the correct offset was when the file was last revised, we need to + # use a file for which the current offset is known to be valid. That's why + # we create a file rather than using an existing one for the stat() test. + + my $file = 'sys$scratch:vmsish_t_flirble.tmp'; + open TMP, ">$file" or die "Couldn't open file $file"; + close TMP; + END { 1 while unlink $file; } + { use_ok('vmsish qw(time)'); + + # but that didn't get it in our current scope + use vmsish qw(time); + $vmstime = time; @vmslocal = localtime($vmstime); @vmsgmtime = gmtime($vmstime); - $vmsmtime = (stat $0)[9]; + $vmsmtime = (stat $file)[9]; } $utctime = time; @utclocal = localtime($vmstime); @utcgmtime = gmtime($vmstime); - $utcmtime = (stat $0)[9]; + $utcmtime = (stat $file)[9]; $offset = $ENV{'SYS$TIMEZONE_DIFFERENTIAL'}; @@ -130,23 +145,23 @@ is($?,0,"outer lex scope of vmsish [POSIX status]"); # since it's unlikely local time will differ from UTC by so small # an amount, and it renders the test resistant to delays from # things like stat() on a file mounted over a slow network link. - ok($utctime - $vmstime +$offset <= 10,"(time) UTC:$utctime VMS:$vmstime"); + ok(abs($utctime - $vmstime + $offset) <= 10,"(time) UTC: $utctime VMS: $vmstime"); $utcval = $utclocal[5] * 31536000 + $utclocal[7] * 86400 + $utclocal[2] * 3600 + $utclocal[1] * 60 + $utclocal[0]; $vmsval = $vmslocal[5] * 31536000 + $vmslocal[7] * 86400 + $vmslocal[2] * 3600 + $vmslocal[1] * 60 + $vmslocal[0]; - ok($vmsval - $utcval + $offset <= 10, "(localtime)"); + ok(abs($vmsval - $utcval + $offset) <= 10, "(localtime) UTC: $utcval VMS: $vmsval"); print "# UTC: @utclocal\n# VMS: @vmslocal\n"; $utcval = $utcgmtime[5] * 31536000 + $utcgmtime[7] * 86400 + $utcgmtime[2] * 3600 + $utcgmtime[1] * 60 + $utcgmtime[0]; $vmsval = $vmsgmtime[5] * 31536000 + $vmsgmtime[7] * 86400 + $vmsgmtime[2] * 3600 + $vmsgmtime[1] * 60 + $vmsgmtime[0]; - ok($vmsval - $utcval + $offset <= 10, "(gmtime)"); + ok(abs($vmsval - $utcval + $offset) <= 10, "(gmtime) UTC: $utcval VMS: $vmsval"); print "# UTC: @utcgmtime\n# VMS: @vmsgmtime\n"; - ok($vmsmtime - $utcmtime + $offset <= 10,"(stat) UTC: $utcmtime VMS: $vmsmtime"); + ok(abs($utcmtime - $vmsmtime + $offset) <= 10,"(stat) UTC: $utcmtime VMS: $vmsmtime"); } }