Jeffrey Thalhammer wrote:
* Should a test script have a shebang? What should it be? Any flags on that?
I often see "-t" in a shebang. One downside of the shebang, though, is that it's not particularly portable. As chromatic said, with "prove" it's not really necessary. ("prove -t")
* Should a test script make any assumptions about the CWD? Is it fair/safe for the test script to change directories?
Anything that affects the file system (particularly creating directories and files) often needs to change directories as part of the test.
As a side note, I wrote File::pushd to make it easy to change directories locally in a block and then snap back to where one started. I find it handy for that kind of testing.
use File::pushd; { my $dir = pushd( $some_dir ); # change to $some_dir # do stuff in $some_dir directory } # back to original directory here # convenient for testing: { my $dir = tempd; # change to a temp directory # do stuff in temp directory } # back to original directory and temp directory is gone
* What's the best practice for testing-only libraries? Where do they go and how do you load them? Is there a naming convention that most people follow (e.g. t::Foo::Bar).
I've personally come to like the "t::Foo::Bar" style as it is immediately obvious that the module in question is test-related. It's a handy affordance.
Regards, David Golden