test_requires_git to replace has_git

About a year ago, a few weeks after the Perl QA Hackathon 2015, I started hacking on Test::Requires::Git, as part of my on-going colonization of the Git-related namespaces in CPAN. The idea was suggested by DOLMEN, who also told me to look at Test::Requires for inspiration.

It's now time for test_requires_git to replace has_git.

has_git was introduced in November 2010 as the first function in Test::Git. It skips the entire test script if the minimum Git version (if any) required is not available: Test::Git is shipped as part of the Git-Repository distribution.

use Test::Git;
has_git('1.6.5');

Test::Requires::Git offers a lot more flexibility, like the ability to skip a specific number of tests, or the rest of the test script (not just the script as a whole). It also support the total set of Git version comparison operators (as provided by Git::Version::Compare. The equivalent of the above is written as follows:

use Test::Requires::Git;
test_requires_git version_ge => '1.6.5';

A few weeks ago, I started thinking seriously about deprecating has_git, and started to replace its use in my own test scripts. I was seriously annoyed that I had to specify version_ge each time.

Therefore, in the latest version of Test::Requires::Git (1.005), I have added a shortcut for the most common use case (the only one that has_git supports). And so you can replace the first code snippet I showed by this one:

use Test::Requires::Git;
test_requires_git '1.6.5';

And you can also be a lot more flexible, like this:

SKIP: {
    test_requires_git version_ge => '1.6.5', version_lt => '1.8.0', skip => 4;
    # four tests here
}

And since version_ge basically became optional, you could write the above as follows (although I find it a bit confusing):

SKIP: {
    test_requires_git '1.6.5', version_lt => '1.8.0', skip => 4;
    # four tests here
}

The Test::Git included in the next Git-Repository release will still provide has_git, but it will emit a warning pointing to the test_requires_git replacement. I'll probably remove has_git entirely once I can't find used anywhere on CPAN.

In the mean time, I've decided to submit pull requests to the 32 CPAN modules using has_git.

Only two of them are not on GitHub, so I'll also email the authors directly.

Leave a comment

About BooK

user-pic Pink.