App-Module-Template

 view release on metacpan or  search on metacpan

t/get_config.t  view on Meta::CPAN


use Test::More tests => 5;
use Test::Exception;

use File::Spec;

use_ok( 'App::Module::Template', '_get_config' );

ok( my $config_file = File::Spec->catfile( File::Spec->curdir, 't/.module-template/config' ), 'set config file' );

throws_ok{ _get_config() } qr/\ACould not read configuration file/, 'fails without config file';

ok( my $cfg = _get_config($config_file), 'get config file' );

is( ref $cfg, 'HASH', 'returns hash reference' );

t/get_config_path.t  view on Meta::CPAN

use Test::Exception;

use File::Spec;

use_ok( 'App::Module::Template', '_get_config_path' );

ok( my $template_dir = File::Spec->catdir( File::Spec->curdir, 't', '.module-template', 'templates' ), 'set template dir' );

ok( my $config_file = File::Spec->catfile( File::Spec->curdir, 't', '.module-template', 'config' ), 'set config file' );

throws_ok{ _get_config_path(undef, 'some') } qr/\ACould not locate configuration file/, 'fails for non-existent file';

is( _get_config_path($config_file), $config_file, 'returns config file' );

ok( my $ret_config = File::Spec->catfile( File::Spec->curdir, 't', '.module-template', 'templates', '..', 'config' ), 'set return config' );

is( _get_config_path(undef, $template_dir), $ret_config, 'returns config file' );

t/get_template_path.t  view on Meta::CPAN

use Test::Exception;

use File::HomeDir;
use File::Path qw/remove_tree make_path/;
use File::Spec;

use_ok( 'App::Module::Template', '_get_template_path' );

ok( my $path = File::Spec->catdir( File::Spec->curdir, 'test_dir' ), 'set path' );

throws_ok{ _get_template_path($path) } qr/\ATemplate directory/, 'fails for non-existent template path';

ok( make_path($path), 'create template path' );

ok( -d $path, 'template path exists' );

is( _get_template_path($path), $path, 'returns path' );

ok( remove_tree($path), 'removing path' );

is( -d $path, undef, 'path removed' );

t/module_template.t  view on Meta::CPAN


SKIP: {
    skip( "test doesn't exist", 1) unless -d $test_dir;
    ok( remove_tree($test_dir), 'remove test directory' );
}

ok( my $mt_test_dir = File::Spec->catdir( $test_dir, '.module-template' ), 'set test module dir' );

is( module_template($test_dir), $mt_test_dir, 'module_template() w/ test dir' );

throws_ok{ module_template($test_dir) } qr/Directory/, 'fails on existing directory';

ok( my $tmpl_dir = File::Spec->catdir( $mt_test_dir, 'templates' ), 'set template dir' );

ok( -f File::Spec->catfile( $mt_test_dir, 'config') , 'config exists' );
ok( -f File::Spec->catfile( $tmpl_dir, '.gitignore' ), '.gitignore exists' );
ok( -f File::Spec->catfile( $tmpl_dir, '.travis.yml' ), '.travis.yml exists' );
ok( -f File::Spec->catfile( $tmpl_dir, 'Changes' ), 'Changes exists' );
ok( -f File::Spec->catfile( $tmpl_dir, 'LICENSE'), 'LICENSE exists' );
ok( -f File::Spec->catfile( $tmpl_dir, 'Makefile.PL' ), 'Makefile.PL exists' );
ok( -f File::Spec->catfile( $tmpl_dir, 'README' ), 'README exists' );

t/process_dirs_abs.t  view on Meta::CPAN


ok( my $cant_read = File::Spec->catdir( File::Spec->curdir, 'cant_read' ), 'set cant_read' );

ok( make_path($cant_read), 'create cant_read' );

SKIP: {
    skip( 'Running under windows', 2 ) if $^O eq 'MSWin32';

    ok( chmod(oct(0400), $cant_read), 'make cant_read unreadable' );

    throws_ok{ _process_dirs($abs_tt2, $tmpl_vars, $abs_tmpl_path, $cant_read) } qr/\ACouldn't open directory/, '_process_dirs() fails on unreadable output path';
}

ok( remove_tree($cant_read), 'removing cant_read path' );

is( -d $cant_read, undef, 'cant_read path is removed' );

ok( _process_dirs($abs_tt2, $tmpl_vars, $abs_tmpl_path, $abs_tmpl_path), '_process_dirs() w/ absolute paths' );

ok( -d File::Spec->catdir( $abs_output_path, 'bin' ), 'bin exists' );
ok( -d File::Spec->catdir( $abs_output_path, 'lib' ), 'lib exists' );

t/process_template.t  view on Meta::CPAN

ok( my $fake_tmpl_path = File::Spec->catdir( File::Spec->curdir, 'some-non-dir' ), 'set fake template path' );

ok( my $abs_tmpl_path = File::Spec->catfile( File::Spec->curdir, 't', '.module-template', 'templates', 'Changes' ), 'set fake template path' );
#
ok( my $abs_output_path = File::Spec->catdir( File::Spec->curdir, 'test_dir' ), 'set output path' );

