On 4 avr, 17:46, sterl...@hanenkamp.com (Sterling Hanenkamp) wrote:
> I am expanding the test suite for a module and to do so, I will need/want to
> create some temporary git repositories that I can work on. However, I'm not
> sure what the best practice is for locating these directories and files?
>
> My inclination is to use FIle::Temp to create a temporary directory to hold
> all the files and subdirectories I need and then clean this out when I'm
> done. I just didn't know if there was a different or better common practice
> in use by other module authors.

I am using File::Temp to create a temp test directory and I clean up
afterwards.

Have a look at https://github.com/klaus03/File-Vctools/blob/master/t/0010_test.t

>> use File::Temp qw(tempdir);
>>
>> my ($cwd, ... );
>>
>> preparations();

The interesting lines are in sub preparations starting at line 1130

>> sub preparations {
>>     $cwd = cwd();
>>     [...]
>>     $tempdir = tempdir(CLEANUP => 1); END { chdir $cwd if defined $cwd; }
>>     [...]
>> }

I use CLEANUP => 1 and I also make sure (by using the END {...}
clause) that I chdir out of the temp dir before cleanup (that's
important on windows systems)

Reply via email to