File-Stubb

 view release on metacpan or  search on metacpan

t/40_stubb.t  view on Meta::CPAN

#!/usr/bin/perl
use 5.016;
use strict;

use Test::More;

use File::Stubb;

use File::Path qw(remove_tree);
use File::Spec;
use File::Temp qw(tempdir);

use File::Stubb::Home;

my $TMPDIR = tempdir;
my $TMP = File::Spec->catfile($TMPDIR, 'stubb');
my $TEMPLATES = File::Spec->catfile(qw/t data templates/);

sub slurp {

    my ($file) = @_;

    local $/ = undef;
    open my $fh, '<', $file
        or die "Failed to open $file for reading: $!\n";
    my $slurp = <$fh>;
    close $fh;

    return $slurp;

}

sub new_stubb {

    local @ARGV = @_;

    return File::Stubb->init;

}

$ENV{ STUBB_TEMPLATES } = $TEMPLATES;

my $stubb;

$stubb = new_stubb($TMP, 'basic');
isa_ok($stubb, 'File::Stubb');

is($stubb->{ Mode }, 0, 'mode ok');
is_deeply(
    $stubb->{ Files },
    [ $TMP ],
    'files ok'
);
is($stubb->{ Template }, File::Spec->catfile($TEMPLATES, 'basic.stubb'), 'template ok');
is($stubb->{ Subst }, undef, 'subst ok');
is_deeply(
    $stubb->{ TempDir },
    [ $TEMPLATES, File::Spec->catfile(home, '.stubb') ],
    'template directory ok'
);
is($stubb->{ Verbose }, 1, 'verbose ok');
is($stubb->{ Hidden }, undef, 'hidden ok');
is($stubb->{ FollowLinks }, undef, 'follow symlinks ok');
is($stubb->{ CopyPerms }, undef, 'copy perms ok');
is($stubb->{ Defaults }, undef, 'defaults ok');
is($stubb->{ IgnoreConf }, undef, 'ignore config ok');

ok($stubb->run, "stubb doesn't die");

is(
    slurp($TMP),
    <<'HERE',
My favorite number: ^^one^^
My third favorite number: ^^three^^
My three favorite numbers: ^^one^^, ^^two^^, ^^three^^, 4
HERE
    'file render ok'
);

unlink $TMP;

$stubb = new_stubb("$TMP.basic");
isa_ok($stubb, 'File::Stubb');

ok($stubb->run, "stubb doesn't die");
ok(-f "$TMP.basic", 'file render ok');

unlink "$TMP.basic";

$stubb = new_stubb('-t', 'basic', $TMP);
isa_ok($stubb, 'File::Stubb');

ok($stubb->run, "stubb doesn't die");
ok(-f $TMP, 'file render ok');



( run in 1.616 second using v1.01-cache-2.11-cpan-b16cb0d3907 )