From: Grant M. <gr...@us...> - 2007-08-02 10:38:24
|
Update of /cvsroot/perl-xml/xml-simple/t In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6004/t Modified Files: 3_Storable.t Log Message: - make test more robust to file mtime inaccuracies Index: 3_Storable.t =================================================================== RCS file: /cvsroot/perl-xml/xml-simple/t/3_Storable.t,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- 3_Storable.t 29 Jan 2005 04:17:42 -0000 1.10 +++ 3_Storable.t 2 Aug 2007 10:38:22 -0000 1.11 @@ -70,6 +70,39 @@ ############################################################################## +# Delete a file - portably +# + +sub DeleteFile { + my($Filename) = @_; + + if ('VMS' eq $^O) { + 1 while (unlink($Filename)); + } else { + unlink($Filename); + } +} + + +############################################################################## +# Create a file, making sure that its timestamp is newer than another +# existing file. +# + +sub MakeNewerFile { + my($File1, $File2, $CodeRef) = @_; + + my $t0 = (stat($File1))[9]; + while(1) { + unlink($File2); + $CodeRef->(); + return if (stat($File2))[9] > $t0; + sleep(1); + } +} + + +############################################################################## # Wait until the current time is greater than the supplied value # @@ -146,19 +179,15 @@ $t2 = (stat($CacheFile))[9]; isnt($t1, $t2, 'and this time the cache timestamp has changed'); -if ('VMS' eq $^O) { - 1 while (unlink($XMLFile)); -} else { - unlink($XMLFile); -} -ok(! -e $XMLFile, 'deleted the cache file'); +DeleteFile($XMLFile); +ok(! -e $XMLFile, 'deleted the source file'); open(FILE, ">$XMLFile"); # Re-create it (empty) close(FILE); ok(-e $XMLFile, 'recreated the source file'); is(-s $XMLFile, 0, 'but with nothing in it'); -PassTime((stat($XMLFile))[9]); # But ensure cache file is newer -unlink($CacheFile); # Seems to be rqd for test on Win32 -Storable::nstore($Expected, $CacheFile); +MakeNewerFile($XMLFile, $CacheFile, sub { # Make sure cache file is newer + Storable::nstore($Expected, $CacheFile); +}); $opt = XMLin($XMLFile, cache => 'storable'); is_deeply($opt, $Expected, 'got the expected data from the cache'); $t2 = (stat($CacheFile))[9]; |