develooper Front page | perl.perl5.porters | Postings from February 2009

Use tempfile() in tests

Thread Next
From:
Bram
Date:
February 14, 2009 12:48
Subject:
Use tempfile() in tests
Message ID:
20090214214834.jnkqrkdrxcgwkssg@horde.wizbit.be
Attached patch changes two scripts to use tempfile() instead of static  
filenames.

It also changes two other test scripts to use "$tempfile" instead of  
"./$tempfile" but that change was made only because it gave problems  
with the way I was testing it. (read: not 100% nesseary)

These were detected by changing the tempfile() function in test.pl to  
return a filename in /tmp/.... and to run the test suite with a user  
that had no permission to write in the perl-current.
In the test suite there are still some test scripts directly writing to files:

- t/op/magic.t:

the test script creates the filename 'show-shebang' and then executes it.
Switching to tempfile() from test.pl is not straightforward since the  
test script also defines an  ok  and  skip  subroutine (with different  
behaviour than  ok  and  skip  from test.pl).

- lib/charnames.t

this test script creates the file lib/unicore/xyzzy_alias.pl, changing  
this to use tempfile() is not possible.
- conflicts in tests: lib/strict.t and lib/subs.t

lib/strict.t reads the files in t/lib/strict/* and executes every test  
in these files. If the test begins with  '--FILE-- foo'  then it will  
create the file 'foo'.

lib/subs.t takes the tests from __DATA__ and executes every test in  
it. If the test  begins with '--FILE-- foo' then it will create the  
file 'foo'.

The conflict:

$ grep -E -- '--FILE-- +[^ ]' lib/subs.t
--FILE-- abc

$ grep -E -- '--FILE-- +[^ ]' t/lib/strict/*
t/lib/strict/refs:--FILE-- abc
t/lib/strict/refs:--FILE-- abc
t/lib/strict/refs:--FILE-- abc
t/lib/strict/refs:--FILE-- abc.pm
t/lib/strict/subs:--FILE-- abc
t/lib/strict/subs:--FILE-- abc
t/lib/strict/subs:--FILE-- abc
t/lib/strict/subs:--FILE-- abc.pm
t/lib/strict/vars:--FILE-- abc
t/lib/strict/vars:--FILE-- abc
t/lib/strict/vars:--FILE-- abc
t/lib/strict/vars:--FILE-- abc.pm
t/lib/strict/vars:--FILE-- abc.pm
t/lib/strict/vars:--FILE-- abc
If lib/subs.t is run in parallel with lib/strict.t then tests can fail.

One solution could be to use  '--FILE-- TEMPFILE'  and to replace it  
with tempfile(); (it will also needs to change TEMPFILE in the code  
with the actual filename)


[There are still modules in lib/ and ext/ that don't use a real  
temporary file name but I guess it would better to change these  
upstream]



Kind regards,

Bram



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About