File: bashrc_content.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 (65 lines) | stat: -rw-r--r-- 1,556 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
#!/usr/bin/env perl
use strict;
use warnings;

use App::perlbrew;

use Test::Spec;

local $App::perlbrew::PERLBREW_ROOT;
local %ENV;

sub describe_bashrc_content;

describe "App::perlbrew->BASHRC_CONTENT()" => sub {
	context "should not export custom PERLBREW_ROOT" => sub {
		describe_bashrc_content "with default settings" => (
		);

		describe_bashrc_content "when set only via global variable" => (
			PERLBREW_ROOT => 'perlbrew/root',
		);
	};

	context "should export custom PERLBREW_ROOT" => sub {
		describe_bashrc_content "when env variable PERLBREW_ROOT is set" => (
			ENV_PERLBREW_ROOT => 'env/root',
			should_match => 'env/root',
		);

		describe_bashrc_content "when provided via argument" => (
			args => [qw[ --root arg/root ]],
			should_match => "arg/root",
		);

		describe_bashrc_content "when provided via argument (favor over env)" => (
			args => [qw[ --root arg/root ]],
			ENV_PERLBREW_ROOT => 'env/root',
			should_match => "arg/root",
		);

	};

};

runtests unless caller;

sub describe_bashrc_content {
	my ($title, %params) = @_;

	it $title => sub {
		local %ENV = (
			HOME => 'default/home',
			(PERLBREW_ROOT => $params{ENV_PERLBREW_ROOT}) x!! exists $params{ENV_PERLBREW_ROOT},
		);
		local $App::perlbrew::PERLBREW_ROOT = $params{PERLBREW_ROOT} || $ENV{PERLBREW_ROOT};

		my $app = App::perlbrew->new (@{ $params{args} || [] });

		return ok $app->BASHRC_CONTENT =~ m{^export PERLBREW_ROOT=\Q$params{should_match}\E}m
			if $params{should_match};

		return ok $app->BASHRC_CONTENT !~ m{^export PERLBREW_ROOT=}m;
	};
}