summaryrefslogtreecommitdiff
path: root/t/data/regenerate-data
blob: f796f8fc2e4a8eefa26251ab6bbc73bc9f7f5840 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/perl
#
# Development helper program to regenerate test data.
#
# When the templates in the DocKnot package change, all of the tests will fail
# because the output is out of date.  This program regenerates all of the test
# output data using the local instance of App::DocKnot.  It should be run from
# the root of the DocKnot distribution directory.
#
# Copyright 2018-2022 Russ Allbery <rra@cpan.org>
#
# SPDX-License-Identifier: MIT

use 5.018;
use autodie;
use warnings;

use lib 'blib/lib';

use App::DocKnot;
use App::DocKnot::Generate;
use App::DocKnot::Spin;
use Path::Tiny qw(path);
use Pod::Thread;

# For each subdirectory of t/data/generate, regenerate each file in the output
# subdirectory using the metadata subdirectory and the template matching the
# output name.  Special-case the docknot subdirectory, which uses DocKnot's
# own metadata.
my $data = path('t', 'data', 'generate');
my @packages = map { $_->basename() } grep { $_->is_dir() } $data->children();
for my $package (@packages) {
    my $metadata;
    if ($package eq 'docknot') {
        $metadata = path('docs', 'docknot.yaml');
    } else {
        $metadata = $data->child($package, 'docknot.yaml');
    }
    my $output = $data->child($package, 'output');
    for my $template (map { $_->basename() } $output->children()) {
        my $docknot = App::DocKnot::Generate->new({ metadata => $metadata });
        $docknot->generate_output($template, $output->child($template));
    }
}

# The test of spinning a tree of files uses a reference to App::DocKnot's own
# POD documentation.  Regenerate the expected output in case the POD has
# changed.
my $source = path('lib', 'App', 'DocKnot.pm');
my $podthread = Pod::Thread->new(navbar => 1);
my $spin = App::DocKnot::Spin::Thread->new();
my $thread;
$podthread->output_string(\$thread);
$podthread->parse_file("$source");
my $html = $spin->spin_thread($thread);

# Add the additional metadata that should be added by spin.
my $links = <<'EOD';
  <link rel="stylesheet" href="/~eagle/styles/pod.css" type="text/css" />
  <link rel="next" href="app-docknot-command.html"
        title="App::DocKnot::Command" />
  <link rel="up" href="../" title="DocKnot" />
  <link rel="top" href="../../../" />
EOD
my $comment = '<!-- Spun from DocKnot.pm by DocKnot %VERSION% on %DATE% -->';
my $navbar = <<'EOD';
<table class="navbar"><tr>
  <td class="navleft"></td>
  <td>
    <a href="../../../">Russ Allbery</a>
    &gt; <a href="../../">Software</a>
    &gt; <a href="../">DocKnot</a>
  </td>
  <td class="navright"><a href="app-docknot-command.html">App::DocKnot::Command</a>&nbsp;&gt;</td>
</tr></table>
EOD
my $address = <<'EOD';
<address>
    Last <a href="https://www.eyrie.org/~eagle/software/web/">spun</a>
    %DATE% from thread modified %DATE%
</address>
EOD
$html =~ s{ (</head>) }{$links$1}xms;
$html =~ s{ <!-- [ ] Spun .*? [ ] --> }{$comment}xms;
$html =~ s{ (<body> \n) }{$1$navbar}xms;
$html =~ s{ (</body>) }{$navbar\n$address$1}xms;

# Replace the expected data file.
my $output = path(
    't', 'data', 'spin', 'output', 'software', 'docknot', 'api',
    'app-docknot.html',
);
$output->spew_utf8($html);