Move CPANPLUS from lib/ to ext/
[p5sagit/p5-mst-13.2.git] / ext / CPANPLUS / t / 09_CPANPLUS-Internals-Search.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';
9use Data::Dumper;
10use CPANPLUS::Backend;
11use CPANPLUS::Internals::Constants;
12
13my $Conf = gimme_conf();
14my $CB = CPANPLUS::Backend->new($Conf);
15my $ModName = TEST_CONF_MODULE;
16my $Mod = $CB->module_tree( $ModName );
17
18
19### search for modules ###
20for my $type ( CPANPLUS::Module->accessors() ) {
21
22 ### don't muck around with references/objects
23 ### or private identifiers
24 next if ref $Mod->$type() or $type =~/^_/;
25
26 my @aref = $CB->search(
27 type => $type,
28 allow => [$Mod->$type()],
29 );
30
31 ok( scalar @aref, "Module found by '$type'" );
32 for( @aref ) {
33 ok( IS_MODOBJ->($_)," Module isa module object" );
34 }
35}
36
37### search for authors ###
38my $auth = $Mod->author;
39for my $type ( CPANPLUS::Module::Author->accessors() ) {
4443dd53 40
41 ### don't muck around with references/objects
42 ### or private identifiers
43 next if ref $auth->$type() or $type =~/^_/;
44
6aaee015 45 my @aref = $CB->search(
46 type => $type,
47 allow => [$auth->$type()],
48 );
49
50 ok( @aref, "Author found by '$type'" );
51 for( @aref ) {
52 ok( IS_AUTHOBJ->($_), " Author isa author object" );
53 }
54}
55
56
57{ my $warning = '';
58 local $SIG{__WARN__} = sub { $warning .= "@_"; };
59
60 { ### try search that will yield nothing ###
61 ### XXX SOURCEFILES FIX
62 my @list = $CB->search( type => 'module',
63 allow => [$ModName.$$] );
64
65 is( scalar(@list), 0, "Valid search yields no results" );
66 is( $warning, '', " No warnings issued" );
67 }
68
69 { ### try bogus arguments ###
70 my @list = $CB->search( type => '', allow => ['foo'] );
71
72 is( scalar(@list), 0, "Broken search yields no results" );
73 like( $warning, qr/^Key 'type'.* is of invalid type for/,
74 " Got a warning for wrong arguments" );
75 }
76}
77
78# Local variables:
79# c-indentation-style: bsd
80# c-basic-offset: 4
81# indent-tabs-mode: nil
82# End:
83# vim: expandtab shiftwidth=4: