Test::...es::Git(3pm)
okay bestie, welcome to Test::...es::Git(3pm) β straight out of the User Contributed Perl Documentation, and yes we are reading a manpage for fun now, this is who we are π
πΈ NAME πΈ
Test::Requires::Git β check your test requirements against the available version of Git π¦
Like, it literally does a vibe check on your Git before your tests even start. No cap.
β¨ SYNOPSIS β¨
# will skip all if git is not available
use Test::Requires::Git;
# needs some git that supports `git init $dir`
test_requires_git version_ge => '1.6.5';
π DESCRIPTION π
So Test::Requires::Git checks whether the version of Git you've got available for testing actually meets the requirements you're asking for. If the checks fail? Every single test gets skipped. All of them. Gone. Periodt. π
use Test::Requires::Git always calls test_requires_git with whatever arguments you handed it. And if you do not want test_requires_git getting called at import time (respect, honestly), you write this instead:
use Test::Requires::Git -nocheck;
And if you pass the git parameter (peep test_requires_git below π) to use Test::Requires::Git, it overrides it for the rest of the program run. Like, the whole rest of the run. Commit to it.
π EXPORTED FUNCTIONS π
test_requires_git
# skip all unless git is available as required
test_requires_git version_ge => '1.6.5';
# giving no operator implies 'version_ge'
test_requires_git '1.6.5';
# skip 2 if git is not available
SKIP: {
test_requires_git skip => 2;
...;
}
# skip 2 unless git is available as required
SKIP: {
test_requires_git
skip => 2,
version_ge => '1.7.12';
...;
}
# skip all remaining tests if git is not available
test_requires_git;
# force which git binary to use
test_requires_git
git => '/usr/local/bin/git',
version_ge => '1.6.5';
So here's the tea π β you hand it a list of version requirements (the deets are in "GIT VERSION CHECKING" below), and if even one of them doesn't pass, it skips all the remaining tests. Every condition has to be satisfied for the check to pass. All of them. It's giving strict.
When you give it the skip parameter, only that specific number of tests gets skipped. Just those. Iconic.
The "current git" is obtained by running git --version. Which means: the first git binary it finds in the current environment is the one getting tested. And yes, that is of course sensitive to local changes to PATH β so this behaves exactly how you'd expect:
# skip 4 tests if there's no git available in the alternative PATH
SKIP: {
local $ENV{PATH} = $alternative_PATH;
test_requires_git skip => 4;
...;
}
When you give it the git parameter, test_requires_git will run that program instead of git. You're the one picking the main character now π
If you give it no condition at all, test_requires_git will simply check if git is available. Low effort, high reward.
The first time it's called, test_require_git will print a test diagnostic with the output of git --version β assuming git is available, of course π. (Yes, it's spelled test_require_git right there in the original. We don't fix it, we respect it. π
) And if you want to prevent that behaviour entirely, load the module with:
use Test::Requires::Git -quiet;
π GIT VERSION CHECKING π
The actual comparison is handled by Git::Version::Compare, so the strings you pass can be version numbers, tags from git.git, or the output of git version or git describe. Flexible fr fr.
These are the version checks currently supported:
version_eq
Aliases: version_eq, eq, ==, version.
test_requires_git version_eq => $version;
Passes if the current git version is equal to $version.
version_ne
Aliases: version_ne, ne, !=.
test_requires_git version_eq => $version;
Passes if the current git version is not equal to $version. (And yep β that example above is written exactly like that in the original. Copying it character for character, bestie, that's the rule π«Ά)
version_lt
Aliases: version_lt, lt, <.
test_requires_git version_lt => $version;
Passes if the current git version is less than $version.
version_gt
Aliases: version_gt, gt, >.
test_requires_git version_gt => $version;
Passes if the current git version is greater than $version.
version_le
Aliases: version_le, le, <=.
test_requires_git version_le => $version;
Passes if the current git version is less than or equal $version.
version_ge
Aliases: version_ge, ge, >=.
test_requires_git version_ge => $version;
Passes if the current git version is greater than or equal $version.
And as a special shortcut for the most common case, a lone version number gets turned into a version_ge check β so these two lines are exactly equivalent:
test_requires_git version_ge => '1.6.5';
# version_ge implied
test_requires_git '1.6.5';
π SEE ALSO π
Test::Requires, Git::Version::Compare.
Go read them, iykyk π
π«Ά ACKNOWLEDGEMENTS π«Ά
Thanks to Oliver MenguΓ© (DOLMEN), who gave me the idea for this module at the Perl QA Hackathon 2015 in Berlin, and suggested to give a look at Test::Requires for inspiration. Genuinely so sweet of him, we love a supportive icon π
π AUTHOR π
Philippe Bruhat (BooK), <book@cpan.org>.
π COPYRIGHT π
Copyright 2015-2016 Philippe Bruhat (BooK), all rights reserved.
β LICENSE β
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Slay, legally speaking.
okay that's the whole page, bestie β and for the record, this little masterpiece is from perl v5.34.0, dated 2022-06-28, and it's the Test::...es::Git(3pm) manpage β¨ go forth and skip your tests responsibly π
π¦ where this page comes from
- debian bookworm: libtest-requires-git-perl 1.008-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtest-requires-git-perl 1.008-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtest-requires-git-perl 1.008-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-requires-git-perl 1.008-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-requires-git-perl 1.008-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms