NAME

Test::Dist::Zilla::BuiltFiles - Check files built by your Dist::Zilla plugin

VERSION

Version v0.4.3_01, released on 2016-12-19 22:05 UTC. This is a trial release.

SYNOPSIS

# Let's test Manifest Dist::Zilla plugin:

use strict;
use warnings;

use Test::Deep qw{ re };
use Test::More;
use Test::Routine;
use Test::Routine::Util;

with 'Test::Dist::Zilla::Build';
with 'Test::Dist::Zilla::BuiltFiles';

run_me 'A test' => {
    plugins => [
        'GatherDir',
        'Manifest',
        'MetaJSON',
    ],
    files => {
        'lib/Dummy.pm' => 'package Dummy; 1;',
    },
    expected => {
        files => {
            'MANIFEST' => [
                re( qr{^# This file was } ),
                'MANIFEST',
                'META.json',
                'dist.ini',
                'lib/Dummy.pm',
            ],
        },
    },
};

done_testing;

DESCRIPTION

This is a Test::Routine-based role for testing Dist::Zilla and its plugins. It is intended to be used in cooperation with Test::Dist::Zilla::Build role. Test::Dist::Zilla::Build builds the distribution and checks exception and build messages, while Test::Dist::Zilla::BuiltFiles checks built files.

OBJECT METHODS

BuiltFiles

It is a test routine. It checks built files. Names of files to check should be be enlisted in files key of expected hash. Value should be HashRef, keys are filenames, values are file content. For every file the test routine checks the file exists and its actual content matches the expected content. If expected content is undef, the file should not exist.

File content may be specified either by Str or by ArrayRef:

run_me {
    …
    expected => {
        files => {
            'filename1' => "line1\nline2\n",
            'filename2' => [
                'line1',            # Should not include newline character.
                'line2',
                re( '^#' ),         # See "Special Comparisons" in Test::Deep.
            ],
            'filename3' => undef,   # This file should not exist.
        },
    },
};

Actual file content is compared with expected file content by cmp_deeply routine from Test::Deep.

BuiltFiles assumes successful build. If an exception occurred, BuiltFiles skips all the checks.

SEE ALSO

Test::Dist::Zilla
Test::Dist::Zilla::Build
"$ok = cmp_deeply($got, $expected, $name)" in Test::Deep
Test::Routine

AUTHOR

Van de Bugger <van.de.bugger@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2015, 2016 Van de Bugger

License GPLv3+: The GNU General Public License version 3 or later <http://www.gnu.org/licenses/gpl-3.0.txt>.

This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.