test grandfathered Config variables
[p5sagit/p5-mst-13.2.git] / lib / Config.t
1 BEGIN {
2     chdir 't' if -d 't';
3     @INC = '../lib';
4     require "./test.pl";
5 }
6
7 plan tests => 29;
8
9 use_ok('Config');
10
11 # Some (safe?) bets.
12
13 ok(keys %Config > 500, "Config has more than 500 entries");
14
15 ok(each %Config);
16
17 is($Config{PERL_REVISION}, 5, "PERL_REVISION is 5");
18
19 # Check that old config variable names are aliased to their new ones.
20 my %grandfathers = ( PERL_VERSION       => 'PATCHLEVEL',
21                      PERL_SUBVERSION    => 'SUBVERSION',
22                      PERL_CONFIG_SH     => 'CONFIG'
23                    );
24 while( my($new, $old) = each %grandfathers ) {
25     isnt($Config{$new}, undef,       "$new is defined");
26     is($Config{$new}, $Config{$old}, "$new is aliased to $old");
27 }
28
29 ok( exists $Config{cc},      "has cc");
30
31 ok( exists $Config{ccflags}, "has ccflags");
32
33 ok(!exists $Config{python},  "has no python");
34
35 ok( exists $Config{d_fork},  "has d_fork");
36
37 ok(!exists $Config{d_bork},  "has no d_bork");
38
39 like($Config{ivsize},     qr/^(4|8)$/, "ivsize is 4 or 8 (it is $Config{ivsize})");
40
41 # byteorder is virtual, but it has rules. 
42
43 like($Config{byteorder}, qr/^(1234|4321|12345678|87654321)$/, "byteorder is 1234 or 4321 or 12345678 or 87654321 (it is $Config{byteorder})");
44
45 is(length $Config{byteorder}, $Config{ivsize}, "byteorder is as long as ivsize (which is $Config{ivsize})");
46
47 # ccflags_nolargefiles is virtual, too.
48
49 ok(exists $Config{ccflags_nolargefiles}, "has ccflags_nolargefiles");
50
51 # Utility functions.
52
53 like(Config::myconfig(),  qr/cc='$Config{cc}'/, "myconfig");
54
55 SKIP: {
56         skip "cc is tied in $^O", 1 if $^O eq 'MacOS';
57         like(Config::config_sh(), qr/cc='$Config{cc}'/, "config_sh");
58 }
59
60 my $out = tie *STDOUT, 'FakeOut';
61
62 Config::config_vars('cc');
63 my $out1 = $$out;
64 $out->clear;
65
66 Config::config_vars('d_bork');
67 my $out2 = $$out;
68 $out->clear;
69
70 untie *STDOUT;
71
72 like($out1, qr/^cc='$Config{cc}';/, "config_vars cc");
73 like($out2, qr/^d_bork='UNKNOWN';/, "config_vars d_bork is UNKNOWN");
74
75 # Read-only.
76
77 undef $@;
78 eval { $Config{d_bork} = 'borkbork' };
79 like($@, qr/Config is read-only/, "no STORE");
80
81 ok(!exists $Config{d_bork}, "still no d_bork");
82
83 undef $@;
84 eval { delete $Config{d_fork} };
85 like($@, qr/Config is read-only/, "no DELETE");
86
87 ok( exists $Config{d_fork}, "still d_fork");
88
89 undef $@;
90 eval { %Config = () };
91 like($@, qr/Config is read-only/, "no CLEAR");
92
93 ok( exists $Config{d_fork}, "still d_fork");
94
95 package FakeOut;
96
97 sub TIEHANDLE {
98         bless(\(my $text), $_[0]);
99 }
100
101 sub clear {
102         ${ $_[0] } = '';
103 }
104
105 sub PRINT {
106         my $self = shift;
107         $$self .= join('', @_);
108 }
109