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 99 100 101 102 103 104 105
|
use strict;
use warnings;
use File::Spec;
use File::Basename;
use Test::More tests => 11;
{
package App;
use Moo;
with 'Dancer2::Core::Role::HasLocation';
}
note 'Defaults:'; {
my $app = App->new();
isa_ok( $app, 'App' );
can_ok( $app, qw<caller location> ); # attributes
can_ok( $app, '_build_location' ); # methods
ok(
$app->DOES('Dancer2::Core::Role::HasLocation'),
'App consumes Dancer2::Core::Role::HasLocation',
);
my $path = File::Spec->catfile(qw<
t classes Dancer2-Core-Role-HasLocation with.t
>);
is(
File::Spec->canonpath( $app->caller ),
$path,
'Default caller',
);
}
my $basedir = dirname( File::Spec->rel2abs(__FILE__) );
note 'With lib/ and bin/:'; {
my $app = App->new(
caller => File::Spec->catfile(
$basedir, qw<FakeDancerDir fake inner dir fakescript.pl>
)
);
isa_ok( $app, 'App' );
my $location = $app->location;
$location =~ s/\/$//;
my $path = File::Spec->rel2abs(
File::Spec->catdir(
File::Spec->curdir,
qw<t classes Dancer2-Core-Role-HasLocation FakeDancerDir>,
)
);
is(
$location,
$path,
'Got correct location with lib/ and bin/',
);
}
note 'With .dancer file:'; {
my $app = App->new(
caller => File::Spec->catfile(
$basedir, qw<FakeDancerFile script.pl>
)
);
isa_ok( $app, 'App' );
my $location = $app->location;
my $path = File::Spec->rel2abs(
File::Spec->catdir(
File::Spec->curdir,
qw<t classes Dancer2-Core-Role-HasLocation FakeDancerFile>,
)
);
is( $location, $path, 'Got correct location with .dancer file' );
}
note 'blib/ ignored:'; {
my $app = App->new(
caller => File::Spec->catfile(
$basedir, qw<FakeDancerDir blib lib fakescript.pl>
)
);
isa_ok( $app, 'App' );
my $location = $app->location;
$location =~ s/\/$//;
my $path = File::Spec->rel2abs(
File::Spec->catdir(
File::Spec->curdir,
qw<t classes Dancer2-Core-Role-HasLocation FakeDancerDir>,
)
);
is( $location, $path, 'blib/ dir is ignored' );
}
|