1Test::Requires::Git(3)User Contributed Perl DocumentationTest::Requires::Git(3)
2
3
4
6 Test::Requires::Git - Check your test requirements against the
7 available version of Git
8
10 # will skip all if git is not available
11 use Test::Requires::Git;
12
13 # needs some git that supports `git init $dir`
14 test_requires_git version_ge => '1.6.5';
15
17 Test::Requires::Git checks if the version of Git available for testing
18 meets the given requirements. If the checks fail, then all tests will
19 be skipped.
20
21 "use Test::Requires::Git" always calls "test_requires_git" with the
22 given arguments. If you don't want "test_requires_git" to be called at
23 import time, write this instead:
24
25 use Test::Requires::Git -nocheck;
26
27 Passing the "git" parameter (see "test_requires_git" below) to "use
28 Test::Requires::Git" will override it for the rest of the program run.
29
31 test_requires_git
32 # skip all unless git is available as required
33 test_requires_git version_ge => '1.6.5';
34
35 # giving no operator implies 'version_ge'
36 test_requires_git '1.6.5';
37
38 # skip 2 if git is not available
39 SKIP: {
40 test_requires_git skip => 2;
41 ...;
42 }
43
44 # skip 2 unless git is available as required
45 SKIP: {
46 test_requires_git
47 skip => 2,
48 version_ge => '1.7.12';
49 ...;
50 }
51
52 # skip all remaining tests if git is not available
53 test_requires_git;
54
55 # force which git binary to use
56 test_requires_git
57 git => '/usr/local/bin/git',
58 version_ge => '1.6.5';
59
60 Takes a list of version requirements (see "GIT VERSION CHECKING"
61 below), and if one of them does not pass, skips all remaining tests.
62 All conditions must be satisfied for the check to pass.
63
64 When the "skip" parameter is given, only the specified number of tests
65 will be skipped.
66
67 The "current git" is obtained by running "git --version". I.e. the
68 first "git" binary found in the current environment will be tested.
69 This is of course sensitive to local changes to "PATH", so this will
70 behave as expected:
71
72 # skip 4 tests if there's no git available in the alternative PATH
73 SKIP: {
74 local $ENV{PATH} = $alternative_PATH;
75 test_requires_git skip => 4;
76 ...;
77 }
78
79 When the "git" parameter is given, "test_requires_git" will run that
80 program instead of "git".
81
82 If no condition is given, "test_requires_git" will simply check if
83 "git" is available.
84
85 The first time it's called, "test_require_git" will print a test
86 diagnostic with the output of "git --version" (if "git" is available,
87 of course). To prevent this behaviour, load the module with:
88
89 use Test::Requires::Git -quiet;
90
92 The actual comparison is handled by Git::Version::Compare, so the
93 strings can be version numbers, tags from "git.git" or the output of
94 "git version" or "git describe".
95
96 The following version checks are currently supported:
97
98 version_eq
99 Aliases: "version_eq", "eq", "==", "version".
100
101 test_requires_git version_eq => $version;
102
103 Passes if the current git version is equal to $version.
104
105 version_ne
106 Aliases: "version_ne", "ne", "!=".
107
108 test_requires_git version_eq => $version;
109
110 Passes if the current git version is not equal to $version.
111
112 version_lt
113 Aliases: "version_lt", "lt", "<".
114
115 test_requires_git version_lt => $version;
116
117 Passes if the current git version is less than $version.
118
119 version_gt
120 Aliases: "version_gt", "gt", ">".
121
122 test_requires_git version_gt => $version;
123
124 Passes if the current git version is greater than $version.
125
126 version_le
127 Aliases: "version_le", "le", "<=".
128
129 test_requires_git version_le => $version;
130
131 Passes if the current git version is less than or equal $version.
132
133 version_ge
134 Aliases: "version_ge", "ge", ">=".
135
136 test_requires_git version_ge => $version;
137
138 Passes if the current git version is greater than or equal $version.
139
140 As a special shortcut for the most common case, a lone version number
141 is turned into a "version_ge" check, so the following two lines are
142 exactly equivalent:
143
144 test_requires_git version_ge => '1.6.5';
145
146 # version_ge implied
147 test_requires_git '1.6.5';
148
150 Test::Requires, Git::Version::Compare.
151
153 Thanks to Oliver Mengué (DOLMEN), who gave me the idea for this module
154 at the Perl QA Hackathon 2015 in Berlin, and suggested to give a look
155 at Test::Requires for inspiration.
156
158 Philippe Bruhat (BooK), <book@cpan.org>.
159
161 Copyright 2015-2016 Philippe Bruhat (BooK), all rights reserved.
162
164 This program is free software; you can redistribute it and/or modify it
165 under the same terms as Perl itself.
166
167
168
169perl v5.30.1 2020-01-30 Test::Requires::Git(3)