Fixes for open.pm which attempts to load layers:
[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
a48f8c77 9plan tests => 34;
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
41aba5b7 43# byteorder is virtual, but it has rules.
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
a48f8c77 65like(Config::myconfig(), qr/osname=$Config{osname}/, "myconfig");
66like(Config::config_sh(), qr/osname='$Config{osname}'/, "config_sh");
67like(join("\n", Config::config_re('c.*')),
68 qr/^c.*?=/, 'config_re' );
69
41aba5b7 70my $out = tie *STDOUT, 'FakeOut';
71
72Config::config_vars('cc');
73my $out1 = $$out;
74$out->clear;
75
76Config::config_vars('d_bork');
77my $out2 = $$out;
78$out->clear;
79
80untie *STDOUT;
81
82like($out1, qr/^cc='$Config{cc}';/, "config_vars cc");
83like($out2, qr/^d_bork='UNKNOWN';/, "config_vars d_bork is UNKNOWN");
84
85# Read-only.
86
7956ade2 87undef $@;
41aba5b7 88eval { $Config{d_bork} = 'borkbork' };
89like($@, qr/Config is read-only/, "no STORE");
90
7956ade2 91ok(!exists $Config{d_bork}, "still no d_bork");
92
93undef $@;
41aba5b7 94eval { delete $Config{d_fork} };
95like($@, qr/Config is read-only/, "no DELETE");
96
7956ade2 97ok( exists $Config{d_fork}, "still d_fork");
98
99undef $@;
41aba5b7 100eval { %Config = () };
101like($@, qr/Config is read-only/, "no CLEAR");
102
7956ade2 103ok( exists $Config{d_fork}, "still d_fork");
104
41aba5b7 105package FakeOut;
106
107sub TIEHANDLE {
108 bless(\(my $text), $_[0]);
109}
110
111sub clear {
112 ${ $_[0] } = '';
113}
114
41aba5b7 115sub PRINT {
116 my $self = shift;
7956ade2 117 $$self .= join('', @_);
41aba5b7 118}
119