File: home.t

package info (click to toggle)
perlbrew 0.86-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 704 kB
  • sloc: perl: 8,459; makefile: 7; sh: 1
file content (75 lines) | stat: -rw-r--r-- 1,771 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
68
69
70
71
72
73
74
75
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib $FindBin::Bin;
use App::perlbrew;
require "test_helpers.pl";

use Test::Deep qw[];
use Test::Spec;

sub looks_like_perlbrew_home;

local $App::perlbrew::PERLBREW_HOME = '/perlbrew/home';
local $ENV{PERLBREW_HOME} = '/env/home';
local $ENV{HOME} = '/home';

describe "App::perlbrew#home method" => sub {
    it "should return \$App::perlbrew::PERLBREW_HOME if provided" => sub {
        my $app = App::perlbrew->new;

        looks_like_perlbrew_home $app->home, '/perlbrew/home';
    };

    it "should default to \$ENV{PERLBREW_HOME} if provided" => sub {
		local $App::perlbrew::PERLBREW_HOME;

        my $app = App::perlbrew->new;

        looks_like_perlbrew_home $app->home, '/env/home';
    };

    it "should default to \$ENV{HOME} subpath" => sub {
		local $App::perlbrew::PERLBREW_HOME;
		local $ENV{PERLBREW_HOME};

        my $app = App::perlbrew->new;

        looks_like_perlbrew_home $app->home, '/home/.perlbrew';
    };

    it "should return the instance property of 'home' if set" => sub {
        my $app = App::perlbrew->new;
        $app->home("/fnord");

        looks_like_perlbrew_home $app->home, "/fnord";
    };
};

runtests unless caller;

sub looks_like_perlbrew_home {
	my ($got, $expected) = @_;

	my ($ok, $stack);

	($ok, $stack) = Test::Deep::cmp_details "$got", "$expected";
	unless ($ok) {
		fail;
		diag "Return value comparison failed";
		diag Test::Deep::deep_diag $stack;
		return;
	}

	($ok, $stack) = Test::Deep::cmp_details "$got", "$App::perlbrew::PERLBREW_HOME";
	unless ($ok) {
		fail;
		diag "Global \$PERLBREW_HOME comparison failed";
		diag Test::Deep::deep_diag $stack;
		return;
	}

	return Test::Deep::cmp_deeply $got, Isa ('App::Perlbrew::Path');
}