Dist::...:dztest(3pm)
π Dist::Zilla::Util::Test::KENTNL::dztest β the manual page, but make it make sense π
okay bestie, so this is the dztest page from the Dist::Zilla::Util::Test::KENTNL family, and it lives in section 3pm of the perl docs. it's the shared dist-testing logic that makes dzil stuff easy to test. yes, the real name up top is Dist::...:dztest(3pm) because perl doc tooling loves to abbreviate, but you and me both know what it is π«Ά
β¨ NAME β¨
Dist::Zilla::Util::Test::KENTNL::dztest β the shared dist testing logic for easy dzil things. it's giving "one helper to rule all your test files" energy π
πΈ VERSION πΈ
version 1.005014 β that's the one, no cap.
π¦ SYNOPSIS π¦
here's the whole vibe in one go, literally copy-paste territory:
use Test::More;
use Test::DZil qw( simple_ini );
use Dist::Zilla::Util::Test::KENTNL qw( dztest );
my $test = dztest;
## utility method.
$test->add_file( 'dist.ini', simple_ini( .... ));
## build the dist
# 1x subtest
$test->build_ok;
## assert prereqs are identical to the hash
## extracting them from distmeta
# 1x subtest
$test->prereqs_deeply( { } );
## Test for specific log messages by regex
# 1x subtest
# - tests there are messages
# - each regex must match a message
my @list = (
[ $regex, $indepdent_reason ],
[ $regex ],
);
$test->has_messages( $reason, \@list );
## Test for any deep structure addressed
## By a Data::DPath expression
# 1x subtest
# - asserts the expression returns a result
# - compares the structure against the expected one.
$test->meta_path_deeply(
'/author/*/[1]',
[ 'E. Xavier Ample <example@example.org>' ],
'The 1st author is the example author emitted by simple_ini'
);
## Test for a file existing on the build side
## and return it if it exists.
my $file = $test->test_has_built_file('dist.ini');
like, that's the whole tour. slay π
π METHODS π
π "add_file"
drop a file into the scratch directory so it can be built later. think of it as prepping your little dist before the glow-up β¨
# ->add_file( $path, $string );
# ->add_file( \@path, $string );
$test->add_file('dist.ini', simple_ini() );
$test->add_file('lib/Foo.pm', $content );
$test->add_file([ 'lib','Foo.pm' ], $content );
π "build_ok"
build the dist safely, and report "ok" if the dist builds "ok", spewing file listings via "note".
bestie, heads up:"BAIL_OUT"gets triggered if any of your"add_file"calls don't arrive in the intended location. so if your file is missing, the whole thing nopes out. no silent failures here π
π "prereqs_deeply"
demand that "distmeta" "prereqs" exactly match the ones you specified. exact match. not "close enough". exact. periodt.
$test->prereqs_deeply( { hash } );
this is literally just a more memorable version of:
$test->meta_path_deeply('/prereqs/', { });
π "has_messages"
test that there are messages, and that all the given rules match messages. every regex has to land on something, fr fr.
$test->has_messages( 'Some descriptor', [
[ $regex, $description ],
[ $regex, $description ],
]);
π "meta_path_deeply"
$test->meta_path_deeply( $expression, $expected_data, $reason );
uses $expression as a "Data::DPath" expression to pick a LIST of nodes from "distmeta", and compares that LIST vs $expected_data. π§
# Matches only the first author.
$test->meta_path_deeply('/author/*/[1]', ['SomeAuthorName <wadef@wath>'], $reason );
# Matches all authors
$test->meta_path_deeply('/author/*/*', ['SomeAuthorName <wadef@wath>','Author2', ..], $reason );
π "test_has_built_file"
test (as in, "Test::More::ok") that a file exists in the "dzil" build output directory.
also returns it if it exists. so you get the verdict and the goods. two-for-one π
$test->test_has_built_file('dist.ini'); # ok/fail
my $object = test->test_has_built_file('dist.ini'); # ok/fail + return
π "create_plugin"
make an instance of the named plugin and hand it back to you. main character plugin energy π
my $t = dztest();
$t->add_file('dist.ini', simple_ini( ... ));
my $plugin = $t->create_plugin('GatherDir' => { ignore_dotfiles => 1 });
# poke at $plugin here
note: this lets you test plugins outside the requirement of interoperating with"dzil"phases, but the downside is that it doesn't interact with"dzil"phases β and it won't even be seen by"dzil"phases. yes, seen. with asterisks and everything. iconic. π
but that's totally OK if you want to directly test a module's interface instead of doing it through the proxy of "dzil".
and bonus: you can subsequently create many such objects without requiring a "dzil build" penalty. no tax, just vibes β¨
π "source_file"
re-fetch content you added with "add_file".
you probably want "built_file" though, just saying π
$test->source_file( $path );
$test->source_file( \@path );
returns "undef" if the file does not exist.
if ( my $content = $test->source_file('dist.ini') ) {
print $content->slurp_raw;
}
π "safe_build"
make sure the distribution is built safely, returns exceptions or "undef".
if ( $test->safe_build ) {
say "Failed build";
}
π "safe_configure"
construct the internal builder object safely. returns exceptions or "undef".
if( $test->configure ) { say "configure failed" }
π "built_file"
returns the named file if it exists in the build, "undef" otherwise. simple as. π¦
my $file = $test->built_file('dist.ini');
π "note_tempdir_files"
recursively walk "tempdir" and note its contents. a lil stroll through your temp dir π
π "note_builddir_files"
recursively walk "builddir"(output) and note its contents. same stroll, but the output side π
π "has_message"
assert there are messages, and that this single message exists:
$test->has_message( $regex, $description );
π "run_command"
execute a Dist::Zilla command in the constructed scratch directory.
$test->run_command(['build','foo']);
the syntax is technically:
$test->run_command( $argv, $arg );
but, and I quote the author's own vibe here, they're yet to work out the meaning of the latter. π honestly same.
π ATTRIBUTES π
πΈ "configure"
construct the internal builder object.
$test->configure;
π AUTHOR π
Kent Fredric <kentnl@cpan.org> β the legend themself.
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2017 by Kent Fredric <kentnl@cpan.org>.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie!! π this one's from the perl docs as shipped with perl v5.34.0, dated 2022-06-13, and it's the Dist::...:dztest(3pm) page under User Contributed Perl Documentation. go forth and test your dists, you absolute icon π«Άβ¨
π¦ where this page comes from
- debian bookworm: libdist-zilla-util-test-kentnl-perl 1.005014-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdist-zilla-util-test-kentnl-perl 1.005014-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdist-zilla-util-test-kentnl-perl 1.005014-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdist-zilla-util-test-kentnl-perl 1.005014-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdist-zilla-util-test-kentnl-perl 1.005014-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms