DB_File 1.809 was RE: [perl #30237] DB_File methods and substr don't mix
[p5sagit/p5-mst-13.2.git] / lib / Config.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require "./test.pl";
7 }
8
9 plan tests => 47;
10
11 use_ok('Config');
12
13 # Some (safe?) bets.
14
15 ok(keys %Config > 500, "Config has more than 500 entries");
16
17 ok(each %Config);
18
19 is($Config{PERL_REVISION}, 5, "PERL_REVISION is 5");
20
21 # Check that old config variable names are aliased to their new ones.
22 my %grandfathers = ( PERL_VERSION       => 'PATCHLEVEL',
23                      PERL_SUBVERSION    => 'SUBVERSION',
24                      PERL_CONFIG_SH     => 'CONFIG'
25                    );
26 while( 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
31 ok( exists $Config{cc},      "has cc");
32
33 ok( exists $Config{ccflags}, "has ccflags");
34
35 ok(!exists $Config{python},  "has no python");
36
37 ok( exists $Config{d_fork},  "has d_fork");
38
39 ok(!exists $Config{d_bork},  "has no d_bork");
40
41 like($Config{ivsize},     qr/^(4|8)$/, "ivsize is 4 or 8 (it is $Config{ivsize})");
42
43 # byteorder is virtual, but it has rules. 
44
45 like($Config{byteorder}, qr/^(1234|4321|12345678|87654321)$/, "byteorder is 1234 or 4321 or 12345678 or 87654321 (it is $Config{byteorder})");
46
47 is(length $Config{byteorder}, $Config{ivsize}, "byteorder is as long as ivsize (which is $Config{ivsize})");
48
49 # ccflags_nolargefiles is virtual, too.
50
51 ok(exists $Config{ccflags_nolargefiles}, "has ccflags_nolargefiles");
52
53 # Utility functions.
54
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     }
63 }
64
65 like(Config::myconfig(),       qr/osname=\Q$Config{osname}\E/,   "myconfig");
66 like(Config::config_sh(),      qr/osname='\Q$Config{osname}\E'/, "config_sh");
67 like(join("\n", Config::config_re('c.*')),
68                                qr/^c.*?=/,                   'config_re' );
69
70 my $out = tie *STDOUT, 'FakeOut';
71
72 Config::config_vars('cc');
73 my $out1 = $$out;
74 $out->clear;
75
76 Config::config_vars('d_bork');
77 my $out2 = $$out;
78 $out->clear;
79
80 Config::config_vars('PERL_API_.*');
81 my $out3 = $$out;
82 $out->clear;
83
84 Config::config_vars(':PERL_API_.*:');
85 my $out4 = $$out;
86 $out->clear;
87
88 Config::config_vars(':PERL_API_REVISION:');
89 my $out5 = $$out;
90 $out->clear;
91
92 Config::config_vars('?flags');
93 my $out6 = $$out;
94 $out->clear;
95
96 untie *STDOUT;
97 like($out1, qr/^cc='\Q$Config{cc}\E';/, "config_vars cc");
98 like($out2, qr/^d_bork='UNKNOWN';/, "config_vars d_bork is UNKNOWN");
99
100 is(3, scalar split(/\n/, $out3), "3 PERL_API vars found");
101 my @api = $out3 =~ /^PERL_API_(\w+)=(.*);/mg;
102 is("'5'", $api[1], "1st is 5");
103 is("'9'", $api[5], "2nd is 9");
104 is("'1'", $api[3], "3rd is 1");
105 @api = split(/ /, $out4);
106 is(3, @api, "trailing colon puts 3 terms on same line");
107 unlike($out4, qr/=/, "leading colon suppresses param names");
108 is("'5'", $api[0], "revision is 5");
109 is("'9'", $api[2], "version is 9");
110 is("'1'", $api[1], "subversion is 1");
111
112 is("'5' ", $out5, "leading and trailing colons return just the value");
113
114 like($out6, qr/\bnot\s+found\b/, "config_vars with invalid regexp");
115
116 # Read-only.
117
118 undef $@;
119 eval { $Config{d_bork} = 'borkbork' };
120 like($@, qr/Config is read-only/, "no STORE");
121
122 ok(!exists $Config{d_bork}, "still no d_bork");
123
124 undef $@;
125 eval { delete $Config{d_fork} };
126 like($@, qr/Config is read-only/, "no DELETE");
127
128 ok( exists $Config{d_fork}, "still d_fork");
129
130 undef $@;
131 eval { %Config = () };
132 like($@, qr/Config is read-only/, "no CLEAR");
133
134 ok( exists $Config{d_fork}, "still d_fork");
135
136 {
137     package FakeOut;
138
139     sub TIEHANDLE {
140         bless(\(my $text), $_[0]);
141     }
142
143     sub clear {
144         ${ $_[0] } = '';
145     }
146
147     sub PRINT {
148         my $self = shift;
149         $$self .= join('', @_);
150     }
151 }
152
153 # Signal-related variables
154 # (this is actually a regression test for Configure.)
155
156 is($Config{sig_num_init}  =~ tr/,/,/, $Config{sig_size}, "sig_num_init size");
157 is($Config{sig_name_init} =~ tr/,/,/, $Config{sig_size}, "sig_name_init size");