require_ok()functions provided by Test::More don't do exactly what we wanted.
use_ok()
The short story is that we ended up doing something like this:
eval {We later looked for a more general, better solution, and a colleague posted on the perl-qa mailing list, but the bottom line is that a more elegant solution still involves executing a new perl interpreter, but in a platform-independent way (perhaps using
$output = `perl -c $script 2>&1`;
chomp $output;
};
is($output, "$script syntax OK", "$script compiles");
IPC::Open3 or something.) It's also likely that a better test is to ignore the output altogether and just check the return code from the compile process (the call to perl -c.)Tags:
March 18, 2006 update: Jeff Thalhammer found that a colleague Pierre Denis provides a syntax_ok method in Test::Strict that does what we want.
More update - I was prodded by Randall Schwartz to post why you should be careful when "only" compiling Perl code - see BEGIN Blocks Considered Harmful.