Skip to content

Commit 1b60fca

Browse files
authored
Merge pull request #2977 from metacpan/haarg/static-file-regen
add regeneration to static-files.t test
2 parents 108dfec + 876e296 commit 1b60fca

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

t/static-files.t

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,66 @@ use Digest::SHA ();
1111
# normally use a new file name. If it's a minor change where it is acceptable
1212
# for users to use the old files, then updating the hash can be done instead.
1313

14+
## regenerate with: perl t/static-files.t --regen
15+
16+
for my $arg (@ARGV) {
17+
if ( $arg eq '--regen' ) {
18+
my @roots = qw(
19+
root/static/icons
20+
root/static/images
21+
);
22+
23+
my @files;
24+
25+
require File::Find;
26+
File::Find::find(
27+
{
28+
no_chdir => 1,
29+
wanted => sub {
30+
return
31+
if -d;
32+
return
33+
if m{\/\.} || m{~$};
34+
35+
push @files, $_;
36+
},
37+
},
38+
@roots,
39+
);
40+
41+
my %sha = map {
42+
$_ => Digest::SHA->new('sha1')->addfile( $_, 'b' )->hexdigest
43+
} @files;
44+
45+
my $script = $0;
46+
$script = "./$script"
47+
unless $script =~ m{^/};
48+
49+
open my $fh, '+<', $script
50+
or die;
51+
52+
while ( my $line = <$fh> ) {
53+
chomp $line;
54+
if ( $line eq '__DATA__' ) {
55+
truncate $fh, tell $fh;
56+
for my $file ( sort keys %sha ) {
57+
print $fh "$sha{$file} $file\n";
58+
}
59+
close $fh;
60+
61+
@ARGV = ();
62+
do $script or die;
63+
exit;
64+
}
65+
}
66+
67+
die "Can't find __DATA__ marker in $0!\n";
68+
}
69+
else {
70+
die "Unsupported option $arg!\n";
71+
}
72+
}
73+
1474
my %files = reverse map /(\S+)/g, <DATA>;
1575

1676
for my $file ( sort keys %files ) {
@@ -23,8 +83,6 @@ for my $file ( sort keys %files ) {
2383

2484
done_testing;
2585

26-
## generated with: shasum $(find root/static/icons root/static/images -type f | sort)
27-
2886
__DATA__
2987
679be699079a90f586aa90dbc79aac14731a226c root/static/icons/apple-touch-icon.png
3088
9352147a2cb97acb161f21202e9bfec29b6faa30 root/static/icons/favicon-16.ico
@@ -373,6 +431,7 @@ fb43b99a721b83aeebf528977f3df7083a69289e root/static/images/sponsors/perl-caree
373431
5cdd9d7bda9936c0ab678063a93df341fd37acb1 root/static/images/sponsors/perl_logo.png
374432
e691cd3eb125c4b9e157a083a1c0a5f14e5a692a root/static/images/sponsors/qah-2014.png
375433
bb659e08ba1966a9e6d90f9969ce89dd8c6a61b7 root/static/images/sponsors/servercentral.png
434+
b22714f31bf7817c297cf6670fa27c0fe53e9897 root/static/images/sponsors/sonic.png
376435
f251ab8c5c58c9c87bbd2e6042d9b2574cd0bc8b root/static/images/sponsors/speedchilli.png
377436
28b210ec069326d1914b54186854e278b874e08e root/static/images/sponsors/travis-ci.png
378437
d1756602e3883c084a901338b96d8a03b8b540b9 root/static/images/sponsors/vienna.pm.jpeg

0 commit comments

Comments
 (0)