May 2013 Archives

If there's a shortage of programmers, why aren't wages up?

"There's no shortage of IT workers because wages would rise!"

I've heard that so many times that I want to scream. And it's all because of one damnably simply, yet misunderstood, supply and demand graph:

supply and demand graph

We all learn about that graph in introductory economics classes and, to misquote Mencken (as everyone does), it's simple, elegant, and wrong.

Cleaning up the Test::Class::Moose base class

I'm quite enjoying Test::Class::Moose. It's very easy to use and it gives you such fine-grained control over your test suite and powerful reporting capabilities that it's turning out to be far more powerful than I had expected. It's actually easy enough to use for beginners, but power users will really appreciate it. There was, however, a major issue I had with it and it stems from a habit I picked up from Test::Class.

For those who are very familiar with using Test::Class (or if you've read my Test::Class tutorial), you may be used to seeing a base class that looks like this:

package My::Test::Class;
use parent 'Test::Class';

INIT { Test::Class->runtests }

sub startup  : Tests(startup)  {}
sub setup    : Tests(setup)    {}
sub teardown : Tests(teardown) {}
sub shutdown : Tests(shutdown) {}

1;

The empty test control methods are there so that a subclass knows it can always safely do this:

sub startup : Tests(startup) {
    my $test = shift;
    $test->next::method;
    # more code here
}

Those stub test methods are no longer needed with Test::Class::Moose, but until today, that INIT block was an annoying code smell that had some unfortunate side-effects. Let's make that go away.

Tags now available with Test::Class::Moose

Side note: Why did I miss that last Perl QA-Hackathon? I've attended every one since they started ... except for the last one. I missed it because the damned French government can't get around to reissuing my damned visa, despite the fact that they're legally required to. I've also had to pass on some business opportunities and a trip Romania. /me is very unhappy with France right now.

So I've finally gotten around to updating Test::Class::Moose to have tags. You can read my previous post when I explain why they're useful. You can go out to github and grab it now, or wait a bit for it to hit your favorite CPAN mirror.

The constructor is very straightforward. For the case I previously described when the network went down? Skip test methods with a network tag!

Test::Class::Moose->new(
    exclude_tags => 'network', # scalar or arrayref of tags
)->runtests;

Or maybe you want to run your Big Data and API tests, but skip deprecated methods:

Test::Class::Moose->new(
    include_tags => [qw/bigdata api/],
    exclude_tags => 'deprecated',
)->runtests;

This should solve a common issue where people want to attach metadata to their test suite but there's no clean support for it.

Unfortunately, this was implemented with Sub::Attribute. That's a fantastic module, but it's an optional dependency that some don't want. I had to use that module, though, because there's a little-known edge case where subroutine attributes won't fire if the module was loaded via "eval". I might try another swing at fixing this in the future (via require and a path in Test::Class::Moose::Load?), but for now, if you can't load Sub::Attribute, a warning will be issued and your tag filters will be ignored.

Patches welcome for improving this feature (there are many things which can be done here), but for now, this is the last major piece really needed to make this the goto module for many large test suites.

About Ovid

user-pic Freelance Perl/Testing/Agile consultant and trainer. See http://www.allaroundtheworld.fr/ for our services. If you have a problem with Perl, we will solve it for you. And don't forget to buy my book! http://www.amazon.com/Beginning-Perl-Curtis-Poe/dp/1118013840/