1HasVersion(3) User Contributed Perl Documentation HasVersion(3)
2
3
4
6 Test::HasVersion - Check Perl modules have version numbers
7
9 "Test::HasVersion" lets you check a Perl module has a version number in
10 a "Test::Simple" fashion.
11
12 use Test::HasVersion tests => 1;
13 pm_version_ok("M.pm", "Valid version");
14
15 Module authors can include the following in a t/has_version.t file and
16 let "Test::HasVersion" find and check all installable PM files in a
17 distribution.
18
19 use Test::More;
20 eval "use Test::HasVersion";
21 plan skip_all =>
22 'Test::HasVersion required for testing for version numbers' if $@;
23 all_pm_version_ok();
24
26 Do you wanna check that every one of your Perl modules in a
27 distribution has a version number? You wanna make sure you don't forget
28 the brand new modules you just added? Well, that's the module you have
29 been looking for. Use it!
30
31 Do you wanna check someone else's distribution to make sure the author
32 have not committed the sin of leaving Perl modules without a version
33 that can be used to tell if you have this or that feature?
34 "Test::HasVersion" is also for you, nasty little fellow.
35
36 There's a script test_version which is installed with this
37 distribution. You may invoke it from within the root directory of a
38 distribution you just unpacked, and it will check every .pm file in the
39 directory and under lib/ (if any).
40
41 $ test_version
42
43 You may also provide directories and files as arguments.
44
45 $ test_version *.pm lib/ inc/
46 $ test_version .
47
48 (Be warned that many Perl modules in a t/ directory do not receive
49 versions because they are not used outside the distribution.)
50
51 Ok. That's not a very useful module by now. But it will be. Wait for
52 the upcoming releases.
53
54 FUNCTIONS
55 PRIVATE _pm_version
56 $v = _pm_version($pm);
57
58 Parses a PM file and return what it thinks is $VERSION in this
59 file. (Actually implemented with "use ExtUtils::MakeMaker;
60 MM->parse_version($file)".) $pm is the filename (eg.,
61 lib/Data/Dumper.pm).
62
63 pm_version_ok
64 pm_version_ok('Module.pm');
65 pm_version_ok('M.pm', 'Has valid version');
66
67 Checks to see if the given file has a valid version. Actually a
68 valid version number is defined and not equal to 'undef' (the
69 string) which is return by "_pm_version" if a version cannot be
70 determined.
71
72 all_pm_version_ok
73 all_pm_version_ok();
74 all_pm_version_ok(@PM_FILES);
75
76 Checks every given file and .pm files found under given directories
77 to see if they provide valid version numbers. If no argument is
78 given, it defaults to check every file *.pm in the current
79 directory and recurses under the lib/ directory (if it exists).
80
81 If no test plan was setted, "Test::HasVersion" will set one after
82 computing the number of files to be tested. Otherwise, the plan is
83 left untouched.
84
85 PRIVATE _list_pm_files
86 @pm_files = _list_pm_files(@dirs);
87
88 Returns all PM files under the given directories.
89
90 all_pm_files
91 @files = all_pm_files()
92 @files = all_pm_files(@files_and_dirs);
93
94 Implements finding the Perl modules according to the semantics of
95 the previous function "all_pm_version_ok".
96
98 Other usage patterns besides the ones given in the synopsis.
99
100 use Test::More tests => $num_tests;
101 use Test::HasVersion;
102 pm_version_ok($file1);
103 pm_version_ok($file2);
104
105 Obviously, you can't plan twice.
106
107 use Test::More;
108 use Test::HasVersion;
109 plan tests => $num_tests;
110 pm_version_ok($file);
111
112 "plan" comes from "Test::More".
113
114 use Test::More;
115 use Test::HasVersion;
116 plan 'no_plan';
117 pm_version_ok($file);
118
119 "no_plan" is ok either.
120
122 Test::Version
123
124 Please reports bugs via CPAN RT,
125 http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-HasVersion
126
128 A. R. Ferreira, <ferreira@cpan.org>
129
131 Copyright (C) 2006, 2016 by Adriano R. Ferreira
132
133 This library is free software; you can redistribute it and/or modify it
134 under the same terms as Perl itself.
135
136
137
138perl v5.34.0 2021-07-23 HasVersion(3)