X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FConfig.t;h=df2b55d3a6958ab2051d9965db87f2be56500979;hb=a644ec488eb5f4499bbbcf821abc0e1ab10ed06c;hp=fc75d4c55363914fc84d2e928540165f10606d90;hpb=a667ff70662bc9aa79513f1cbac0d483124162fa;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Config.t b/lib/Config.t index fc75d4c..df2b55d 100644 --- a/lib/Config.t +++ b/lib/Config.t @@ -6,7 +6,7 @@ BEGIN { require "./test.pl"; } -plan tests => 36; +plan 'no_plan'; use_ok('Config'); @@ -38,13 +38,16 @@ ok( exists $Config{d_fork}, "has d_fork"); ok(!exists $Config{d_bork}, "has no d_bork"); -like($Config{ivsize}, qr/^(4|8)$/, "ivsize is 4 or 8 (it is $Config{ivsize})"); +like($Config{ivsize}, qr/^(4|8)$/, "ivsize is 4 or 8 (it is $Config{ivsize})"); -# byteorder is virtual, but it has rules. +# byteorder is virtual, but it has rules. -like($Config{byteorder}, qr/^(1234|4321|12345678|87654321)$/, "byteorder is 1234 or 4321 or 12345678 or 87654321 (it is $Config{byteorder})"); +like($Config{byteorder}, qr/^(1234|4321|12345678|87654321)$/, + "byteorder is 1234 or 4321 or 12345678 or 87654321 " + . "(it is $Config{byteorder})"); -is(length $Config{byteorder}, $Config{ivsize}, "byteorder is as long as ivsize (which is $Config{ivsize})"); +is(length $Config{byteorder}, $Config{ivsize}, + "byteorder is as long as ivsize (which is $Config{ivsize})"); # ccflags_nolargefiles is virtual, too. @@ -62,25 +65,101 @@ ok(exists $Config{ccflags_nolargefiles}, "has ccflags_nolargefiles"); } } -like(Config::myconfig(), qr/osname=\Q$Config{osname}\E/, "myconfig"); -like(Config::config_sh(), qr/osname='\Q$Config{osname}\E'/, "config_sh"); -like(join("\n", Config::config_re('c.*')), - qr/^c.*?=/, 'config_re' ); +like(Config::myconfig(), qr/osname=\Q$Config{osname}\E/, "myconfig"); +like(Config::config_sh(), qr/osname='\Q$Config{osname}\E'/, "config_sh"); +like(Config::config_sh(), qr/byteorder='[1-8]+'/, + "config_sh has a valid byteorder"); +foreach my $line (Config::config_re('c.*')) { + like($line, qr/^c.*?=.*$/, 'config_re' ); +} my $out = tie *STDOUT, 'FakeOut'; -Config::config_vars('cc'); +Config::config_vars('cc'); # non-regex test of essential cfg-var my $out1 = $$out; $out->clear; -Config::config_vars('d_bork'); +Config::config_vars('d_bork'); # non-regex, non-existent cfg-var my $out2 = $$out; $out->clear; +Config::config_vars('PERL_API_.*'); # regex, tagged multi-line answer +my $out3 = $$out; +$out->clear; + +Config::config_vars('PERL_API_.*:'); # regex, tagged single-line answer +my $out4 = $$out; +$out->clear; + +Config::config_vars(':PERL_API_.*:'); # regex, non-tagged single-line answer +my $out5 = $$out; +$out->clear; + +Config::config_vars(':PERL_API_.*'); # regex, non-tagged multi-line answer +my $out6 = $$out; +$out->clear; + +Config::config_vars('PERL_API_REVISION.*:'); # regex, tagged +my $out7 = $$out; +$out->clear; + +# regex, non-tagged multi-line answer +Config::config_vars(':PERL_API_REVISION.*'); +my $out8 = $$out; +$out->clear; + +Config::config_vars('PERL_EXPENSIVE_.*:'); # non-matching regex +my $out9 = $$out; +$out->clear; + +Config::config_vars('?flags'); # bogus regex, no explicit warning ! +my $out10 = $$out; +$out->clear; + untie *STDOUT; -like($out1, qr/^cc='\Q$Config{cc}\E';/, "config_vars cc"); -like($out2, qr/^d_bork='UNKNOWN';/, "config_vars d_bork is UNKNOWN"); +like($out1, qr/^cc='\Q$Config{cc}\E';/, "found config_var cc"); +like($out2, qr/^d_bork='UNKNOWN';/, "config_var d_bork is UNKNOWN"); + +# test for leading, trailing colon effects +is(scalar split(/;\n/, $out3), 3, "3 lines found"); +is(scalar split(/;\n/, $out6), 3, "3 lines found"); + +is($out4 =~ /(;\n)/s, '', "trailing colon gives 1-line response: $out4"); +is($out5 =~ /(;\n)/s, '', "trailing colon gives 1-line response: $out5"); + +is(scalar split(/=/, $out3), 4, "found 'tag='"); +is(scalar split(/=/, $out4), 4, "found 'tag='"); + +my @api; + +my @rev = @Config{qw(PERL_API_REVISION PERL_API_VERSION PERL_API_SUBVERSION)}; + +print ("# test tagged responses, multi-line and single-line\n"); +foreach $api ($out3, $out4) { + @api = $api =~ /PERL_API_(\w+)=(.*?)(?:;\n|\s)/mg; + is($api[0], "REVISION", "REVISION tag"); + is($api[4], "VERSION", "VERSION tag"); + is($api[2], "SUBVERSION", "SUBVERSION tag"); + is($api[1], "'$rev[0]'", "REVISION is $rev[0]"); + is($api[5], "'$rev[1]'", "VERSION is $rev[1]"); + is($api[3], "'$rev[2]'", "SUBVERSION is $rev[2]"); +} + +print("# test non-tagged responses, multi-line and single-line\n"); +foreach $api ($out5, $out6) { + @api = split /(?: |;\n)/, $api; + is($api[0], "'$rev[0]'", "revision is $rev[0]"); + is($api[2], "'$rev[1]'", "version is $rev[1]"); + is($api[1], "'$rev[2]'", "subversion is $rev[2]"); +} + +# compare to each other, the outputs for trailing, leading colon +$out7 =~ s/ $//; +is("$out7;\n", "PERL_API_REVISION=$out8", "got expected diffs"); + +like($out9, qr/\bnot\s+found\b/, "$out9 - perl is FREE !"); +like($out10, qr/\bnot\s+found\b/, "config_vars with invalid regexp"); # Read-only. @@ -122,8 +201,24 @@ ok( exists $Config{d_fork}, "still d_fork"); # Signal-related variables # (this is actually a regression test for Configure.) -ok((split / /, $Config{sig_num}) == $Config{sig_size}+1, "sig_size"); -SKIP : { - if ($^O eq 'hpux') { skip "HP-UX has SIGRTM(IN|AX) == -1" } - like($Config{sig_num}, qr/^[ \d]+\z/, "sig_num has only positive numbers"); +is($Config{sig_num_init} =~ tr/,/,/, $Config{sig_size}, "sig_num_init size"); +is($Config{sig_name_init} =~ tr/,/,/, $Config{sig_size}, "sig_name_init size"); + +# Test the troublesome virtual stuff +my @virtual = qw(byteorder ccflags_nolargefiles); + +foreach my $pain (@virtual) { + # No config var is named with anything that is a regexp metachar + my @result = $Config{$pain}; + is (scalar @result, 1, "single result for \$config('$pain')"); + + TODO: { + local $TODO; + $TODO = "No regexp lookup for $pain yet" unless $pain eq 'byteorder'; + + @result = Config::config_re($pain); + is (scalar @result, 1, "single result for config_re('$pain')"); + like ($result[0], qr/^$pain=(['"])$Config{$pain}\1$/, # grr ' + "which is the expected result for $pain"); + } }