To: | bug-catalyst [...] rt.cpan.org |
From: | David Wheeler <david [...] kineticode.com> |
Subject: | Generated Tests Need Help |
Date: | Mon, 9 Jan 2006 12:32:56 -0800 |
I'm using Catalystd 5.61.
Here's what a test file looks like after I run `catalyst.pl MiniMojo`:
use Test::More tests => 2;
BEGIN { use_ok( Catalyst::Test, 'MiniMojo' ); }
ok( request('/')->is_success );
I always like to have warnings and strict on, so I changed it to this:
#!/usr/bin/perl -w
use strict;
use Test::More tests => 2;
BEGIN { use_ok( Catalyst::Test, 'MiniMojo' ); }
ok( request('/')->is_success );
This causes the test to fail rather mysteriously:
Execution of t/01app.t aborted due to compilation errors.
But it doesn't say why. It took me half an hour to figure it that it
was because Catalyst::Test is a bare word, which is not allowed under
strict. Why there isn't a message about that I have no idea, but
please, *please*, add -w and strict to the generated tests and quote
Catalyst::Test.
Now, another issue: When I run the above test, it outputs a ton of
junk from the Catalyst HTTP server (I assume). This is all well and
good, but none of it is properly escaped for Test::Harness. All lines
should start with "#", or else you risk confusing Test::Harness as it
tries to keep track of tests. But even better, make sure that it's
outputting the right thing!
Here's how I'd like to see the default test written, instead:
#!/usr/bin/perl -w
use strict;
use Test::More tests => 4;
use Test::Output;
BEGIN {
stderr_like { use_ok 'Catalyst::Test', 'MiniMojo' }
qr/MiniMojo/, 'MiniMojo should be in the Catalyst output';
}
stderr_like { ok request('/')->is_success, 'Basic request should
succeed' }
qr{/default}, '... And the output should reflect that';
Yes, it introduces a dependency on Test::Output, but all of the noisy
output has got to go.
Best,
David