File: 20_formatter.t

package info (click to toggle)
libdist-zilla-plugin-run-perl 0.050-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 444 kB
  • sloc: perl: 580; makefile: 2
file content (157 lines) | stat: -rw-r--r-- 6,982 bytes parent folder | download | duplicates (2)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
use strict;
use warnings;
use Test::More 0.88;
use Test::DZil;
use Test::Deep;
use Path::Tiny;

for my $trial (0, 1) {
    local $ENV{TRIAL} = $trial;
    my $tzil = Builder->from_config(
        { dist_root => 'does-not-exist' },
        {
            add_files => {
                path(qw(source dist.ini)) => simple_ini(
                    [ GatherDir => ],
                    [ MetaConfig => ],

                    [ 'Run::BeforeBuild' => { run => [ '"%x" %o%pscript%prun.pl before_build %s %n %v%t %o.%d.%a. %x' ] } ],
                    [ 'Run::AfterBuild' => { run => [ '"%x" %o%pscript%prun.pl after_build %n %v%t %o %d %s %s %v%t .%a. %x' ] } ],
                    [ 'Run::BeforeArchive' => { run => [ '"%x" %o%pscript%prun.pl before_archive %o %d %v%t %n %a %x' ] } ],
                    [ 'Run::BeforeRelease' => { run => [ '"%x" %o%pscript%prun.pl before_release %n -d %o %d %s -v %v%t .%a. %x' ] } ],
                    [ 'Run::Release' => { run => [ '"%x" %o%pscript%prun.pl release %s %n %v%t %o %d/a %d/b %a %x' ] } ],
                    [ 'Run::AfterRelease' => { run => [ '"%x" %o%pscript%prun.pl after_release %o %d %v%t %s %s %n %a %x' ] } ],
                ),
                path(qw(source lib Foo.pm)) => "package Foo;\n1;\n",
                path(qw(source script run.pl)) => <<'SCRIPT',
use strict;
use warnings;

# I do nothing!
SCRIPT
            },
        },
    );

    my $source_dir = 'fakesource';
    my $build_dir = 'fakebuild';

    my %f = (
        a => 'DZT-Sample-0.001.tar.gz',
        n => 'DZT-Sample',
        o => $source_dir,
        d => $build_dir,
        v => '0.001',
        t => $tzil->is_trial ? '-TRIAL' : '',
    );

    my $formatter = $tzil->plugin_named('Run::AfterRelease')->build_formatter({
        archive   => $f{a},
        source_dir => $source_dir,
        dir       => $build_dir,
        pos       => [qw(run run reindeer)]
    });

    is $formatter->format('snowflakes/%v%t|%n\\%s,%s,%s,%s in %o %d(%a)'),
        "snowflakes/$f{v}$f{t}|$f{n}\\run,run,reindeer, in $f{o} $f{d}($f{a})",
        'correct formatting';

    is $formatter->format('%v%t%s%n'), "$f{v}$f{t}$f{n}", 'ran out of %s (but not the constants)';

    $tzil->chrome->logger->set_debug(1);
    $tzil->release;

    cmp_deeply(
        $tzil->distmeta,
        superhashof({
            x_Dist_Zilla => superhashof({
                plugins => supersetof(
                    {
                        class => 'Dist::Zilla::Plugin::Run::BeforeBuild',
                        config => {
                            'Dist::Zilla::Plugin::Run::Role::Runner' => {
                                run => [ '"%x" %o%pscript%prun.pl before_build %s %n %v%t %o.%d.%a. %x' ],
                                fatal_errors => 1,
                                quiet => 0,
                                version => Dist::Zilla::Plugin::Run::Role::Runner->VERSION,
                            },
                        },
                        name => 'Run::BeforeBuild',
                        version => Dist::Zilla::Plugin::Run::BeforeBuild->VERSION,
                    },
                    {
                        class => 'Dist::Zilla::Plugin::Run::AfterBuild',
                        config => {
                            'Dist::Zilla::Plugin::Run::Role::Runner' => {
                                run => [ '"%x" %o%pscript%prun.pl after_build %n %v%t %o %d %s %s %v%t .%a. %x' ],
                                fatal_errors => 1,
                                quiet => 0,
                                version => Dist::Zilla::Plugin::Run::Role::Runner->VERSION,
                            },
                        },
                        name => 'Run::AfterBuild',
                        version => Dist::Zilla::Plugin::Run::AfterBuild->VERSION,
                    },
                    {
                        class => 'Dist::Zilla::Plugin::Run::BeforeArchive',
                        config => {
                            'Dist::Zilla::Plugin::Run::Role::Runner' => {
                                run => [ '"%x" %o%pscript%prun.pl before_archive %o %d %v%t %n %a %x' ],
                                fatal_errors => 1,
                                quiet => 0,
                                version => Dist::Zilla::Plugin::Run::Role::Runner->VERSION,
                            },
                        },
                        name => 'Run::BeforeArchive',
                        version => Dist::Zilla::Plugin::Run::BeforeArchive->VERSION,
                    },
                    {
                        class => 'Dist::Zilla::Plugin::Run::BeforeRelease',
                        config => {
                            'Dist::Zilla::Plugin::Run::Role::Runner' => {
                                run => [ '"%x" %o%pscript%prun.pl before_release %n -d %o %d %s -v %v%t .%a. %x' ],
                                fatal_errors => 1,
                                quiet => 0,
                                version => Dist::Zilla::Plugin::Run::Role::Runner->VERSION,
                            },
                        },
                        name => 'Run::BeforeRelease',
                        version => Dist::Zilla::Plugin::Run::BeforeRelease->VERSION,
                    },
                    {
                        class => 'Dist::Zilla::Plugin::Run::Release',
                        config => {
                            'Dist::Zilla::Plugin::Run::Role::Runner' => {
                                run => [ '"%x" %o%pscript%prun.pl release %s %n %v%t %o %d/a %d/b %a %x' ],
                                fatal_errors => 1,
                                quiet => 0,
                                version => Dist::Zilla::Plugin::Run::Role::Runner->VERSION,
                            },
                        },
                        name => 'Run::Release',
                        version => Dist::Zilla::Plugin::Run::Release->VERSION,
                    },
                    {
                        class => 'Dist::Zilla::Plugin::Run::AfterRelease',
                        config => {
                            'Dist::Zilla::Plugin::Run::Role::Runner' => {
                                run => [ '"%x" %o%pscript%prun.pl after_release %o %d %v%t %s %s %n %a %x' ],
                                fatal_errors => 1,
                                quiet => 0,
                                version => Dist::Zilla::Plugin::Run::Role::Runner->VERSION,
                            },
                        },
                        name => 'Run::AfterRelease',
                        version => Dist::Zilla::Plugin::Run::AfterRelease->VERSION,
                    },
                ),
            }),
        }),
        'dumped configs are good',
    ) or diag 'got distmeta: ', explain $tzil->distmeta;

    diag 'got log messages: ', explain $tzil->log_messages
        if not Test::Builder->new->is_passing;
}

done_testing;