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