add Module::Build 0.27_08
[p5sagit/p5-mst-13.2.git] / lib / Module / Build / t / signature.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest;
6
7 if ( $ENV{TEST_SIGNATURE} ) {
8   if ( have_module( 'Module::Signature' ) ) {
9     plan tests => 7;
10   } else {
11     plan skip_all => '$ENV{TEST_SIGNATURE} is set, but Module::Signature not found';
12   }
13 } else {
14   plan skip_all => '$ENV{TEST_SIGNATURE} is not set';
15 }
16
17 #########################
18
19 use Cwd ();
20 my $cwd = Cwd::cwd;
21 my $tmp = File::Spec->catdir( $cwd, 't', '_tmp' );
22
23 use DistGen;
24 my $dist = DistGen->new( dir => $tmp );
25 $dist->change_file( 'Build.PL', <<"---" );
26 use Module::Build;
27
28 my \$build = new Module::Build(
29   module_name => @{[$dist->name]},
30   license     => 'perl',
31   sign        => 1,
32 );
33 \$build->create_build_script;
34 ---
35 $dist->regen;
36
37 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
38
39 #########################
40
41 use Module::Build;
42
43 my $mb = Module::Build->new_from_context;
44
45
46 {
47   eval {$mb->dispatch('distdir')};
48   is $@, '';
49   chdir( $mb->dist_dir ) or die "Can't chdir to '@{[$mb->dist_dir]}': $!";
50   ok -e 'SIGNATURE';
51   
52   # Make sure the signature actually verifies
53   ok Module::Signature::verify() == Module::Signature::SIGNATURE_OK();
54   chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
55 }
56
57 {
58   # Fake out Module::Signature and Module::Build - the first one to
59   # run should be distmeta.
60   my @run_order;
61   {
62     local $^W; # Skip 'redefined' warnings
63     local *Module::Signature::sign              = sub { push @run_order, 'sign' };
64     local *Module::Build::Base::ACTION_distmeta = sub { push @run_order, 'distmeta' };
65     eval { $mb->dispatch('distdir') };
66   }
67   is $@, '';
68   is $run_order[0], 'distmeta';
69   is $run_order[1], 'sign';
70 }
71
72 eval { $mb->dispatch('realclean') };
73 is $@, '';
74
75
76 # cleanup
77 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
78 $dist->remove;
79
80 use File::Path;
81 rmtree( $tmp );