Enhance the caveat in the description of tell()
[p5sagit/p5-mst-13.2.git] / lib / Config.t
CommitLineData
a48f8c77 1#!./perl
2
41aba5b7 3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require "./test.pl";
7}
8
8d871aab 9plan 'no_plan';
41aba5b7 10
11use_ok('Config');
12
13# Some (safe?) bets.
14
484fdf61 15ok(keys %Config > 500, "Config has more than 500 entries");
41aba5b7 16
17ok(each %Config);
18
19is($Config{PERL_REVISION}, 5, "PERL_REVISION is 5");
20
d10bb151 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 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 41like($Config{ivsize}, qr/^(4|8)$/, "ivsize is 4 or 8 (it is $Config{ivsize})");
42
8d871aab 43# byteorder is virtual, but it has rules.
41aba5b7 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 48
49# ccflags_nolargefiles is virtual, too.
50
51ok(exists $Config{ccflags_nolargefiles}, "has ccflags_nolargefiles");
52
53# Utility functions.
54
a48f8c77 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
8468119f 65like(Config::myconfig(), qr/osname=\Q$Config{osname}\E/, "myconfig");
66like(Config::config_sh(), qr/osname='\Q$Config{osname}\E'/, "config_sh");
67like(Config::config_sh(), qr/byteorder='[1-8]+'/,
68 "config_sh has a valid byteorder");
8d871aab 69foreach my $line (Config::config_re('c.*')) {
70 like($line, qr/^c.*?=.*$/, 'config_re' );
71}
a48f8c77 72
41aba5b7 73my $out = tie *STDOUT, 'FakeOut';
74
75Config::config_vars('cc');
76my $out1 = $$out;
77$out->clear;
78
79Config::config_vars('d_bork');
80my $out2 = $$out;
81$out->clear;
82
4a305f6a 83Config::config_vars('PERL_API_.*');
84my $out3 = $$out;
85$out->clear;
86
87Config::config_vars(':PERL_API_.*:');
88my $out4 = $$out;
89$out->clear;
41aba5b7 90
4a305f6a 91Config::config_vars(':PERL_API_REVISION:');
92my $out5 = $$out;
93$out->clear;
94
0c6e7072 95Config::config_vars('?flags');
96my $out6 = $$out;
97$out->clear;
98
4a305f6a 99untie *STDOUT;
9d60fda3 100like($out1, qr/^cc='\Q$Config{cc}\E';/, "config_vars cc");
41aba5b7 101like($out2, qr/^d_bork='UNKNOWN';/, "config_vars d_bork is UNKNOWN");
102
4a305f6a 103is(3, scalar split(/\n/, $out3), "3 PERL_API vars found");
104my @api = $out3 =~ /^PERL_API_(\w+)=(.*);/mg;
105is("'5'", $api[1], "1st is 5");
106is("'9'", $api[5], "2nd is 9");
107is("'1'", $api[3], "3rd is 1");
108@api = split(/ /, $out4);
109is(3, @api, "trailing colon puts 3 terms on same line");
110unlike($out4, qr/=/, "leading colon suppresses param names");
111is("'5'", $api[0], "revision is 5");
112is("'9'", $api[2], "version is 9");
113is("'1'", $api[1], "subversion is 1");
114
115is("'5' ", $out5, "leading and trailing colons return just the value");
0c6e7072 116
117like($out6, qr/\bnot\s+found\b/, "config_vars with invalid regexp");
118
41aba5b7 119# Read-only.
120
7956ade2 121undef $@;
41aba5b7 122eval { $Config{d_bork} = 'borkbork' };
123like($@, qr/Config is read-only/, "no STORE");
124
7956ade2 125ok(!exists $Config{d_bork}, "still no d_bork");
126
127undef $@;
41aba5b7 128eval { delete $Config{d_fork} };
129like($@, qr/Config is read-only/, "no DELETE");
130
7956ade2 131ok( exists $Config{d_fork}, "still d_fork");
132
133undef $@;
41aba5b7 134eval { %Config = () };
135like($@, qr/Config is read-only/, "no CLEAR");
136
7956ade2 137ok( exists $Config{d_fork}, "still d_fork");
138
059ca955 139{
140 package FakeOut;
41aba5b7 141
059ca955 142 sub TIEHANDLE {
143 bless(\(my $text), $_[0]);
144 }
41aba5b7 145
059ca955 146 sub clear {
147 ${ $_[0] } = '';
148 }
41aba5b7 149
059ca955 150 sub PRINT {
151 my $self = shift;
152 $$self .= join('', @_);
153 }
41aba5b7 154}
155
059ca955 156# Signal-related variables
157# (this is actually a regression test for Configure.)
158
b25be8c8 159is($Config{sig_num_init} =~ tr/,/,/, $Config{sig_size}, "sig_num_init size");
160is($Config{sig_name_init} =~ tr/,/,/, $Config{sig_size}, "sig_name_init size");
8468119f 161
162# Test the troublesome virtual stuff
163foreach my $pain (qw(byteorder)) {
164 # No config var is named with anything that is a regexp metachar"
165 my @result = Config::config_re($pain);
166 is (scalar @result, 1, "single result for config_re('$pain')");
167 like ($result[0], qr/^$pain=(['"])$Config{$pain}\1$/, # grr '
168 "which is the expected result for $pain");
169}