Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Perl-Critic CPAN distribution.

Report information
The Basics
Id: 31986
Status: rejected
Priority: 0/
Queue: Test-Perl-Critic

People
Owner: Nobody in particular
Requestors: kutterma [...] users.sourceforge.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.01
Fixed in: (no value)



Subject: Test::Perl::Critic configuration methods missing
There's no configuration methods for Test::Perl::Critic available. This makes writing a test file that works both in "make test" and when run from within t/ harder than necessary. This does not work: use Test::Perl::Critic -profile => 't/perlcriticrc'; if (-d 't/') { # when run from make test all_critic_ok(); } else { all_critic_ok('../lib'); } Test::Perl::Critic complains that it can't find 't/perlcriticrc'. The ugly workaround is to either chdir or call import later (to configure the critic): This does not work: use Test::Perl::Critic -profile => 't/perlcriticrc'; if (-d 't/') { # when run from make test all_critic_ok(); } else { chdir('..'); all_critic_ok('lib'); } This does, too: use Test::Perl::Critic; if (-d 't/') { # when run from make test import Test::Perl::Critic, -profile => 't/perlcriticrc'; all_critic_ok(); } else { import Test::Perl::Critic, -profile => 'perlcriticrc'); all_critic_ok('../lib'); } Both workarounds are undesirable, because they rely on Test::Perl::Critic internals: The first one relies on the late loading of the perlcriticrc given (in fact it wouldn't work if import only checked for the file's existance), the second one (possibly) calling import() several times (one could of course "require Test::Perl::Critic", but this disallows writing "critic_ok $file, $comment" in the style most testing modules propose). A easy fix would be the addition of a configuration method similar to Test::More's plan(), which accepts the same configuration parameters as import.
Sorry, the second example of course works, despite the typo "This does not work" above...
From: ELLIOTJS [...] cpan.org
The problem here is that T::P::C needs to be able to find the file. Said file is not likely to be anywhere in @INC, so where does T::P::C look? If you want to be able to run your tests from an arbitrary directory, give an absolute path for the profile. The way to do this in a location independent way is to use the FindBin core module in your .t file.
Hi Elliot, of course I can make T::P::C find the file - both my two workarounds and FindBin work. However, the workarounds rely on T::P::C's internals (which could change - one could even consider the late loading of the profile as bug), and FindBin has similar problems: It does only work when used before T::P::C, and does not under persistent interpreters (like mod_perl). A conifguration method, like the "plan" method in Test::More is the only reliable way to make T::P::C configurable at run-time - an that's my current need. Regards, Martin
Subject: Re: [rt.cpan.org #31986] Test::Perl::Critic configuration methods missing
Date: Mon, 31 Dec 2007 10:42:52 -0600
To: bug-Test-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
Martin Kutter via RT wrote: Show quoted text
> A conifguration method, like the "plan" method in Test::More is the only > reliable way to make T::P::C configurable at run-time - an that's my > current need.
I seriously don't know how finding the profile can be moved into the module.
In hindsight, I'm not wild about the interface to T::P::C. But I have to agree with Elliot on this one. The problem isn't the import() interface, it is the use of relative paths. If you're going to run this test from an arbitrary directory, then you have to specify the paths absolutely. For example (untested): use FindBin qw($Bin); use Test::Perl::Critic(-profile => "$Bin/perlcriticrc"); my ($blib_dir, $lib_dir) = ("$Bin/../blib", "$Bin/../lib"); all_critic_ok( -d $blib_dir ? $blib_dir : $lib_dir ); I don't see how this (or your workarounds) rely on the "internals" of Perl::Critic in an unacceptable way. Please let me know if I've misunderstood you. Happy new year! -Jeff