Upgrade to Encode 2.08.
[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
307dc113 75Config::config_vars('cc'); # non-regex test of essential cfg-var
41aba5b7 76my $out1 = $$out;
77$out->clear;
78
307dc113 79Config::config_vars('d_bork'); # non-regex, non-existent cfg-var
41aba5b7 80my $out2 = $$out;
81$out->clear;
82
307dc113 83Config::config_vars('PERL_API_.*'); # regex, tagged multi-line answer
4a305f6a 84my $out3 = $$out;
85$out->clear;
86
307dc113 87Config::config_vars('PERL_API_.*:'); # regex, tagged single-line answer
4a305f6a 88my $out4 = $$out;
89$out->clear;
41aba5b7 90
307dc113 91Config::config_vars(':PERL_API_.*:'); # regex, non-tagged single-line answer
4a305f6a 92my $out5 = $$out;
93$out->clear;
94
307dc113 95Config::config_vars(':PERL_API_.*'); # regex, non-tagged multi-line answer
0c6e7072 96my $out6 = $$out;
97$out->clear;
98
307dc113 99Config::config_vars('PERL_API_REVISION.*:'); # regex, tagged
100my $out7 = $$out;
101$out->clear;
102
103Config::config_vars(':PERL_API_REVISION.*'); # regex, non-tagged multi-line answer
104my $out8 = $$out;
105$out->clear;
106
107Config::config_vars('PERL_EXPENSIVE_.*:'); # non-matching regex
108my $out9 = $$out;
109$out->clear;
110
111Config::config_vars('?flags'); # bogus regex, no explicit warning !
112my $out10 = $$out;
113$out->clear;
114
4a305f6a 115untie *STDOUT;
307dc113 116
117like($out1, qr/^cc='\Q$Config{cc}\E';/, "found config_var cc");
118like($out2, qr/^d_bork='UNKNOWN';/, "config_var d_bork is UNKNOWN");
119
120# test for leading, trailing colon effects
121is(scalar split(/;\n/, $out3), 3, "3 lines found");
122is(scalar split(/;\n/, $out6), 3, "3 lines found");
123
124is($out4 =~ /(;\n)/s, '', "trailing colon gives 1-line response: $out4");
125is($out5 =~ /(;\n)/s, '', "trailing colon gives 1-line response: $out5");
126
127is(scalar split(/=/, $out3), 4, "found 'tag='");
128is(scalar split(/=/, $out4), 4, "found 'tag='");
129
130my @api;
131
132my @rev = @Config{qw(PERL_API_REVISION PERL_API_VERSION PERL_API_SUBVERSION)};
133
134print ("# test tagged responses, multi-line and single-line\n");
135foreach $api ($out3, $out4) {
136 @api = $api =~ /PERL_API_(\w+)=(.*?)(?:;\n|\s)/mg;
137 is($api[0], "REVISION", "REVISION tag");
138 is($api[4], "VERSION", "VERSION tag");
139 is($api[2], "SUBVERSION", "SUBVERSION tag");
140 is($api[1], "'$rev[0]'", "REVISION is $rev[0]");
141 is($api[5], "'$rev[1]'", "VERSION is $rev[1]");
142 is($api[3], "'$rev[2]'", "SUBVERSION is $rev[2]");
143}
144
145print("# test non-tagged responses, multi-line and single-line\n");
146foreach $api ($out5, $out6) {
147 @api = split /(?: |;\n)/, $api;
148 is($api[0], "'$rev[0]'", "revision is $rev[0]");
149 is($api[2], "'$rev[1]'", "version is $rev[1]");
150 is($api[1], "'$rev[2]'", "subversion is $rev[2]");
151}
152
153# compare to each other, the outputs for trailing, leading colon
154$out7 =~ s/ $//;
155is("$out7;\n", "PERL_API_REVISION=$out8", "got expected diffs");
156
157like($out9, qr/\bnot\s+found\b/, "$out9 - perl is FREE !");
158like($out10, qr/\bnot\s+found\b/, "config_vars with invalid regexp");
0c6e7072 159
41aba5b7 160# Read-only.
161
7956ade2 162undef $@;
41aba5b7 163eval { $Config{d_bork} = 'borkbork' };
164like($@, qr/Config is read-only/, "no STORE");
165
7956ade2 166ok(!exists $Config{d_bork}, "still no d_bork");
167
168undef $@;
41aba5b7 169eval { delete $Config{d_fork} };
170like($@, qr/Config is read-only/, "no DELETE");
171
7956ade2 172ok( exists $Config{d_fork}, "still d_fork");
173
174undef $@;
41aba5b7 175eval { %Config = () };
176like($@, qr/Config is read-only/, "no CLEAR");
177
7956ade2 178ok( exists $Config{d_fork}, "still d_fork");
179
059ca955 180{
181 package FakeOut;
41aba5b7 182
059ca955 183 sub TIEHANDLE {
184 bless(\(my $text), $_[0]);
185 }
41aba5b7 186
059ca955 187 sub clear {
188 ${ $_[0] } = '';
189 }
41aba5b7 190
059ca955 191 sub PRINT {
192 my $self = shift;
193 $$self .= join('', @_);
194 }
41aba5b7 195}
196
059ca955 197# Signal-related variables
198# (this is actually a regression test for Configure.)
199
b25be8c8 200is($Config{sig_num_init} =~ tr/,/,/, $Config{sig_size}, "sig_num_init size");
201is($Config{sig_name_init} =~ tr/,/,/, $Config{sig_size}, "sig_name_init size");
8468119f 202
203# Test the troublesome virtual stuff
204foreach my $pain (qw(byteorder)) {
205 # No config var is named with anything that is a regexp metachar"
206 my @result = Config::config_re($pain);
207 is (scalar @result, 1, "single result for config_re('$pain')");
208 like ($result[0], qr/^$pain=(['"])$Config{$pain}\1$/, # grr '
209 "which is the expected result for $pain");
210}