Update CPANPLUS to 0.81_01
[p5sagit/p5-mst-13.2.git] / lib / CPANPLUS / t / 02_CPANPLUS-Internals.t
CommitLineData
6aaee015 1### make sure we can find our conf.pl file
2BEGIN {
3 use FindBin;
4 require "$FindBin::Bin/inc/conf.pl";
5}
6
7use strict;
8use Test::More 'no_plan';
9
10use CPANPLUS::Configure;
11use CPANPLUS::Backend;
12use CPANPLUS::Internals::Constants;
13use Module::Load::Conditional qw[can_load];
14use Data::Dumper;
15
16my $cb = CPANPLUS::Backend->new( CPANPLUS::Configure->new() );
17
18isa_ok($cb, 'CPANPLUS::Internals');
19is($cb->_id, $cb->_last_id, "Comparing ID's");
20
21### delete/store/retrieve id tests ###
22{ my $del = $cb->_remove_id( $cb->_id );
23 ok( $del, "ID deleted" );
24 isa_ok( $del, "CPANPLUS::Internals" );
25 is( $del, $cb, " Deleted ID matches last object" );
26
27 my $id = $cb->_store_id( $del );
28 ok( $id, "ID stored" );
29 is( $id, $cb->_id, " Stored proper ID" );
30
31 my $obj = $cb->_retrieve_id( $id );
32 ok( $obj, "Object retrieved from ID" );
33 isa_ok( $obj, 'CPANPLUS::Internals' );
34 is( $obj->_id, $id, " Retrieved ID properly" );
35
36 my @obs = $cb->_return_all_objects();
37 ok( scalar(@obs), "Returned objects" );
38 is( scalar(@obs), 1, " Proper amount of objects found" );
39 is( $obs[0]->_id, $id, " Proper ID found on object" );
40
41 my $lid = $cb->_last_id;
42 ok( $lid, "Found last registered ID" );
43 is( $lid, $id, " ID matches last object" );
44
45 my $iid = $cb->_inc_id;
46 ok( $iid, "Incremented ID" );
47 is( $iid, $id+1, " ID matched last ID + 1" );
48}
49
50### host ok test ###
51{
52 my $host = $cb->configure_object->get_conf('hosts')->[0];
53
54 is( $cb->_host_ok( host => $host ), 1, "Host ok" );
55 is( $cb->_add_fail_host(host => $host), 1, " Host now marked as bad" );
56 is( $cb->_host_ok( host => $host ), 0, " Host still bad" );
57 ok( $cb->_flush( list => ['hosts'] ), " Hosts flushed" );
58 is( $cb->_host_ok( host => $host ), 1, " Host now ok again" );
59}
60
61### flush loads test
62{ my $mod = 'Benchmark';
63 my $file = $mod . '.pm';
64
65 ### XXX whitebox test -- mark this module as unloadable
66 $Module::Load::Conditional::CACHE->{$mod}->{usable} = 0;
67
68 ok( !can_load( modules => { $mod => 0 }, verbose => 0 ),
69 "'$mod' not loaded" );
70
71 ok( $cb->flush('load'), " 'load' cache flushed" );
72 ok( can_load( modules => { $mod => 0 }, verbose => 0 ),
73 " '$mod' loaded" );
74}
75
76### callback registering tests ###
77{ my $callback_map = {
622d31ac 78 ### name default value
6aaee015 79 install_prerequisite => 1, # install prereqs when 'ask' is set?
80 edit_test_report => 0, # edit the prepared test report?
81 send_test_report => 1, # send the test report?
82 munge_test_report => $$, # munge the test report
83 filter_prereqs => $$, # limit prereqs
622d31ac 84 proceed_on_test_failure => 0, # continue on failed 'make test'?
502c7995 85 munge_dist_metafile => $$, # munge the metailfe
6aaee015 86 };
87
88 for my $callback ( keys %$callback_map ) {
89
983ffab6 90 { my $rv = $callback_map->{$callback};
6aaee015 91
92 is( $rv, $cb->_callbacks->$callback->( $0, $$ ),
93 "Default callback '$callback' called" );
94 like( CPANPLUS::Error->stack_as_string, qr/DEFAULT '\S+' HANDLER/s,
95 " Default handler warning recorded" );
96 CPANPLUS::Error->flush;
97 }
98
99 ### try to register the callback
100 my $ok = $cb->_register_callback(
101 name => $callback,
102 code => sub { return $callback }
103 );
104
105 ok( $ok, "Registered callback '$callback' ok" );
106
107 my $sub = $cb->_callbacks->$callback;
108 ok( $sub, " Retrieved callback" );
109 ok( IS_CODEREF->($sub), " Callback is a sub" );
110
111 my $rv = $sub->();
112 ok( $rv, " Callback called ok" );
113 is( $rv, $callback, " Got expected return value" );
114 }
115}
116
117
118# Local variables:
119# c-indentation-style: bsd
120# c-basic-offset: 4
121# indent-tabs-mode: nil
122# End:
123# vim: expandtab shiftwidth=4: