Skip to content

Commit

Permalink
fix more Windows bugs (closes #1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 10, 2017
1 parent d69f603 commit b4400a6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/Mojo/File.pm
Expand Up @@ -14,7 +14,7 @@ use File::Copy ();
use File::Find ();
use File::Path ();
use File::Spec::Functions
qw(abs2rel catfile file_name_is_absolute rel2abs splitdir);
qw(abs2rel canonpath catfile file_name_is_absolute rel2abs splitdir);
use File::Temp ();
use Mojo::Collection;

Expand All @@ -38,7 +38,7 @@ sub list {
@files = map { catfile $$self, $_ } @files;
@files = grep { !-d } @files unless $options->{dir};

return Mojo::Collection->new(map { $self->new($_) } sort @files);
return Mojo::Collection->new(map { $self->new(canonpath($_)) } sort @files);
}

sub list_tree {
Expand Down Expand Up @@ -72,7 +72,7 @@ sub move_to {

sub new {
my $class = shift;
my $value = @_ == 1 ? $_[0] : @_ > 1 ? catfile @_ : getcwd;
my $value = @_ == 1 ? $_[0] : @_ > 1 ? catfile @_ : canonpath getcwd;
return bless \$value, ref $class || $class;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/Home.pm
Expand Up @@ -10,8 +10,9 @@ sub detect {
my $detected;
if ($ENV{MOJO_HOME}) { $detected = Mojo::File->new($ENV{MOJO_HOME})->to_abs }

# Location of the application class
# Location of the application class (Windows mixes slash and backslash)
elsif ($class && (my $path = $INC{my $file = class_to_path $class})) {
$path =~ s/\\/\//g;
$path =~ s/(?:\/b?lib)?\/\Q$file\E$//;
$detected = Mojo::File->new($path)->to_abs;
}
Expand Down
8 changes: 4 additions & 4 deletions t/mojo/file.t
Expand Up @@ -3,14 +3,14 @@ use Mojo::Base -strict;
use Test::More;
use Cwd 'getcwd';
use File::Basename qw(basename dirname);
use File::Spec::Functions qw(abs2rel catfile rel2abs splitdir);
use File::Spec::Functions qw(abs2rel canonpath catfile rel2abs splitdir);
use File::Temp;
use Mojo::File qw(path tempdir);

# Constructor
is(Mojo::File->new, getcwd(), 'same path');
is path(), getcwd(), 'same path';
is path()->to_string, getcwd(), 'same path';
is(Mojo::File->new, canonpath(getcwd), 'same path');
is path(), canonpath(getcwd), 'same path';
is path()->to_string, canonpath(getcwd), 'same path';
is path('/foo/bar'), '/foo/bar', 'same path';
is path('foo', 'bar', 'baz'), catfile('foo', 'bar', 'baz'), 'same path';

Expand Down
6 changes: 3 additions & 3 deletions t/mojo/home.t
Expand Up @@ -19,23 +19,23 @@ use Mojo::Home;
# Specific class detection
{
my $fake = path->to_abs->child('does_not_exist_2');
local $INC{'My/Class.pm'} = $fake->child('My', 'Class.pm');
local $INC{'My/Class.pm'} = $fake->child('My', 'Class.pm')->to_string;
my $home = Mojo::Home->new->detect('My::Class');
is_deeply $home->to_array, $fake->to_array, 'right path detected';
}

# Specific class detection (with "lib")
{
my $fake = path->to_abs->child('does_not_exist_3');
local $INC{'My/Class.pm'} = $fake->child('lib', 'My', 'Class.pm');
local $INC{'My/Class.pm'} = $fake->child('lib', 'My', 'Class.pm')->to_string;
my $home = Mojo::Home->new->detect('My::Class');
is_deeply $home->to_array, $fake->to_array, 'right path detected';
}

# Specific class detection (with "blib")
{
my $fake = path->to_abs->child('does_not_exist_3');
local $INC{'My/Class.pm'} = $fake->child('blib', 'My', 'Class.pm');
local $INC{'My/Class.pm'} = $fake->child('blib', 'My', 'Class.pm')->to_string;
my $home = Mojo::Home->new->detect('My::Class');
is_deeply $home->to_array, $fake->to_array, 'right path detected';
}
Expand Down

0 comments on commit b4400a6

Please sign in to comment.