Commit | Line | Data |
---|---|---|
6aee8cc4 | 1 | #!./perl -w |
a48f8c77 | 2 | |
41aba5b7 JH |
3 | BEGIN { |
4 | chdir 't' if -d 't'; | |
5 | @INC = '../lib'; | |
6 | require "./test.pl"; | |
41aba5b7 | 7 | |
6aee8cc4 NC |
8 | plan ('no_plan'); |
9 | ||
10 | use_ok('Config'); | |
11 | } | |
41aba5b7 | 12 | |
6aee8cc4 | 13 | use strict; |
41aba5b7 JH |
14 | |
15 | # Some (safe?) bets. | |
16 | ||
484fdf61 | 17 | ok(keys %Config > 500, "Config has more than 500 entries"); |
41aba5b7 | 18 | |
2ddb7828 NC |
19 | my ($first) = Config::config_sh() =~ /^(\S+)=/m; |
20 | die "Can't find first entry in Config::config_sh()" unless defined $first; | |
21 | print "# First entry is '$first'\n"; | |
22 | ||
23 | # It happens that the we know what the first key should be. This is somewhat | |
24 | # cheating, but there was briefly a bug where the key got a bonus newline. | |
25 | my ($first_each) = each %Config; | |
26 | is($first_each, $first, "First key from each is correct"); | |
27 | ok(exists($Config{$first_each}), "First key exists"); | |
28 | ok(!exists($Config{"\n$first"}), | |
29 | "Check that first key with prepended newline isn't falsely existing"); | |
41aba5b7 JH |
30 | |
31 | is($Config{PERL_REVISION}, 5, "PERL_REVISION is 5"); | |
32 | ||
d10bb151 MS |
33 | # Check that old config variable names are aliased to their new ones. |
34 | my %grandfathers = ( PERL_VERSION => 'PATCHLEVEL', | |
35 | PERL_SUBVERSION => 'SUBVERSION', | |
36 | PERL_CONFIG_SH => 'CONFIG' | |
37 | ); | |
38 | while( my($new, $old) = each %grandfathers ) { | |
39 | isnt($Config{$new}, undef, "$new is defined"); | |
40 | is($Config{$new}, $Config{$old}, "$new is aliased to $old"); | |
41 | } | |
42 | ||
41aba5b7 JH |
43 | ok( exists $Config{cc}, "has cc"); |
44 | ||
45 | ok( exists $Config{ccflags}, "has ccflags"); | |
46 | ||
47 | ok(!exists $Config{python}, "has no python"); | |
48 | ||
49 | ok( exists $Config{d_fork}, "has d_fork"); | |
50 | ||
51 | ok(!exists $Config{d_bork}, "has no d_bork"); | |
52 | ||
9829f96e | 53 | like($Config{ivsize}, qr/^(4|8)$/, "ivsize is 4 or 8 (it is $Config{ivsize})"); |
7956ade2 | 54 | |
8d871aab | 55 | # byteorder is virtual, but it has rules. |
41aba5b7 | 56 | |
9829f96e NC |
57 | like($Config{byteorder}, qr/^(1234|4321|12345678|87654321)$/, |
58 | "byteorder is 1234 or 4321 or 12345678 or 87654321 " | |
59 | . "(it is $Config{byteorder})"); | |
41aba5b7 | 60 | |
9829f96e NC |
61 | is(length $Config{byteorder}, $Config{ivsize}, |
62 | "byteorder is as long as ivsize (which is $Config{ivsize})"); | |
41aba5b7 JH |
63 | |
64 | # ccflags_nolargefiles is virtual, too. | |
65 | ||
66 | ok(exists $Config{ccflags_nolargefiles}, "has ccflags_nolargefiles"); | |
67 | ||
68 | # Utility functions. | |
69 | ||
a48f8c77 MS |
70 | { |
71 | # make sure we can export what we say we can export. | |
72 | package Foo; | |
73 | my @exports = qw(myconfig config_sh config_vars config_re); | |
74 | Config->import(@exports); | |
75 | foreach my $func (@exports) { | |
76 | ::ok( __PACKAGE__->can($func), "$func exported" ); | |
77 | } | |
6664971e | 78 | } |
41aba5b7 | 79 | |
8468119f NC |
80 | like(Config::myconfig(), qr/osname=\Q$Config{osname}\E/, "myconfig"); |
81 | like(Config::config_sh(), qr/osname='\Q$Config{osname}\E'/, "config_sh"); | |
82 | like(Config::config_sh(), qr/byteorder='[1-8]+'/, | |
83 | "config_sh has a valid byteorder"); | |
8d871aab NC |
84 | foreach my $line (Config::config_re('c.*')) { |
85 | like($line, qr/^c.*?=.*$/, 'config_re' ); | |
86 | } | |
a48f8c77 | 87 | |
41aba5b7 JH |
88 | my $out = tie *STDOUT, 'FakeOut'; |
89 | ||
307dc113 | 90 | Config::config_vars('cc'); # non-regex test of essential cfg-var |
41aba5b7 JH |
91 | my $out1 = $$out; |
92 | $out->clear; | |
93 | ||
307dc113 | 94 | Config::config_vars('d_bork'); # non-regex, non-existent cfg-var |
41aba5b7 JH |
95 | my $out2 = $$out; |
96 | $out->clear; | |
97 | ||
307dc113 | 98 | Config::config_vars('PERL_API_.*'); # regex, tagged multi-line answer |
4a305f6a JC |
99 | my $out3 = $$out; |
100 | $out->clear; | |
101 | ||
307dc113 | 102 | Config::config_vars('PERL_API_.*:'); # regex, tagged single-line answer |
4a305f6a JC |
103 | my $out4 = $$out; |
104 | $out->clear; | |
41aba5b7 | 105 | |
307dc113 | 106 | Config::config_vars(':PERL_API_.*:'); # regex, non-tagged single-line answer |
4a305f6a JC |
107 | my $out5 = $$out; |
108 | $out->clear; | |
109 | ||
307dc113 | 110 | Config::config_vars(':PERL_API_.*'); # regex, non-tagged multi-line answer |
0c6e7072 RB |
111 | my $out6 = $$out; |
112 | $out->clear; | |
113 | ||
307dc113 JC |
114 | Config::config_vars('PERL_API_REVISION.*:'); # regex, tagged |
115 | my $out7 = $$out; | |
116 | $out->clear; | |
117 | ||
9829f96e NC |
118 | # regex, non-tagged multi-line answer |
119 | Config::config_vars(':PERL_API_REVISION.*'); | |
307dc113 JC |
120 | my $out8 = $$out; |
121 | $out->clear; | |
122 | ||
123 | Config::config_vars('PERL_EXPENSIVE_.*:'); # non-matching regex | |
124 | my $out9 = $$out; | |
125 | $out->clear; | |
126 | ||
127 | Config::config_vars('?flags'); # bogus regex, no explicit warning ! | |
128 | my $out10 = $$out; | |
129 | $out->clear; | |
130 | ||
6aee8cc4 | 131 | undef $out; |
4a305f6a | 132 | untie *STDOUT; |
307dc113 JC |
133 | |
134 | like($out1, qr/^cc='\Q$Config{cc}\E';/, "found config_var cc"); | |
135 | like($out2, qr/^d_bork='UNKNOWN';/, "config_var d_bork is UNKNOWN"); | |
136 | ||
137 | # test for leading, trailing colon effects | |
6aee8cc4 NC |
138 | # Split in scalar context it deprecated, and will warn. |
139 | my @tmp; | |
140 | is(scalar (@tmp = split(/;\n/, $out3)), 3, "3 lines found"); | |
141 | is(scalar (@tmp = split(/;\n/, $out6)), 3, "3 lines found"); | |
307dc113 JC |
142 | |
143 | is($out4 =~ /(;\n)/s, '', "trailing colon gives 1-line response: $out4"); | |
144 | is($out5 =~ /(;\n)/s, '', "trailing colon gives 1-line response: $out5"); | |
145 | ||
6aee8cc4 NC |
146 | is(scalar (@tmp = split(/=/, $out3)), 4, "found 'tag='"); |
147 | is(scalar (@tmp = split(/=/, $out4)), 4, "found 'tag='"); | |
307dc113 JC |
148 | |
149 | my @api; | |
150 | ||
151 | my @rev = @Config{qw(PERL_API_REVISION PERL_API_VERSION PERL_API_SUBVERSION)}; | |
152 | ||
153 | print ("# test tagged responses, multi-line and single-line\n"); | |
6aee8cc4 | 154 | foreach my $api ($out3, $out4) { |
307dc113 JC |
155 | @api = $api =~ /PERL_API_(\w+)=(.*?)(?:;\n|\s)/mg; |
156 | is($api[0], "REVISION", "REVISION tag"); | |
157 | is($api[4], "VERSION", "VERSION tag"); | |
158 | is($api[2], "SUBVERSION", "SUBVERSION tag"); | |
159 | is($api[1], "'$rev[0]'", "REVISION is $rev[0]"); | |
160 | is($api[5], "'$rev[1]'", "VERSION is $rev[1]"); | |
161 | is($api[3], "'$rev[2]'", "SUBVERSION is $rev[2]"); | |
162 | } | |
163 | ||
164 | print("# test non-tagged responses, multi-line and single-line\n"); | |
6aee8cc4 | 165 | foreach my $api ($out5, $out6) { |
307dc113 JC |
166 | @api = split /(?: |;\n)/, $api; |
167 | is($api[0], "'$rev[0]'", "revision is $rev[0]"); | |
168 | is($api[2], "'$rev[1]'", "version is $rev[1]"); | |
169 | is($api[1], "'$rev[2]'", "subversion is $rev[2]"); | |
170 | } | |
171 | ||
172 | # compare to each other, the outputs for trailing, leading colon | |
173 | $out7 =~ s/ $//; | |
174 | is("$out7;\n", "PERL_API_REVISION=$out8", "got expected diffs"); | |
175 | ||
176 | like($out9, qr/\bnot\s+found\b/, "$out9 - perl is FREE !"); | |
177 | like($out10, qr/\bnot\s+found\b/, "config_vars with invalid regexp"); | |
0c6e7072 | 178 | |
41aba5b7 JH |
179 | # Read-only. |
180 | ||
7956ade2 | 181 | undef $@; |
41aba5b7 JH |
182 | eval { $Config{d_bork} = 'borkbork' }; |
183 | like($@, qr/Config is read-only/, "no STORE"); | |
184 | ||
7956ade2 JH |
185 | ok(!exists $Config{d_bork}, "still no d_bork"); |
186 | ||
187 | undef $@; | |
41aba5b7 JH |
188 | eval { delete $Config{d_fork} }; |
189 | like($@, qr/Config is read-only/, "no DELETE"); | |
190 | ||
7956ade2 JH |
191 | ok( exists $Config{d_fork}, "still d_fork"); |
192 | ||
193 | undef $@; | |
41aba5b7 JH |
194 | eval { %Config = () }; |
195 | like($@, qr/Config is read-only/, "no CLEAR"); | |
196 | ||
7956ade2 JH |
197 | ok( exists $Config{d_fork}, "still d_fork"); |
198 | ||
059ca955 RGS |
199 | { |
200 | package FakeOut; | |
41aba5b7 | 201 | |
059ca955 RGS |
202 | sub TIEHANDLE { |
203 | bless(\(my $text), $_[0]); | |
204 | } | |
41aba5b7 | 205 | |
059ca955 RGS |
206 | sub clear { |
207 | ${ $_[0] } = ''; | |
208 | } | |
41aba5b7 | 209 | |
059ca955 RGS |
210 | sub PRINT { |
211 | my $self = shift; | |
212 | $$self .= join('', @_); | |
213 | } | |
41aba5b7 JH |
214 | } |
215 | ||
059ca955 RGS |
216 | # Signal-related variables |
217 | # (this is actually a regression test for Configure.) | |
218 | ||
b25be8c8 JH |
219 | is($Config{sig_num_init} =~ tr/,/,/, $Config{sig_size}, "sig_num_init size"); |
220 | is($Config{sig_name_init} =~ tr/,/,/, $Config{sig_size}, "sig_name_init size"); | |
8468119f NC |
221 | |
222 | # Test the troublesome virtual stuff | |
a6ea9771 NC |
223 | my @virtual = qw(byteorder ccflags_nolargefiles ldflags_nolargefiles |
224 | libs_nolargefiles libswanted_nolargefiles); | |
a644ec48 | 225 | |
2ddb7828 NC |
226 | # Also test that the first entry in config.sh is found correctly. There was |
227 | # special casing code for this | |
e9a5b206 NC |
228 | |
229 | foreach my $pain ($first, @virtual) { | |
a644ec48 | 230 | # No config var is named with anything that is a regexp metachar |
e89403c1 NC |
231 | ok(exists $Config{$pain}, "\$config('$pain') exists"); |
232 | ||
a644ec48 NC |
233 | my @result = $Config{$pain}; |
234 | is (scalar @result, 1, "single result for \$config('$pain')"); | |
235 | ||
06482b90 NC |
236 | @result = Config::config_re($pain); |
237 | is (scalar @result, 1, "single result for config_re('$pain')"); | |
375b6f9c | 238 | like ($result[0], qr/^$pain=(['"])\Q$Config{$pain}\E\1$/, # grr ' |
06482b90 | 239 | "which is the expected result for $pain"); |
8468119f | 240 | } |
e9a5b206 | 241 | |
5b8bd2c6 NC |
242 | # Check that config entries appear correctly in @INC |
243 | # TestInit.pm has probably already messed with our @INC | |
87ad9899 | 244 | # This little bit of evil is to avoid a @ in the program, in case it confuses |
af224ca8 NC |
245 | # shell 1 liners. We used to use a perl 1-ism, until that was deprecated, so |
246 | # now some octal in an eval. | |
5b8bd2c6 | 247 | my ($path, $ver, @orig_inc) |
87ad9899 NC |
248 | = split /\n/, |
249 | runperl (nolib=>1, | |
af224ca8 | 250 | prog=>'print qq{$_\n} foreach $^X, $], eval qq{\100INC}'); |
5b8bd2c6 NC |
251 | |
252 | die "This perl is $] at $^X; other perl is $ver (at $path) " | |
253 | . '- failed to find this perl' unless $] eq $ver; | |
254 | ||
255 | my %orig_inc; | |
256 | @orig_inc{@orig_inc} = (); | |
257 | ||
258 | my $failed; | |
79cf6d14 | 259 | # This [used to be] the order that directories are pushed onto @INC in perl.c: |
5b8bd2c6 | 260 | foreach my $lib (qw(applibexp archlibexp privlibexp sitearchexp sitelibexp |
79cf6d14 | 261 | vendorarchexp vendorlibexp)) { |
5b8bd2c6 NC |
262 | my $dir = $Config{$lib}; |
263 | SKIP: { | |
d1888197 | 264 | skip "lib $lib not in \@INC on Win32" if $^O eq 'MSWin32'; |
5b8bd2c6 NC |
265 | skip "lib $lib not defined" unless defined $dir; |
266 | skip "lib $lib not set" unless length $dir; | |
d80510fd CB |
267 | # May be in @INC in either Unix or VMS format on VMS. |
268 | if ($^O eq 'VMS' && !exists($orig_inc{$dir})) { | |
269 | $dir = VMS::Filespec::unixify($dir); | |
270 | $dir =~ s|/$||; | |
271 | } | |
5b8bd2c6 NC |
272 | # So we expect to find it in @INC |
273 | ||
274 | ok (exists $orig_inc{$dir}, "Expect $lib '$dir' to be in \@INC") | |
275 | or $failed++; | |
276 | } | |
277 | } | |
278 | _diag ('@INC is:', @orig_inc) if $failed; |