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