~ubuntu-branches/ubuntu/precise/libmodule-signature-perl/precise-updates

« back to all changes in this revision

Viewing changes to t/wrap.pl

  • Committer: Bazaar Package Importer
  • Author(s): Jotam Jr. Trejo, Jotam Jr. Trejo, gregor herrmann
  • Date: 2011-05-13 21:19:36 UTC
  • mfrom: (1.1.8 upstream) (3.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20110513211936-yp0kp1q4knv7kao3
Tags: 0.68-1
[ Jotam Jr. Trejo ]
* New upstream release
* Bump DH compat level to 8

[ gregor herrmann ]
* Don't run test that needs network access.
* Clean up (build) dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# use 5.010;
 
4
use strict;
 
5
use warnings;
 
6
 
 
7
=head1 NAME
 
8
 
 
9
 
 
10
 
 
11
=head1 SYNOPSIS
 
12
 
 
13
  t/wrap.pl -c # for create
 
14
 
 
15
  t/wrap.pl -x # for extract
 
16
 
 
17
=head1 OPTIONS
 
18
 
 
19
=over 8
 
20
 
 
21
=cut
 
22
 
 
23
my @opt = <<'=back' =~ /B<-(\S+)>/g;
 
24
 
 
25
=item B<-c>
 
26
 
 
27
Wrap the test files into wrapper file
 
28
 
 
29
=item B<-f>
 
30
 
 
31
Path to the wrapper file. Defaults to t/wrapped-tests.bin.
 
32
 
 
33
=item B<-help|h!>
 
34
 
 
35
This help
 
36
 
 
37
=item B<-x>
 
38
 
 
39
Unwrap the test files from the wrapper file
 
40
 
 
41
=back
 
42
 
 
43
=head1 DESCRIPTION
 
44
 
 
45
The t/ directory contains tests for different line endings. To
 
46
distribute these tests we wrap them into a Data::Dumper file to avoid
 
47
problems on distribution verification.
 
48
 
 
49
Called with -c we create the wrapping file. Called with -x we unwrap
 
50
the files and install them into place.
 
51
 
 
52
The test t/3-verify.t calls us with -x.
 
53
 
 
54
When anything changes that breaks 3-verify.t, then the procedure to
 
55
create new test files is something like the following:
 
56
 
 
57
(1) call wrap.pl -x
 
58
 
 
59
(2) edit files in t/test*; take care that the files in test-datlf*
 
60
    have Unix line endings and the files in test-datcrlf* have DOS
 
61
    line endings. Apart from that keep the files identical
 
62
 
 
63
(3) sign in t/test-datlf-sigold/ with an old version of Module::Signature
 
64
 
 
65
(4) copy the signature over to t/test-datcrlf-sigold/
 
66
 
 
67
(5) sign in t/test-datlf-signew/ with the upcoming version of
 
68
    Module::Signature
 
69
 
 
70
(6) copy the signature over to t/test-datcrlf-signew/
 
71
 
 
72
(7) call wrap.pl -c
 
73
 
 
74
=cut
 
75
 
 
76
 
 
77
use FindBin;
 
78
use lib "$FindBin::Bin/../lib";
 
79
BEGIN {
 
80
    push @INC, qw(       );
 
81
}
 
82
 
 
83
use Data::Dumper;
 
84
use File::Basename qw(dirname);
 
85
use File::Path qw(mkpath);
 
86
use File::Spec;
 
87
use Getopt::Long;
 
88
use Pod::Usage;
 
89
 
 
90
our %Opt;
 
91
GetOptions(\%Opt,
 
92
           @opt,
 
93
          ) or pod2usage(1);
 
94
 
 
95
$Opt{f} ||= "t/wrapped-tests.bin";
 
96
 
 
97
sub _f ($) {File::Spec->catfile(split /\//, shift);}
 
98
 
 
99
my @files = qw(t/test-datcrlf-signew/MANIFEST
 
100
t/test-datcrlf-signew/README
 
101
t/test-datcrlf-signew/42.gz
 
102
t/test-datcrlf-signew/SIGNATURE
 
103
t/test-datcrlf-sigold/MANIFEST
 
104
t/test-datcrlf-sigold/README
 
105
t/test-datcrlf-sigold/42.gz
 
106
t/test-datcrlf-sigold/SIGNATURE
 
107
t/test-datlf-signew/MANIFEST
 
108
t/test-datlf-signew/README
 
109
t/test-datlf-signew/42.gz
 
110
t/test-datlf-signew/SIGNATURE
 
111
t/test-datlf-sigold/MANIFEST
 
112
t/test-datlf-sigold/README
 
113
t/test-datlf-sigold/42.gz
 
114
t/test-datlf-sigold/SIGNATURE
 
115
);
 
116
my @paths = map { _f($_) } @files;
 
117
 
 
118
if ($Opt{c}) {
 
119
    my $VAR;
 
120
    for my $i (0..$#files) {
 
121
        open my $fh, "<", $paths[$i] or die "Could not open '$paths[$i]': $!";
 
122
        binmode $fh;
 
123
        local $/;
 
124
        $VAR->{$files[$i]} = <$fh>;
 
125
    }
 
126
    my $d = Data::Dumper->new([$VAR]);
 
127
    $d->Useqq(1)->Sortkeys(1);
 
128
    open my $fh, ">", _f($Opt{f}) or die "Could not open $Opt{f}: $!";
 
129
    binmode $fh;
 
130
    print $fh $d->Dump;
 
131
} elsif ($Opt{x}) {
 
132
    open my $fh, "<", _f($Opt{f}) or die "Could not open $Opt{f}: $!";
 
133
    binmode $fh;
 
134
    local $/;
 
135
    my $VAR1;
 
136
    eval <$fh>;
 
137
    close $fh;
 
138
    for my $i (0..$#files) {
 
139
        mkpath dirname $paths[$i];
 
140
        open my $fh, ">", $paths[$i] or die "Could not open '$paths[$i]': $!";
 
141
        binmode $fh;
 
142
        local $\;
 
143
        print $fh $VAR1->{$files[$i]};
 
144
        close $fh or die "Could not write $paths[$i]: $!";
 
145
    }
 
146
} else {
 
147
    warn "Either of the options -x or -c must be specified";
 
148
    pod2usage(1);
 
149
}
 
150
 
 
151
# Local Variables:
 
152
# mode: cperl
 
153
# cperl-indent-level: 4
 
154
# End: