note
macrobat
I'm not sure if I'm using Test::Exception right. Here's the gist of my original test, with the code in <i>eval</i> pulled out and switched to use dies_ok():<p>
<code>
unlink 'test.errors';
redirect_error( output_file => 'test.errors' ); # sets $redirected{error_messages} to 1
dies_ok { lcroak "this is a sample error file" };
ok( -T 'test.errors',
"lcroak opens the error file specified by redirect_error()." );
my $text = `cat test.errors`;
like( $text , qr/this is a sample error file/,
"lcroak writes to the error file specified by redirect_error()." );
unlink 'test.errors';
</code>
--and I get this:<p>
<code>
# Failed test 'lcroak writes to the error file specified by redirect_error().'
t/lcroak....NOK 4# in t/lcroak.t at line 25.
# ''
# doesn't match '(?-xism:this is a sample error file)'
# Looks like you failed 1 test of 4.
</code>
I did try local $@, like so, but perhaps I'm doing it wrong:<p>
<code>
{
local $@;
eval {
lcroak "this is a sample error file";
};
ok($@, "lcroak terminates");
}
</code>
That still redirect STDERR to <code>test.error</code>, however.
503488
503500