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
|
use strict;
use warnings;
use Test::More 0.88;
use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';
use Test::DZil;
use Path::Tiny;
use File::pushd 'pushd';
my $tzil = Builder->from_config(
{ dist_root => 'does-not-exist' },
{
add_files => {
path(qw(source dist.ini)) => simple_ini(
[ GatherDir => ],
[ ExecDir => ],
[ 'FileFinder::ByName' => ExtraTestFiles => { dir => 'xt' } ],
[ 'Test::EOL' => { finder => [ ':InstallModules', ':TestFiles' ], file => [ 'examples/foo' ] } ],
),
path(qw(source lib Foo.pm)) => <<'MODULE',
package Foo;
use strict;
use warnings;
1;
MODULE
path(qw(source lib Bar.pod)) => <<'POD',
package Bar;
=pod
=cut
POD
path(qw(source bin myscript)) => <<'SCRIPT',
use strict;
use warnings;
print "hello there!\n";
SCRIPT
path(qw(source t foo.t)) => <<'TEST',
use strict;
use warnings;
use Test::More tests => 1;
pass('hi!');
TEST
path(qw(source examples foo)) => <<'EXAMPLE',
use strict;
use warnings;
print "hello there!\n";
EXAMPLE
},
},
);
$tzil->chrome->logger->set_debug(1);
$tzil->build;
my $build_dir = path($tzil->tempdir)->child('build');
my $file = $build_dir->child(qw(xt author eol.t));
ok( -e $file, 'test created');
my $content = $file->slurp_utf8;
unlike($content, qr/[^\S\n]\n/, 'no trailing whitespace in generated test');
unlike($content, qr/\t/m, 'no tabs in generated test');
my @files = (
path(qw(lib Foo.pm)),
path(qw(lib Bar.pod)),
path(qw(t foo.t)),
path(qw(examples foo)),
);
like($content, qr/'\Q$_\E'/m, "test checks $_") foreach @files;
unlike($content, qr/'\Q$_\E'/m, "test does not check $_") foreach (
path(qw(bin myscript)),
path(qw(xt bar.t)),
);
# not needed, but Test::EOL (pre-1.5) loads it from the generated test, and $0
# is wrong for it
use FindBin;
my $files_tested;
subtest 'run the generated test' => sub
{
my $wd = pushd $build_dir;
do $file;
note 'ran tests successfully' if not $@;
fail($@) if $@;
$files_tested = Test::Builder->new->current_test;
};
is($files_tested, @files, 'correct number of files were tested');
diag 'got log messages: ', explain $tzil->log_messages
if not Test::Builder->new->is_passing;
done_testing;
|