1#!/pro/bin/perl
2
3use strict;
4use warnings;
5
6BEGIN {
7    use Test::More;
8    my $tests = 42;
9    unless ($ENV{PERL_CORE}) {
10	require Test::NoWarnings;
11	Test::NoWarnings->import ();
12	$tests++;
13	}
14
15    plan tests => $tests;
16
17    use_ok ("Config::Perl::V");
18    }
19
20ok (my $conf = Config::Perl::V::myconfig,	"Read config");
21ok (exists $conf->{$_},	"Has $_ entry") for qw( build environment config inc );
22is (lc $conf->{build}{osname}, lc $conf->{config}{osname}, "osname");
23
24# Test summary
25ok (my $info1 = Config::Perl::V::summary ($conf), "Get a summary for \$conf");
26ok (my $info2 = Config::Perl::V::summary,         "Get a summary for \$^X");
27is_deeply ($info1, $info2, "Info should match");
28
29ok (my $sig = Config::Perl::V::signature, "Get signature");
30like ($sig, qr{^[0-9a-f]{32}$}, "Valid md5");
31
32my $no_md5 = "0" x 32;
33ok (my $bad = Config::Perl::V::signature ({ cfg => 0 }), "Signature on invalid data");
34is ($bad, $no_md5, "Invalid md5");
35ok (   $bad = Config::Perl::V::signature ({ config => {} }), "Signature on incomplete data");
36is ($bad, $no_md5, "Invalid md5");
37ok (   $bad = Config::Perl::V::signature ({ config => 0, build => {} }), "Signature on invalid data");
38is ($bad, $no_md5, "Invalid md5");
39ok (   $bad = Config::Perl::V::signature ({ config => {}, build => 0 }), "Signature on invalid data");
40is ($bad, $no_md5, "Invalid md5");
41
42SKIP: {
43    # Test that the code that shells out to perl -V and parses the output
44    # gives the same results as the code that calls Config::* routines directly.
45    defined &Config::compile_date or
46	skip "This perl doesn't provide perl -V in the Config module", 2;
47    eval q{no warnings "redefine"; sub Config::compile_date { return undef }};
48    is (Config::compile_date (), undef, "Successfully overriden compile_date");
49    is_deeply (Config::Perl::V::myconfig, $conf,
50	"perl -V parsing code produces same result as the Config module");
51    }
52
53$ENV{CPV_TEST_ENV} = 42;
54ok ($conf = Config::Perl::V::myconfig ({ env => qr{^CPV_TEST_ENV$} }), "Read config plus ENV");
55ok (exists $conf->{$_},	"Has $_ entry") for qw( build environment config inc environment );
56ok (my $eh = $conf->{environment}, "Get ENV from conf");
57is ($eh->{CPV_TEST_ENV}, 42, "Valid entry");
58
59ok ($conf = Config::Perl::V::myconfig ([ env => qr{^CPV_TEST_ENV$} ]), "Read config plus ENV");
60ok (exists $conf->{$_},	"Has $_ entry") for qw( build environment config inc environment );
61ok ($eh = $conf->{environment}, "Get ENV from conf");
62is ($eh->{CPV_TEST_ENV}, 42, "Valid entry");
63
64ok ($conf = Config::Perl::V::myconfig (  env => qr{^CPV_TEST_ENV$}  ), "Read config invalid arguments");
65is ($conf->{environment}{CPV_TEST_ENV}, undef, "No entry");
66
67delete $INC{"Digest/MD5.pm"};
68delete $INC{"Digest/base.pm"};
69$INC{"Digest/MD5"} = "./flooble/blurgh/Digest/MD5.pm";
70local @INC = ("xyzzy$$"); # Should be unable to find Digest::MD5
71ok ($sig = Config::Perl::V::signature, "Get signature (No Digest::MD5)");
72is ($sig, $no_md5, "Valid md5");
73