Update CPANPLUS to 0.85_06
[p5sagit/p5-mst-13.2.git] / lib / CPANPLUS / t / 031_CPANPLUS-Internals-Source-SQLite.t
1 ### make sure we can find our conf.pl file
2 BEGIN { 
3     use FindBin; 
4     require "$FindBin::Bin/inc/conf.pl";
5 }
6
7 use strict;
8
9 use Module::Load;
10 use Test::More eval { load 'CPANPLUS::Internals::Source::SQLite'; 1 }
11             ? 'no_plan'
12             : (skip_all => "SQLite engine not available");
13
14 use Data::Dumper;
15 use File::Basename qw[dirname];
16 use CPANPLUS::Error;
17 use CPANPLUS::Backend;
18 use CPANPLUS::Internals::Constants;
19
20 my $conf = gimme_conf();
21
22 ### make sure we use the SQLite engine
23 $conf->set_conf( source_engine => 'CPANPLUS::Internals::Source::SQLite' );
24
25 my $cb   = CPANPLUS::Backend->new( $conf );
26 my $mod  = TEST_CONF_MODULE;
27 my $auth = TEST_CONF_AUTHOR;
28
29 ok( $cb->reload_indices( update_source => 1 ),                 
30                                 "Building trees" );
31 ok( $cb->__sqlite_dbh,          "   Got a DBH " );
32 ok( $cb->__sqlite_file,         "   Got a DB file" );
33
34
35 ### make sure we have trees and they're hashes
36 {   ok( $cb->author_tree,       "Got author tree" );
37     isa_ok( $cb->author_tree,   "HASH" );
38
39     ok( $cb->module_tree,       "Got module tree" );
40     isa_ok( $cb->module_tree,   "HASH" );
41 }
42
43 ### save state, shouldn't work
44 {   CPANPLUS::Error->flush;
45     my $rv = $cb->save_state;
46     
47     ok( !$rv,                   "Saving state not implemented" );
48     like( CPANPLUS::Error->stack_as_string, qr/not implemented/i,
49                                 "   Diagnostics confirmed" );
50 }
51
52 ### test look ups
53 {   my %map = (
54         $auth   => 'author_tree',
55         $mod    => 'module_tree',
56     );
57     
58     while( my($str, $meth) = each %map ) {
59     
60         ok( $str,               "Trying to retrieve $str" );
61         ok( $cb->$meth( $str ), "   Got $str object via ->$meth" );
62         ok( $cb->$meth->{$str}, "   Got author object via ->{ $str }" );
63         ok( exists $cb->$meth->{ $str },
64                                 "       Testing exists() " );   
65         ok( not(exists( $cb->$meth->{ $$ } )),
66                                 "           And non-exists() " );
67         cmp_ok( scalar(keys(%{ $cb->$meth })), ">", 1,
68                                 "   Got keys()" );
69                                 
70         cmp_ok( scalar(keys(%{ $cb->$meth })), '==', scalar(keys(%{ $cb->$meth })),
71                                 "   Keys == Values" );
72
73         while( my($key,$val) = each %{ $cb->$meth } ) {
74             ok( $key,           "   Retrieved $key via each()" );
75             ok( $val,           "       And value" );
76             ok( ref $val,       "           Value is a ref: $val" );
77             can_ok( $val,       '_id' );
78         }            
79     }
80 }