Test Config.
[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 => 20;
8
9 use_ok('Config');
10
11 # Some (safe?) bets.
12
13 ok(keys %Config > 900, "Config has more than 900 entries");
14
15 ok(each %Config);
16
17 is($Config{PERL_REVISION}, 5, "PERL_REVISION is 5");
18
19 like($Config{ivsize},     qr/^(4|8)$/, "ivsize is 4 or 8");
20
21 ok( exists $Config{cc},      "has cc");
22
23 ok( exists $Config{ccflags}, "has ccflags");
24
25 ok(!exists $Config{python},  "has no python");
26
27 ok( exists $Config{d_fork},  "has d_fork");
28
29 ok(!exists $Config{d_bork},  "has no d_bork");
30
31 # byteorder is virtual, but it has rules. 
32
33 like($Config{byteorder}, qr/^(1234|4321|12345678|87654321)$/, "byteorder is 1234 or 4321 or 12345678 or 87654321");
34
35 is(length $Config{byteorder}, $Config{ivsize}, "byteorder is as long as ivsize");
36
37 # ccflags_nolargefiles is virtual, too.
38
39 ok(exists $Config{ccflags_nolargefiles}, "has ccflags_nolargefiles");
40
41 # Utility functions.
42
43 like(Config::myconfig(),  qr/cc='$Config{cc}'/, "myconfig");
44
45 like(Config::config_sh(), qr/cc='$Config{cc}'/, "config_sh");
46
47 my $out = tie *STDOUT, 'FakeOut';
48
49 Config::config_vars('cc');
50 my $out1 = $$out;
51 $out->clear;
52
53 Config::config_vars('d_bork');
54 my $out2 = $$out;
55 $out->clear;
56
57 untie *STDOUT;
58
59 like($out1, qr/^cc='$Config{cc}';/, "config_vars cc");
60 like($out2, qr/^d_bork='UNKNOWN';/, "config_vars d_bork is UNKNOWN");
61
62 # Read-only.
63
64 eval { $Config{d_bork} = 'borkbork' };
65 like($@, qr/Config is read-only/, "no STORE");
66
67 eval { delete $Config{d_fork} };
68 like($@, qr/Config is read-only/, "no DELETE");
69
70 eval { %Config = () };
71 like($@, qr/Config is read-only/, "no CLEAR");
72
73 package FakeOut;
74
75 sub TIEHANDLE {
76         bless(\(my $text), $_[0]);
77 }
78
79 sub clear {
80         ${ $_[0] } = '';
81 }
82
83 # remove the bell character
84 sub scrub {
85         ${ $_[0] } =~ tr/\a//d;
86 }
87
88 # must shift off self
89 sub PRINT {
90         my $self = shift;
91         ($$self .= join('', @_)) =~ s/\s+/./gm;
92 }
93