Debian Codegraph @

t/is_core.t

raw
1 #!perl -w
2 use strict;
3 use Module::CoreList;
4 use Test::More tests => 44;
5
6 BEGIN { require_ok('Module::CoreList'); }
7
8 # Check that there is a release entry for the current perl version
9 my $released = $Module::CoreList::released{ $] };
10 # duplicate fetch to avoid 'used only once: possible typo' warning
11 $released = $Module::CoreList::released{ $] };
12
13 # Check default perl
14
15 SKIP: {
16 skip 'CPAN release being tested aginst blead', 1 unless $released;
17 ok(Module::CoreList::is_core('IO::File', $Module::CoreList::version{$]}{'IO::File'}), "is_core is self-consistent");
18 }
19
20 ok(!Module::CoreList::is_core('Module::Path'), 'Module::Path has never been in core');
21 ok(!Module::CoreList::is_core('Module::Path', undef, '5.016003'), 'Module::Path has never been in core');
22 ok(!Module::CoreList::is_core('Module::Path', undef), 'Module::Path has never been in core');
23
24 # List::Util::PP was added in 5.010001 and removed in 5.017001
25 ok(!Module::CoreList::is_core('List::Util::PP', undef, '5.002'), 'List::Util::PP was added in 5.10.1 so not in core in 5.002');
26 ok(Module::CoreList::is_core('List::Util::PP', undef, '5.016003'), 'List::Util::PP was in core in 5.16.3');
27 ok(!Module::CoreList::is_core('List::Util::PP', undef, '5.018001'), 'List::Util::PP was removed in 5.17.1 so not in core in 5.18.1');
28
29 # Carp has always been a core module
30 ok(Module::CoreList::is_core('Carp', undef, '5'), 'Carp was a core module in first release of perl 5');
31 ok(Module::CoreList::is_core('Carp', undef, '5.019004'), 'Carp was still a core module in 5.19.4');
32
33 SKIP: {
34 skip 'CPAN release being tested aginst blead', 1 unless $released;
35 ok(Module::CoreList::is_core('Carp'), "Carp should be a core module whatever version of perl you're running");
36 }
37
38 ok(Module::CoreList::is_core('attributes', undef, '5.00503') == 0, "attributes weren't in 5.00503");
39 ok(Module::CoreList::is_core('attributes', undef, '5.006001') == 1, "attributes were in 5.6.1");
40 ok(Module::CoreList::is_core('Pod::Plainer', undef, '5.012001') == 1, "Pod::Plainer was core in 5.12.1");
41 ok(Module::CoreList::is_core('Pod::Plainer', undef, '5.016003') == 0, "Pod::Plainer was removed in 5.13.1");
42
43 ok(!Module::CoreList::is_core('File::Temp', 0, '5.006'), 'File::Temp is not in 5.006000');
44 ok(Module::CoreList::is_core('File::Temp', 0, '5.006001'), 'File::Temp is in 5.006001');
45 ok(!Module::CoreList::is_core('File::Temp', '0.12', '5.006'), 'File::Temp 0.12 is not in 5.006000');
46 ok(Module::CoreList::is_core('File::Temp', '0.12', '5.006001'), 'File::Temp 0.12 is in 5.006001');
47 ok(Module::CoreList::is_core('File::Temp', '0.12', '5.006002'), 'File::Temp 0.12 is in 5.006002');
48
49
50 # history of module 'encoding' in core
51 # version 1.00 included in 5.007003
52 # version 1.35 included in 5.008
53 # version 1.47 included in 5.008001
54 # version 1.48 included in 5.008003
55 # version 2.00 included in 5.008005
56 # version 2.01 included in 5.008006
57 # version 2.02 included in 5.008008
58 # version 2.6_01 included in 5.008009
59 # version 2.04 included in 5.009004
60 # version 2.06 included in 5.009005
61 # version 2.6_01 included in 5.010001
62 # version 2.12 included in 5.019001
63
64 ok(!Module::CoreList::is_core('encoding', undef, '5'), "encoding wasn't in core in first release of perl 5");
65 ok(!Module::CoreList::is_core('encoding', '1.00', '5'), "encoding 1.00 wasn't in core in first release of perl 5");
66 ok(!Module::CoreList::is_core('encoding', '1.35', '5.007003'), "encoding 1.35 wasn't yet in core in perl 5.007003");
67 ok(Module::CoreList::is_core('encoding', '1.35', '5.008'), "encoding 1.35 was first included in perl 5.008");
68 ok(Module::CoreList::is_core('encoding', '1.35', '5.009004'), "encoding 2.04 (>1.35) was included in 5.009004");
69 ok(Module::CoreList::is_core('encoding', '2.01', '5.008007'), "encoding 2.01 was first in core in perl 5.008006, so was core in 5.8.7");
70 ok(Module::CoreList->is_core('encoding', '2.01', '5.008007'), "encoding 2.01 was first in core in perl 5.008006, so was core in 5.8.7");
71
72 # Module::CoreList (2.17) was first included in 5.008009
73 ok(!Module::CoreList::is_core('Module::CoreList', undef, '5.007003'), "Module::CoreList wasn't core in perl 5.7.3");
74 ok(!Module::CoreList->is_core('Module::CoreList', undef, '5.007003'), "Module::CoreList wasn't core in perl 5.7.3 (class method)");
75
76 # Test for situations where different branches on the perl
77 # release tree had different versions of a module, and a naive
78 # checking of perl release number will trip you up
79 ok(Module::CoreList->is_core('Text::Soundex', '1.01', '5.008007'), "Text::Soundex 1.01 was first included in 5.007003");
80 ok(Module::CoreList->is_core('Text::Soundex', '3.03', '5.008009'), "Text::Soundex 3.03 was included in 5.008009");
81 ok(!Module::CoreList->is_core('Text::Soundex', '3.03', '5.009003'), "5.009003 still had Text::Soundex 1.01");
82 ok(Module::CoreList->is_core('Text::Soundex', '1.01', '5.009003'), "5.009003 still had Text::Soundex 1.01");
83 ok(!Module::CoreList->is_core('Text::Soundex', '3.03', '5.009005'), "5.009005 still had Text::Soundex 3.02");
84 ok(Module::CoreList->is_core('Text::Soundex', '3.02', '5.009005'), "5.009005 had Text::Soundex 3.02");
85 ok(Module::CoreList->is_core('Text::Soundex', '3.03', '5.01'), "5.01 had Text::Soundex 3.03");
86
87 # 5.002 was the first perl release where core modules had a version number
88 ok(Module::CoreList->is_core('DB_File', '1.01', '5.002'), "DB_File 1.01 was included in 5.002");
89 ok(!Module::CoreList->is_core('DB_File', '1.03', '5.002'), "DB_File 1.03 wasn't included in 5.002");
90 ok(Module::CoreList->is_core('DB_File', '1.03', '5.00307'), "DB_File 1.03 was included in 5.00307");
91
92 ok(! Module::CoreList->is_core("CGI", undef, 5.021), "CGI not in 5.021");
93 ok(! Module::CoreList->is_core("CGI", undef, 5.021001), "CGI not in 5.021001");
94
95 ok( Module::CoreList::is_core("Config", 0, "5.020"), "Config v0+ is in core in 5.020");
96 ok( Module::CoreList::is_core("Config", undef, "5.020"), "Config v(undef) is in core in 5.020");
97
98 eval { Module::CoreList::is_core('Config', 'invalid', '5.020'); };
99 like( $@, qr/^Invalid version 'invalid' specified\b/, 'invalid version throws');