1#!perl
2
3# This test suite ensures that Module::Starter::BuilderSet behaves
4
5use strict;
6use warnings;
7
8use Test::More tests => 17;
9
10eval { require Module::Starter::BuilderSet };
11
12ok(!$@, 'require Module::Starter::BuilderSet');
13
14my $bset = Module::Starter::BuilderSet->new;
15
16isa_ok($bset, 'Module::Starter::BuilderSet');
17
18can_ok($bset, qw( default_builder
19                  supported_builders
20                  file_for_builder
21                  instructions_for_builder
22                  deps_for_builder
23                  method_for_builder
24                  check_compatibility
25                )
26      );
27
28ok( ( grep { $bset->default_builder() eq $_ } $bset->supported_builders() ),
29    'default builder is in the list of supported builders'
30  );
31
32ok( ( !grep { !$bset->file_for_builder($_) } $bset->supported_builders() ),
33    'all supported builders claim to generate a file'
34  );
35
36ok( (!grep {!$bset->instructions_for_builder($_)} $bset->supported_builders()),
37    'all supported builders provide build instructions'
38  );
39
40foreach my $builder ( $bset->supported_builders() ){
41  foreach my $dep ($bset->deps_for_builder($builder)){
42
43    ok( exists $dep->{command} && $dep->{command} ne '',
44        "dependency command for '$builder' is set"
45      );
46
47    ok(exists $dep->{aliases} &&
48       ref $dep->{aliases} eq 'ARRAY' &&
49       int( @{ $dep->{aliases} } ) > 0,
50       "aliases look correct for builder '$builder', dep '$dep->{command}'"
51      );
52  }
53}
54
55use Module::Starter::Simple;
56my $simple = bless {}, 'Module::Starter::Simple';
57
58can_ok( $simple,
59        map { $bset->method_for_builder($_) } $bset->supported_builders()
60      );
61
62my @incompat =
63  (
64   'ExtUtils::MakeMaker',
65   'Module::Install',
66  );
67
68my @compat =
69  ( 'Module::Build',
70    'Module::Install',
71  );
72
73my @nonexistent =
74  ( 'CJAC::Boing',
75    'CJAC::Flop',
76  );
77
78ok( int( $bset->check_compatibility() ) == 1 &&
79    ( $bset->check_compatibility() )[0] eq $bset->default_builder(),
80    'check_compatibility() with no args returns default builder'
81  );
82
83my @return;
84
85# Capture warnings printed to STDERR
86{
87    local *STDERR;
88    open STDERR, q{>}, File::Spec->devnull();
89
90    @return = $bset->check_compatibility(@nonexistent);
91}
92ok( int( @return ) == 1 &&
93    $return[0] eq $bset->default_builder(),
94    'check_compatibility() with unsupported builder returns default builder'
95  );
96
97my @return2;
98# Capture warnings printed to STDERR
99{
100    local *STDERR;
101    open STDERR, q{>}, File::Spec->devnull();
102
103    @return  = $bset->check_compatibility(@incompat);
104    @return2 = $bset->check_compatibility(reverse @incompat);
105}
106
107ok( int( @return ) != int( @incompat ),
108    'check_compatibility() strips incompatible builder'
109  );
110
111ok( $return[0] eq $incompat[0] && $return2[0] eq $incompat[-1],
112    'check_compatibility() gives precidence to the first module passed'
113  );
114
115is_deeply( [($bset->check_compatibility(@compat))],
116           [@compat],
117           "check_compatibility() returns all compatible builders"
118         );
119
120# Capture warnings printed to STDERR
121{
122    local *STDERR;
123    open STDERR, q{>}, File::Spec->devnull();
124
125    @return = $bset->check_compatibility(@compat, @incompat, @nonexistent);
126}
127
128is_deeply( \@return, \@compat,
129           "check_compatibility() returns only compatible builders ".
130           "when given mixed set of compatible, incompatible and nonsense"
131         );
132