ef57558e5bfa310d585fd3426559fac5028cbd17
[dh-make-perl] / dev / arm / libmodule-build-perl / libmodule-build-perl-0.2808.01 / 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 = MBTest->tmpdir;
22
23 use DistGen;
24 my $dist = DistGen->new( dir => $tmp );
25 $dist->change_build_pl
26 ({
27   module_name => $dist->name,
28   license     => 'perl',
29   sign        => 1,
30 });
31 $dist->regen;
32
33 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
34
35 #########################
36
37 use Module::Build;
38
39 my $mb = Module::Build->new_from_context;
40
41
42 {
43   eval {$mb->dispatch('distdir')};
44   is $@, '';
45   chdir( $mb->dist_dir ) or die "Can't chdir to '@{[$mb->dist_dir]}': $!";
46   ok -e 'SIGNATURE';
47   
48   # Make sure the signature actually verifies
49   ok Module::Signature::verify() == Module::Signature::SIGNATURE_OK();
50   chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
51 }
52
53 {
54   # Fake out Module::Signature and Module::Build - the first one to
55   # run should be distmeta.
56   my @run_order;
57   {
58     local $^W; # Skip 'redefined' warnings
59     local *Module::Signature::sign              = sub { push @run_order, 'sign' };
60     local *Module::Build::Base::ACTION_distmeta = sub { push @run_order, 'distmeta' };
61     eval { $mb->dispatch('distdir') };
62   }
63   is $@, '';
64   is $run_order[0], 'distmeta';
65   is $run_order[1], 'sign';
66 }
67
68 eval { $mb->dispatch('realclean') };
69 is $@, '';
70
71
72 # cleanup
73 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
74 $dist->remove;
75
76 use File::Path;
77 rmtree( $tmp );