1 ### make sure we can find our conf.pl file
4 require "$FindBin::Bin/inc/conf.pl";
8 use Test::More 'no_plan';
10 use CPANPLUS::Backend;
12 my $Class = 'CPANPLUS';
13 my $ModName = TEST_CONF_MODULE;
14 my $Conf = gimme_conf();
15 my $CB = CPANPLUS::Backend->new( $Conf );
17 ### so we get an object with *our* configuration
18 no warnings 'redefine';
19 local *CPANPLUS::Backend::new = sub { $CB };
23 ### install / get / fetch tests
24 for my $meth ( qw[fetch get install] ) {
25 my $sub = $Class->can( $meth );
26 ok( $sub, "$Class->can( $meth )" );
33 ok( 1, "Trying '$meth' in different configurations" );
35 while( my($rv, $re) = each %map ) {
37 ### don't actually install, just test logic
38 no warnings 'redefine';
39 local *CPANPLUS::Module::install = sub { $rv };
40 local *CPANPLUS::Module::fetch = sub { $rv };
42 CPANPLUS::Error->flush;
44 my $ok = $sub->( $ModName );
45 is( $ok, $rv, " Expected RV: $rv" );
46 like( CPANPLUS::Error->stack_as_string, $re,
47 " With expected diagnostic" );
50 ### does not take objects / references
51 { CPANPLUS::Error->flush;
53 my $ok = $sub->( [] );
54 ok( !$ok, "'$meth' with reference does not work" );
55 like( CPANPLUS::Error->stack_as_string, qr/object/,
56 " Error as expected");
60 { CPANPLUS::Error->flush;
63 ok( !$ok, "'$meth' without argument does not work" );
64 like( CPANPLUS::Error->stack_as_string, qr/No module specified/,
65 " Error as expected");
71 my $sub = $Class->can( $meth );
73 ok( $sub, "$Class->can( $meth )" );
75 { ### test package for shell() method
76 package CPANPLUS::Shell::Test;
78 ### ->shell() looks in %INC
79 use Module::Loaded qw[mark_as_loaded];
80 mark_as_loaded( __PACKAGE__ );
82 sub new { bless {}, __PACKAGE__ };
86 my $rv = $sub->( 'Test' );
87 ok( $rv, " Shell started" );
88 is( $rv, $$, " Proper shell called" );