Perl: the Markov chain saw | |
PerlMonks |
1 while unlink 'foo'by rinceWind (Monsignor) |
on Jan 28, 2004 at 10:54 UTC ( [id://324636]=perlmeditation: print w/replies, xml ) | Need Help?? |
Those of you who have need to delve into the core perl tests will see this wierd looking idiom. The reason for this I will explain. Approaching from the other side, I have a CPAN module with tests, some of which create files and directories on the target machine. In order to make the tests rerunnable, I have a test t/00_clear.t, as follows: I had a specific objective in this module, to make it portable. One of the target platforms was VMS, and I was disappointed to find this test failing when the test suite was rerun (and subsequent tests owing to data lying around). Further digging showed that $! contained "directory not empty", and I realised that the problem was that VMS has multiply versioned files, but File::Find will only visit each filename once, so the above code leaves any back versions behind, and fails to remove the containing directories. I posted to the vmsperl list, and received an immediate response: 1 while unlink 'foo';Thinking about this incantation, I incorporated it into my module test: and this worked a treat! I recommend this idiom for everyone writing tests for CPAN modules whenever there is a possibility that a file can become multiversioned on some platforms. I think that portability is a noble aim in itself.
-- I'm Not Just Another Perl Hacker
Back to
Meditations
|
|