This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Pod::LaTeX 0.57
[perl5.git] / lib / Config.t
CommitLineData
a48f8c77
MS
1#!./perl
2
41aba5b7
JH
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require "./test.pl";
7}
8
4a305f6a 9plan tests => 46;
41aba5b7
JH
10
11use_ok('Config');
12
13# Some (safe?) bets.
14
484fdf61 15ok(keys %Config > 500, "Config has more than 500 entries");
41aba5b7
JH
16
17ok(each %Config);
18
19is($Config{PERL_REVISION}, 5, "PERL_REVISION is 5");
20
d10bb151
MS
21# Check that old config variable names are aliased to their new ones.
22my %grandfathers = ( PERL_VERSION => 'PATCHLEVEL',
23 PERL_SUBVERSION => 'SUBVERSION',
24 PERL_CONFIG_SH => 'CONFIG'
25 );
26while( my($new, $old) = each %grandfathers ) {
27 isnt($Config{$new}, undef, "$new is defined");
28 is($Config{$new}, $Config{$old}, "$new is aliased to $old");
29}
30
41aba5b7
JH
31ok( exists $Config{cc}, "has cc");
32
33ok( exists $Config{ccflags}, "has ccflags");
34
35ok(!exists $Config{python}, "has no python");
36
37ok( exists $Config{d_fork}, "has d_fork");
38
39ok(!exists $Config{d_bork}, "has no d_bork");
40
7956ade2
JH
41like($Config{ivsize}, qr/^(4|8)$/, "ivsize is 4 or 8 (it is $Config{ivsize})");
42
41aba5b7
JH
43# byteorder is virtual, but it has rules.
44
7956ade2 45like($Config{byteorder}, qr/^(1234|4321|12345678|87654321)$/, "byteorder is 1234 or 4321 or 12345678 or 87654321 (it is $Config{byteorder})");
41aba5b7 46
7956ade2 47is(length $Config{byteorder}, $Config{ivsize}, "byteorder is as long as ivsize (which is $Config{ivsize})");
41aba5b7
JH
48
49# ccflags_nolargefiles is virtual, too.
50
51ok(exists $Config{ccflags_nolargefiles}, "has ccflags_nolargefiles");
52
53# Utility functions.
54
a48f8c77
MS
55{
56 # make sure we can export what we say we can export.
57 package Foo;
58 my @exports = qw(myconfig config_sh config_vars config_re);
59 Config->import(@exports);
60 foreach my $func (@exports) {
61 ::ok( __PACKAGE__->can($func), "$func exported" );
62 }
6664971e 63}
41aba5b7 64
9d60fda3
NC
65like(Config::myconfig(), qr/osname=\Q$Config{osname}\E/, "myconfig");
66like(Config::config_sh(), qr/osname='\Q$Config{osname}\E'/, "config_sh");
a48f8c77
MS
67like(join("\n", Config::config_re('c.*')),
68 qr/^c.*?=/, 'config_re' );
69
41aba5b7
JH
70my $out = tie *STDOUT, 'FakeOut';
71
72Config::config_vars('cc');
73my $out1 = $$out;
74$out->clear;
75
76Config::config_vars('d_bork');
77my $out2 = $$out;
78$out->clear;
79
4a305f6a
JC
80Config::config_vars('PERL_API_.*');
81my $out3 = $$out;
82$out->clear;
83
84Config::config_vars(':PERL_API_.*:');
85my $out4 = $$out;
86$out->clear;
41aba5b7 87
4a305f6a
JC
88Config::config_vars(':PERL_API_REVISION:');
89my $out5 = $$out;
90$out->clear;
91
92untie *STDOUT;
9d60fda3 93like($out1, qr/^cc='\Q$Config{cc}\E';/, "config_vars cc");
41aba5b7
JH
94like($out2, qr/^d_bork='UNKNOWN';/, "config_vars d_bork is UNKNOWN");
95
4a305f6a
JC
96is(3, scalar split(/\n/, $out3), "3 PERL_API vars found");
97my @api = $out3 =~ /^PERL_API_(\w+)=(.*);/mg;
98is("'5'", $api[1], "1st is 5");
99is("'9'", $api[5], "2nd is 9");
100is("'1'", $api[3], "3rd is 1");
101@api = split(/ /, $out4);
102is(3, @api, "trailing colon puts 3 terms on same line");
103unlike($out4, qr/=/, "leading colon suppresses param names");
104is("'5'", $api[0], "revision is 5");
105is("'9'", $api[2], "version is 9");
106is("'1'", $api[1], "subversion is 1");
107
108is("'5' ", $out5, "leading and trailing colons return just the value");
41aba5b7
JH
109# Read-only.
110
7956ade2 111undef $@;
41aba5b7
JH
112eval { $Config{d_bork} = 'borkbork' };
113like($@, qr/Config is read-only/, "no STORE");
114
7956ade2
JH
115ok(!exists $Config{d_bork}, "still no d_bork");
116
117undef $@;
41aba5b7
JH
118eval { delete $Config{d_fork} };
119like($@, qr/Config is read-only/, "no DELETE");
120
7956ade2
JH
121ok( exists $Config{d_fork}, "still d_fork");
122
123undef $@;
41aba5b7
JH
124eval { %Config = () };
125like($@, qr/Config is read-only/, "no CLEAR");
126
7956ade2
JH
127ok( exists $Config{d_fork}, "still d_fork");
128
059ca955
RGS
129{
130 package FakeOut;
41aba5b7 131
059ca955
RGS
132 sub TIEHANDLE {
133 bless(\(my $text), $_[0]);
134 }
41aba5b7 135
059ca955
RGS
136 sub clear {
137 ${ $_[0] } = '';
138 }
41aba5b7 139
059ca955
RGS
140 sub PRINT {
141 my $self = shift;
142 $$self .= join('', @_);
143 }
41aba5b7
JH
144}
145
059ca955
RGS
146# Signal-related variables
147# (this is actually a regression test for Configure.)
148
b25be8c8
JH
149is($Config{sig_num_init} =~ tr/,/,/, $Config{sig_size}, "sig_num_init size");
150is($Config{sig_name_init} =~ tr/,/,/, $Config{sig_size}, "sig_name_init size");