Skip to content

Commit

Permalink
use Mojo::File for Mojo::Home tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 7, 2017
1 parent a4480d4 commit 7861725
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions t/mojo/home.t
Expand Up @@ -3,39 +3,38 @@ use Mojo::Base -strict;
BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll' }

use Test::More;
use Cwd qw(getcwd realpath);
use File::Spec::Functions qw(canonpath catdir catfile splitdir);
use FindBin;
use List::Util 'first';
use Mojo::File 'path';
use Mojo::HelloWorld;
use Mojo::Home;

# ENV detection
my $target = canonpath realpath getcwd;
my $cwd = path->to_abs;
{
local $ENV{MOJO_HOME} = '.';
my $home = Mojo::Home->new->detect;
is_deeply [splitdir canonpath($home->to_string)], [splitdir $target],
is_deeply path($home->to_string)->to_abs->to_array, $cwd->to_array,
'right path detected';
}

# Current working directory
my $original = catdir splitdir getcwd;
my $home = Mojo::Home->new->detect;
is_deeply [splitdir realpath getcwd], [splitdir $home], 'right path detected';

# Specific class detection
$INC{'MyClass.pm'} = 'MyClass.pm';
$home = Mojo::Home->new->detect('MyClass');
is_deeply [splitdir canonpath($home->to_string)], [splitdir $target],
{
local $INC{'MyClass.pm'} = 'MyClass.pm';
my $home = Mojo::Home->new->detect('MyClass');
is_deeply path($home->to_string)->to_abs->to_array, $cwd->to_array,
'right path detected';
}

# Current working directory
my $home = Mojo::Home->new->detect;
is_deeply path($home->to_string)->to_array, $cwd->to_array,
'right path detected';

# Path generation
$home = Mojo::Home->new($FindBin::Bin);
is $home->lib_dir, catdir(splitdir($FindBin::Bin), 'lib'), 'right path';
is $home->rel_file('foo.txt'), catfile(splitdir($FindBin::Bin), 'foo.txt'),
'right path';
is $home->rel_file('foo/bar.txt'),
catfile(splitdir($FindBin::Bin), 'foo', 'bar.txt'), 'right path';
my $path = path($FindBin::Bin);
is $home->lib_dir, $path->child('lib'), 'right path';
is $home->rel_file('foo.txt'), $path->child('foo.txt'), 'right path';
is $home->rel_file('foo/bar.txt'), $path->child('foo', 'bar.txt'), 'right path';

done_testing();

0 comments on commit 7861725

Please sign in to comment.