Commit | Line | Data |
6aaee015 |
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 CPANPLUS::Backend; |
10 | use Test::More 'no_plan'; |
11 | use Data::Dumper; |
12 | |
13 | my $conf = gimme_conf(); |
14 | $conf->set_conf( verbose => 0 ); |
15 | |
16 | my $Class = 'CPANPLUS::Selfupdate'; |
17 | my $ModClass = "CPANPLUS::Selfupdate::Module"; |
18 | my $CB = CPANPLUS::Backend->new( $conf ); |
19 | my $Acc = 'selfupdate_object'; |
20 | my $Conf = $Class->_get_config; |
21 | my $Dep = TEST_CONF_PREREQ; # has to be in our package file && core! |
22 | my $Feat = 'some_feature'; |
23 | my $Prereq = { $Dep => 0 }; |
24 | |
25 | ### test the object |
26 | { ok( $CB, "New backend object created" ); |
27 | can_ok( $CB, $Acc ); |
28 | |
29 | ok( $Conf, "Got configuration hash" ); |
30 | |
31 | my $su = $CB->$Acc; |
32 | ok( $su, "Selfupdate object retrieved" ); |
33 | isa_ok( $su, $Class ); |
34 | } |
35 | |
36 | ### test the feature list |
37 | { ### start with defining our OWN type of config, as not all mentioned |
38 | ### modules will be present in our bundled package files. |
39 | ### XXX WHITEBOX TEST!!!! |
40 | { delete $Conf->{$_} for keys %$Conf; |
41 | $Conf->{'dependencies'} = $Prereq; |
42 | $Conf->{'core'} = $Prereq; |
43 | $Conf->{'features'}->{$Feat} = [ $Prereq, sub { 1 } ]; |
44 | } |
45 | |
46 | is_deeply( $Conf, $Class->_get_config, |
47 | "Config updated succesfully" ); |
48 | |
49 | my @feat = $CB->$Acc->list_features; |
50 | ok( scalar(@feat), "Features list returned" ); |
51 | |
52 | ### test if we get modules for each feature |
53 | for my $feat (@feat) { |
54 | my $meth = 'modules_for_feature'; |
55 | my @mods = $CB->$Acc->$meth( $feat ); |
56 | |
57 | ok( $feat, "Testing feature '$feat'" ); |
58 | ok( scalar( @mods ), " Module list returned" ); |
59 | |
60 | my $acc = 'is_installed_version_sufficient'; |
61 | for my $mod (@mods) { |
62 | isa_ok( $mod, "CPANPLUS::Module" ); |
63 | isa_ok( $mod, $ModClass ); |
64 | can_ok( $mod, $acc ); |
65 | ok( $mod->$acc, " Module uptodate" ); |
66 | } |
67 | |
68 | ### check if we can get a hashref |
69 | { my $href = $CB->$Acc->$meth( $feat, 1 ); |
70 | ok( $href, "Got result as hash" ); |
71 | isa_ok( $href, 'HASH' ); |
72 | is_deeply( $href, $Prereq, |
73 | " With the proper entries" ); |
74 | |
75 | } |
76 | |
77 | } |
78 | |
79 | ### find enabled features |
80 | { my $meth = 'list_enabled_features'; |
81 | can_ok( $Class, $meth ); |
82 | |
83 | my @list = $CB->$Acc->$meth; |
84 | ok( scalar(@list), "Retrieved enabled features" ); |
85 | is_deeply( [$Feat], \@list, |
86 | " Proper features found" ); |
87 | } |
88 | |
89 | ### find dependencies/core modules |
90 | for my $meth ( qw[list_core_dependencies list_core_modules] ) { |
91 | can_ok( $Class, $meth ); |
92 | |
93 | my @list = $CB->$Acc->$meth; |
94 | ok( scalar(@list), "Retrieved modules" ); |
95 | is( scalar(@list), 1, " 1 Found" ); |
96 | isa_ok( $list[0], $ModClass ); |
97 | is( $list[0]->name, $Dep, |
98 | " Correct module found" ); |
99 | |
100 | ### check if we can get a hashref |
101 | { my $href = $CB->$Acc->$meth( 1 ); |
102 | ok( $href, "Got result as hash" ); |
103 | isa_ok( $href, 'HASH' ); |
104 | is_deeply( $href, $Prereq, |
105 | " With the proper entries" ); |
106 | } |
107 | } |
108 | |
109 | ### now selfupdate ourselves |
110 | { ### XXX just test the mechanics, make sure install returns true |
111 | ### declare twice because warnings are hateful |
112 | ### declare in a block to quelch 'sub redefined' warnings. |
113 | { local *CPANPLUS::Selfupdate::Module::install = sub { 1 }; } |
114 | local *CPANPLUS::Selfupdate::Module::install = sub { 1 }; |
115 | |
116 | my $meth = 'selfupdate'; |
117 | can_ok( $Class, $meth ); |
118 | ok( $CB->$Acc->$meth( update => 'all'), |
119 | " Selfupdate successful" ); |
120 | } |
121 | } |
122 | |