Skip Menu |

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

Report information
The Basics
Id: 115754
Status: open
Priority: 0/
Queue: Test-Needs

People
Owner: Nobody in particular
Requestors: PERLANCAR [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: a generic base class perhaps?
Would you consider a module (perhaps a base class for Test::Needs) that is the generic version? So say Test::Prerequisite provides test_prereq(\&code) which can skip tests when code returns non-empty failure message string. Where Test::Needs is a special case for when the condition is "certain module is available". For example, in one of my distributions, I'm testing with node.js. It would be nice to be able to say something like: subtest "js1" => sub { test_prereq { "node" or "nodejs" is in PATH }; ... }; or even: subtest "js1" => sub { test_prereq { "node" or "nodejs" is in PATH and it supports --harmony_scoping option }; ... };
BTW, yes, this is basically the equivalent of Test::More's: subtest "js1" => sub { plan skip_all => "no node/nodejs found in PATH" if ...; ... }; except that it can work without Test::More.
On Thu Jun 30 07:20:00 2016, PERLANCAR wrote: Show quoted text
> BTW, yes, this is basically the equivalent of Test::More's: > > subtest "js1" => sub { > plan skip_all => "no node/nodejs found in PATH" if ...; > ... > }; > > except that it can work without Test::More.
But if you are using a subtest like this, Test::More will still be required and loaded. I'm not entirely opposed to having some kind of more generic version or reusable routine, but the examples you've used don't show a compelling reason for it.
On Thu, 30 Jun 2016 18:28:30 GMT, haarg wrote: Show quoted text
> On Thu Jun 30 07:20:00 2016, PERLANCAR wrote:
> > BTW, yes, this is basically the equivalent of Test::More's: > > > > subtest "js1" => sub { > > plan skip_all => "no node/nodejs found in PATH" if ...; > > ... > > }; > > > > except that it can work without Test::More.
> > But if you are using a subtest like this, Test::More will still be > required and loaded. > > I'm not entirely opposed to having some kind of more generic version > or reusable routine, but the examples you've used don't show a > compelling reason for it.
Yeah, you're right. Now that I think about it, what I wanted to do is package this functionality into a module: plan skip_all => "no node/nodejs found in PATH" if !nodejs_available(); plan skip_all => "node doesn't support --harmony_scoping" if !nodejs_supports_harmony_scoping(); but I guess I can just package the nodejs_available() and nodejs_supports_harmony_scoping() parts.
I've played around some with making Test::Needs more generic. https://github.com/haarg/Test-Needs/tree/extensions Refactoring the internals some made it easy to write extensions that operate similar to Test::Needs. I wrote a few extensions to prove the concept. I will most likely ship the refactor soon. I'm not certain yet what I want to do with the extensions I wrote.
Thanks for the update. Looks OK. I'll certainly create a few extensions after the API is released.