1 # sample.t -- a sample test file for Module::Build
10 # Ensure any Module::Build modules are loaded from correct directory
11 blib_load('Module::Build');
13 my $dist = DistGen->new->regen->chdir_in;
15 # get a Module::Build object and test with it
18 ok( $mb = $dist->new_from_context, "Default Build.PL" );
21 ok( ! $mb->needs_compiler, "needs_compiler is false" );
22 ok( ! exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'},
23 "ExtUtils::CBuilder is not in build_requires"
26 #--------------------------------------------------------------------------#
28 #--------------------------------------------------------------------------#
29 $dist->change_build_pl({
30 module_name => $dist->name,
36 ok( $mb = $dist->new_from_context,
37 "Build.PL with c_source"
40 is( $mb->c_source, 'src', "c_source is set" );
41 ok( $mb->needs_compiler, "needs_compiler is true" );
42 ok( exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'},
43 "ExtUtils::CBuilder was added to build_requires"
46 #--------------------------------------------------------------------------#
48 #--------------------------------------------------------------------------#
49 $dist = DistGen->new(dir => 'MBTest', xs => 1);
54 ok( $mb = $dist->new_from_context,
55 "Build.PL with xs files"
58 ok( $mb->needs_compiler, "needs_compiler is true" );
59 ok( exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'},
60 "ExtUtils::CBuilder was added to build_requires"
63 #--------------------------------------------------------------------------#
64 # force needs_compiler off, despite xs modules
65 #--------------------------------------------------------------------------#
67 $dist->change_build_pl({
68 module_name => $dist->name,
75 ok( $mb = $dist->new_from_context ,
76 "Build.PL with xs files, but needs_compiler => 0"
79 is( $mb->needs_compiler, 0, "needs_compiler is false" );
80 ok( ! exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'},
81 "ExtUtils::CBuilder is not in build_requires"
84 #--------------------------------------------------------------------------#
85 # don't override specific EU::CBuilder build_requires
86 #--------------------------------------------------------------------------#
88 $dist->change_build_pl({
89 module_name => $dist->name,
91 build_requires => { 'ExtUtils::CBuilder' => 0.2 },
96 ok( $mb = $dist->new_from_context ,
97 "Build.PL with xs files, build_requires EU::CB 0.2"
100 ok( $mb->needs_compiler, "needs_compiler is true" );
101 is( $mb->build_requires->{'ExtUtils::CBuilder'}, 0.2,
102 "build_requires for ExtUtils::CBuilder is correct version"
105 #--------------------------------------------------------------------------#
106 # falsify compiler and test error handling
107 #--------------------------------------------------------------------------#
109 # clear $ENV{CC} so we are sure to fail to find our fake compiler :-)
112 my $err = stderr_of( sub {
113 $mb = $dist->new_from_context( config => { cc => "adfasdfadjdjk" } )
115 ok( $mb, "Build.PL while hiding compiler" );
116 like( $err, qr/no compiler detected/,
117 "hidden compiler resulted in warning message during Build.PL"
119 eval { $mb->dispatch('build') };
120 like( $@, qr/no compiler detected/,
121 "hidden compiler resulted in fatal message during Build"
125 # vim:ts=2:sw=2:et:sta:sts=2