File: home.t

package info (click to toggle)
libmojolicious-perl 2.98%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,968 kB
  • sloc: perl: 10,178; sh: 48; makefile: 8
file content (67 lines) | stat: -rw-r--r-- 2,257 bytes parent folder | download
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
use Mojo::Base -strict;

# Disable libev
BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll' }

use Test::More tests => 15;

use Cwd qw(cwd realpath);
use File::Spec::Functions qw(canonpath catdir splitdir);
use FindBin;
use List::Util 'first';

# "Uh, no, you got the wrong number. This is 9-1... 2"
use Mojo::Home;

# ENV detection
{
  local $ENV{MOJO_HOME} = '.';
  my $home = Mojo::Home->new->detect;
  is_deeply [split /\\|\//, canonpath($home->to_string)],
    [split /\\|\//, canonpath(realpath cwd())], 'right path detected';
}

# Class detection
my $original = catdir(splitdir($FindBin::Bin), '..', '..');
my $home     = Mojo::Home->new->detect;
my $target   = realpath $original;
is_deeply [split /\\|\//, $target], [split /\\|\//, $home],
  'right path detected';

# Specific class detection
$INC{'MyClass.pm'} = 'MyClass.pm';
$home = Mojo::Home->new->detect('MyClass');
is_deeply [split /\\|\//, canonpath($home->to_string)],
  [split /\\|\//, canonpath(realpath cwd())], 'right path detected';

# FindBin detection
$home = Mojo::Home->new->app_class(undef)->detect;
is_deeply [split /\\|\//, catdir(splitdir($FindBin::Bin))],
  [split /\\|\//, $home], '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'), catdir(splitdir($FindBin::Bin), 'foo.txt'),
  'right path';
is $home->rel_file('foo/bar.txt'),
  catdir(splitdir($FindBin::Bin), 'foo', 'bar.txt'), 'right path';
is $home->rel_dir('foo'), catdir(splitdir($FindBin::Bin), 'foo'), 'right path';
is $home->rel_dir('foo/bar'), catdir(splitdir($FindBin::Bin), 'foo', 'bar'),
  'right path';

# List files
is first(sub {/Base1\.pm$/}, @{$home->list_files('lib')}), 'BaseTest/Base1.pm',
  'right result';
is first(sub {/Base2\.pm$/}, @{$home->list_files('lib')}), 'BaseTest/Base2.pm',
  'right result';
is first(sub {/Base3\.pm$/}, @{$home->list_files('lib')}), 'BaseTest/Base3.pm',
  'right result';

# Slurp files
like $home->slurp_rel_file('lib/BaseTest/Base1.pm'), qr/Base1/,
  'right content';
like $home->slurp_rel_file('lib/BaseTest/Base2.pm'), qr/Base2/,
  'right content';
like $home->slurp_rel_file('lib/BaseTest/Base3.pm'), qr/Base3/,
  'right content';