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.
3 comments:
Beware that "perl -c" still executes "BEGIN" blocks (and by extension, anything in the body of anything pulled in with "use"), so it's not safe to use with untrusted code.
For example:
perl -c -e 'BEGIN { print "running!\n" }'
will print "running!".
You are quite correct!
In fact, I have sent email to a couple of vendors of Perl IDE's and posted in the Eclipse/EPIC forum about this "BEGIN Blocks Considered Harmful" situation (See http://tinyurl.com/oja4v)
Hmmm. Maybe time for a proper blog post about it.
Hi eliben - the answer is that I use the "Edit HTML" feature of the editor, and enclose the code in <pre> </pre>
Post a Comment