Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert t/mojo/home.t to use subtests #1569

Merged
merged 1 commit into from
Oct 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions t/mojo/home.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,57 @@ use Mojo::File qw(curfile path);
use Mojo::HelloWorld;
use Mojo::Home;

# ENV detection
{
subtest 'ENV detection' => sub {
my $fake = path->to_abs->child('does_not_exist');
local $ENV{MOJO_HOME} = $fake->to_string;
my $home = Mojo::Home->new->detect;
is_deeply $home->to_array, $fake->to_array, 'right path detected';
}
};

# Specific class detection
{
subtest 'Specific class detection' => sub {
my $fake = path->to_abs->child('does_not_exist_2');
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")
{
subtest 'Specific class detection (with "lib")' => sub {
my $fake = path->to_abs->child('does_not_exist_3');
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/lib")
{
subtest 'Specific class detection (with "blib/lib")' => sub {
my $fake = path->to_abs->child('does_not_exist_3');
local $INC{'My/Class.pm'} = $fake->child('blib', '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 (relative)
{
subtest 'Specific class detection (relative)' => sub {
local $INC{'My/Class.pm'} = path('My', 'Class.pm')->to_string;
my $home = Mojo::Home->new->detect('My::Class');
is_deeply $home->to_array, path->to_array, 'right path detected';
}
};

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

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

# Path generation
$home = Mojo::Home->new(curfile->dirname);
my $path = curfile->dirname;
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';
is $home->rel_file('foo/bar.txt')->basename, 'bar.txt', 'right result';
subtest 'Current working directory' => sub {
my $home = Mojo::Home->new->detect;
is_deeply $home->to_array, path->to_abs->to_array, 'right path detected';
};

subtest 'Path generation' => sub {
my $home = Mojo::Home->new(curfile->dirname);
my $path = curfile->dirname;
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';
is $home->rel_file('foo/bar.txt')->basename, 'bar.txt', 'right result';
};

done_testing();