ok( my $tt2 = Template->new({ABSOLUTE => 1, OUTPUT_PATH => $abs_output_path}), 'create absolute TT2 object' );

ok( my $tmpl_vars = {}, 'set $tmpl_vars' );

throws_ok{ _process_template($tt2, $tmpl_vars, $fake_tmpl_path, undef) } qr/some/, '_process_template throws error';

ok( _process_template($tt2, $tmpl_vars, $abs_tmpl_path, undef), '_process_template()' );

t/run-badname.t  view on Meta::CPAN

use_ok( 'App::Module::Template', 'run' );

ok( my $module_dir = File::Spec->catdir( File::Spec->curdir, 'some-test' ), 'set module directory' );

# make sure we have a clean environment
SKIP: {
    skip( 'module directory does not exist', 1 ) unless -d $module_dir;
    ok( remove_tree($module_dir), 'remove module directory' );
}

throws_ok{ run(@ARGV) } qr/'some::test' is an all lower-case namespace/, 'run croaks on bad module name';

t/run-direxist.t  view on Meta::CPAN

ok( my $module_dir = File::Spec->catdir( File::Spec->curdir, 'Some-Test' ), 'set module directory' );

# make sure we have a clean environment
SKIP: {
    skip( 'module directory does not exist', 1 ) unless -d $module_dir;
    ok( remove_tree($module_dir), 'remove module directory' );
}

ok( make_path($module_dir), 'create module path' );

throws_ok{ run(@ARGV) } qr/Destination directory $module_dir/, 'run croaks on existing module directory';

SKIP: {
    skip( 'module directory does not exist', 1 ) unless -d $module_dir;
    ok( remove_tree($module_dir), 'remove module directory' );
}

t/run-nomod-switch.t  view on Meta::CPAN

use_ok( 'App::Module::Template', 'run' );

ok( my $module_dir = File::Spec->catdir( File::Spec->curdir, 'Some-Test' ), 'set module directory' );

# make sure we have a clean environment
SKIP: {
    skip( 'module directory does not exist', 1 ) unless -d $module_dir;
    ok( remove_tree($module_dir), 'removing module directory' );
}

throws_ok{ run(@ARGV) } qr/-m <Module::Name> is required\. exiting/, 'run() exists with no -m';

ok( @ARGV = ('-m'), 'set @ARGV with no module name' );

throws_ok{ run(@ARGV) } qr/-m <Module::Name> is required\. exiting/, 'run() exists with no -m';

t/validate_module_name.t  view on Meta::CPAN

ok($module_name = 'Valid::Module::With::Levels', 'set valid module name');

ok(_validate_module_name($module_name), 'valid module name with many levels');

ok($module_name = 'ALL::CAPS', 'set valid module name');

ok(_validate_module_name($module_name), 'valid module name with all caps');

ok($module_name = 'TopLevel', 'set top-level module name');

throws_ok{ _validate_module_name($module_name) } qr/'$module_name' is a top-level namespace/, 'top-level namespace';

ok($module_name = 'lower::case', 'set lower-case module name');

throws_ok{ _validate_module_name($module_name) } qr/'$module_name' is an all lower-case namespace/, 'lower-case namespace';

ok($module_name = 'all::lower::case', 'set multiple lower case namespaces');

throws_ok{ _validate_module_name($module_name) } qr/'$module_name' is an all lower-case namespace/, 'multiple lower-case namespaces';

ok($module_name = 'Invalid::lowercase', 'set module name with mixed lower-case');

throws_ok{ _validate_module_name($module_name) } qr/'$module_name' does not meet naming requirements/, 'Mixed namespaces with lower-case';

ok($module_name = 'Not:Enough', 'set module name without enough colons');

throws_ok{ _validate_module_name($module_name) } qr/'$module_name' does not meet naming requirements/, 'Module with one colon';

t/write_tmpl_file.t  view on Meta::CPAN

is( _write_tmpl_file(), undef, 'returns w/o args' );

is( _write_tmpl_file($test_path), undef, 'returns w/o template name' );

is( _write_tmpl_file(undef, $tmpl_name), undef, 'returns w/o base path' );

is( _write_tmpl_file($test_path, 'nothing'), undef, 'returns w/ invalid key' );

ok( my $fqfn = File::Spec->catfile( $test_path, $tmpl_path, 'Changes' ), 'set file name' );

throws_ok{ _write_tmpl_file($test_path, $tmpl_name) } qr/\ACouldn't open /, 'write template file fails on bad path';

ok( _make_tmpl_path($test_path, $tmpl_name), 'create template path' );

is( _write_tmpl_file($test_path, $tmpl_name), $fqfn, 'write template file' );

ok( -f $fqfn, 'file exists' );

ok( remove_tree($test_path), 'removing test path' );

is( -d $test_path, undef, 'test path removed' );



( run in 0.320 second using v1.01-cache-2.11-cpan-496ff517765 )