Scroll to navigation

Dist::Zilla::Util::Test::KENTNL::dztest(3pm) User Contributed Perl Documentation Dist::Zilla::Util::Test::KENTNL::dztest(3pm)


Dist::Zilla::Util::Test::KENTNL::dztest - Shared dist testing logic for easy dzil things


version 1.005014


  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
  ## 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.
      [ 'E. Xavier Ample <>' ],
      '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');



Add a file to the scratch directory to be built.

  # ->add_file( $path, $string );
  # ->add_file( \@path, $string );
  $test->add_file('dist.ini', simple_ini() );
  $test->add_file('lib/', $content );
  $test->add_file([ 'lib','' ], $content );


Build the dist safely, and report "ok" if the dist builds "ok", spewing file listings via "note"

"BAIL_OUT" is triggered if any of "add_file" don't arrive in the intended location.


Demand "distmeta" "prereqs" exactly match those specified.

  $test->prereqs_deeply( { hash } );

This is just a more memorable version of

  $test->meta_path_deeply('/prereqs/', { });


Test that there are messages, and all the given rules match messages.

  $test->has_messages( 'Some descriptor', [
     [ $regex, $description ],
     [ $regex, $description ],


  $test->meta_path_deeply( $expression, $expected_data, $reason );

Uses $expression as a "Data::DPath" expression to pick a LIST of nodes from "distmeta", and compare 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 ( as in, "Test::More::ok" ) that a file exists in the "dzil" build output directory.

Also returns it if it exists.

  $test->test_has_built_file('dist.ini');  # ok/fail
  my $object = test->test_has_built_file('dist.ini'); # ok/fail + return


Create an instance of the named plugin and return it.

  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 inter-operating with "dzil" phases, but has the downside of not interacting with "dzil" phases, or even being *seen* by "dzil" phases.

But this is OK if you want to directly test a modules interface instead of doing it through the proxy of "dzil"

You can also subsequently create many such objects without requiring a "dzil build" penalty.


Re-fetch content added with "add_file".

You probably want "built_file".

  $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;


Ensure the distribution is built safely, returns exceptions or "undef".

  if ( $test->safe_build ) {
    say "Failed build";


Construct the internal builder object safely. Returns exceptions or "undef".

  if( $test->configure ) { say "configure failed" }


Returns the named file if it exists in the build, "undef" otherwise.

  my $file = $test->built_file('dist.ini');


Recursively walk "tempdir" and note its contents.


Recursively walk "builddir"(output) and note its contents.


Assert there are messages, and this single message exists:

  $test->has_message( $regex, $description );


Execute a Dist::Zilla command in the constructed scratch directory.


The syntax is technically:

  $test->run_command( $argv, $arg );

But I'm yet to work out the meaning of the latter.



Construct the internal builder object.



Kent Fredric <>


This software is copyright (c) 2017 by Kent Fredric <>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2022-06-13 perl v5.34.0