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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
use strict;
use warnings;
use Test::More 0.88;
use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';
use Test::DZil;
use Test::Fatal;
use Test::Deep;
use Path::Tiny;
use lib 't/lib';
use TestHelper;
# protect from external environment
local $ENV{TRIAL};
local $ENV{RELEASE_STATUS};
my $command = 'Path::Tiny::path(\'%o\', \'eval_out.txt\')->append_raw(';
my $tzil = Builder->from_config(
{ dist_root => 'does-not-exist' },
{
add_files => {
path(qw(source dist.ini)) => simple_ini(
[ GatherDir => ],
[ MetaConfig => ],
[ FakeRelease => ],
[ 'Run::BeforeBuild' => {
eval => [ $command . '\'before_build for [\' . $_[0]->plugin_name . \'], %s %n %v .%d.%a. %x\' . qq{\\n});' ] } ],
[ 'Run::AfterBuild' => {
eval => [ $command . '\'after_build for [\' . $_[0]->plugin_name . \'], %n %v %d %s %s %v .%a. %x\' . qq{\\n});' ] } ],
[ 'Run::BeforeArchive' => {
eval => [ $command . '\'before_archive for [\' . $_[0]->plugin_name . \'], %n %v %d .%a. %x\' . qq{\\n});' ] } ],
[ 'Run::BeforeRelease' => {
eval => [ $command . '\'before_release for [\' . $_[0]->plugin_name . \'], %n -d %d %s -v %v .%a. %x\' . qq{\\n});' ] } ],
[ 'Run::Release' => {
eval => [ $command . '\'release for [\' . $_[0]->plugin_name . \'], %s %n %v %d/a %d/b %a %x\' . qq{\\n});' ] } ],
[ 'Run::AfterRelease' => {
eval => [ $command . '\'after_release for [\' . $_[0]->plugin_name . \'], %d %v %s %s %n %a %x\' . qq{\\n});' ] } ],
),
path(qw(source lib Foo.pm)) => "package Foo;\n1;\n",
},
},
);
$tzil->chrome->logger->set_debug(1);
is(
exception { $tzil->release },
undef,
'build proceeds normally',
);
my $build_dir = path($tzil->tempdir)->child('build');
my $source_dir = path($tzil->tempdir)->child('source');
my %f = (
a => 'DZT-Sample-0.001.tar.gz',
n => 'DZT-Sample',
o => $source_dir,
d => $build_dir,
v => '0.001',
x => do { my $path = Dist::Zilla::Plugin::Run::Role::Runner->current_perl_path; $path =~ s{\\}{/}g; $path },
);
# test constant conversions as well as positional %s for backward compatibility
my $expected = <<OUTPUT;
before_build for [Run::BeforeBuild], $f{v} $f{n} $f{v} ... $f{x}
after_build for [Run::AfterBuild], $f{n} $f{v} $f{d} $f{d} $f{v} $f{v} .. $f{x}
before_archive for [Run::BeforeArchive], $f{n} $f{v} $f{d} .. $f{x}
before_release for [Run::BeforeRelease], $f{n} -d $f{d} $f{a} -v $f{v} .$f{a}. $f{x}
release for [Run::Release], $f{a} $f{n} $f{v} $f{d}/a $f{d}/b $f{a} $f{x}
after_release for [Run::AfterRelease], $f{d} $f{v} $f{a} $f{v} $f{n} $f{a} $f{x}
OUTPUT
is_path(
$source_dir->child('eval_out.txt')->slurp_raw,
$expected,
'all phases evaluate their code directly',
);
cmp_deeply(
$tzil->distmeta,
superhashof({
x_Dist_Zilla => superhashof({
plugins => supersetof(
{
class => 'Dist::Zilla::Plugin::Run::BeforeBuild',
config => {
'Dist::Zilla::Plugin::Run::Role::Runner' => {
eval => [ $command . '\'before_build for [\' . $_[0]->plugin_name . \'], %s %n %v .%d.%a. %x\' . qq{\\n});' ],
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' => {
eval => [ $command . '\'after_build for [\' . $_[0]->plugin_name . \'], %n %v %d %s %s %v .%a. %x\' . qq{\\n});' ],
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' => {
eval => [ $command . '\'before_archive for [\' . $_[0]->plugin_name . \'], %n %v %d .%a. %x\' . qq{\\n});' ],
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' => {
eval => [ $command . '\'before_release for [\' . $_[0]->plugin_name . \'], %n -d %d %s -v %v .%a. %x\' . qq{\\n});' ],
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' => {
eval => [ $command . '\'release for [\' . $_[0]->plugin_name . \'], %s %n %v %d/a %d/b %a %x\' . qq{\\n});' ],
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' => {
eval => [ $command . '\'after_release for [\' . $_[0]->plugin_name . \'], %d %v %s %s %n %a %x\' . qq{\\n});' ],
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;
cmp_deeply(
[ grep /^\[Run::[^]]+\]/, @{ $tzil->log_messages } ],
[
'[Run::BeforeBuild] attempting to use %d in before_build',
'[Run::BeforeBuild] attempting to use %a in a non-Release plugin',
re(qr/^\Q[Run::BeforeBuild] evaluating: Path::Tiny::path('$source_dir', 'eval_out.txt')->append_raw('before_build \E/),
'[Run::AfterBuild] attempting to use %a in a non-Release plugin',
re(qr/^\Q[Run::AfterBuild] evaluating: Path::Tiny::path('$source_dir', 'eval_out.txt')->append_raw('after_build \E/),
'[Run::BeforeArchive] attempting to use %a in a non-Release plugin',
re(qr/^\Q[Run::BeforeArchive] evaluating: Path::Tiny::path('$source_dir', 'eval_out.txt')->append_raw('before_archive \E/),
re(qr/^\Q[Run::BeforeRelease] evaluating: Path::Tiny::path('$source_dir', 'eval_out.txt')->append_raw('before_release \E/),
re(qr/^\Q[Run::Release] evaluating: Path::Tiny::path('$source_dir', 'eval_out.txt')->append_raw('release \E/),
re(qr/^\Q[Run::AfterRelease] evaluating: Path::Tiny::path('$source_dir', 'eval_out.txt')->append_raw('after_release \E/),
],
'got diagnostics when code is evaluated',
);
diag 'got log messages: ', explain $tzil->log_messages
if not Test::Builder->new->is_passing;
done_testing;
|