File: loadcfg.t

package info (click to toggle)
libcpan-mini-inject-perl 1.012-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 352 kB
  • sloc: perl: 732; makefile: 4
file content (91 lines) | stat: -rw-r--r-- 2,076 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use strict;
use warnings;

use File::Path qw(make_path);
use File::Spec::Functions qw(catfile);
use File::Temp ();

use Test::More;

my $class = 'CPAN::Mini::Inject';

$SIG{'INT'} = sub { print "\nCleaning up before exiting\n"; exit 1 };
my $temp_dir = File::Temp::tempdir(CLEANUP=>1);

subtest 'sanity' => sub {
	use_ok $class;
	can_ok $class, qw(new loadcfg);
	};

subtest nothing => sub {
	delete local $ENV{HOME};
	delete local $ENV{MCPANI_CONFIG};

	my $mcpi = $class->new;
	isa_ok $mcpi, $class;
	can_ok $mcpi, qw(loadcfg);

	my $config_path = catfile $temp_dir, 'nothing-config';
	write_config($config_path);
	ok -e $config_path, 'config path exists';

	ok eval { $mcpi->loadcfg( $config_path ); 1 }, 'loadcfg works';
	ok exists $mcpi->{cfgfile}, 'cfgfile key exists';
	is( $mcpi->{cfgfile}, $config_path );
	};

my $mcpani_dir = catfile $temp_dir, '.mcpani';
subtest 'setup .mcpani' => sub {
	make_path $mcpani_dir;
	ok -e $mcpani_dir, '.mcpani dir exists';
	};

subtest HOME => sub {
	local $ENV{HOME} = $temp_dir;

	my $mcpi = $class->new;
	isa_ok $mcpi, $class;
	can_ok $mcpi, qw(loadcfg);

	my $config_path = catfile $mcpani_dir, 'home-config';
	write_config($config_path);
	ok -e $config_path, 'config path exists';

	ok eval { $mcpi->loadcfg( $config_path ); 1 }, 'loadcfg works';
	ok exists $mcpi->{cfgfile}, 'cfgfile key exists';
	is( $mcpi->{cfgfile}, $config_path );
	};

subtest MCPANI_CONFIG => sub {
	local $ENV{MCPANI_CONFIG} = catfile $temp_dir, 'env-config';

	my $mcpi = $class->new;
	isa_ok $mcpi, $class;
	can_ok $mcpi, qw(loadcfg);

	my $config_path = $ENV{MCPANI_CONFIG};
	write_config($config_path);
	ok -e $config_path, 'config path exists';

	ok eval { $mcpi->loadcfg( $config_path ); 1 }, 'loadcfg works';
	ok exists $mcpi->{cfgfile}, 'cfgfile key exists';
	is( $mcpi->{cfgfile}, $ENV{MCPANI_CONFIG},  );
	};

done_testing();

sub write_config {
	my( $path ) = @_;

	open my $fh, '>', $path;

	print {$fh} <<"HERE";
local: t/local/CPAN
remote : http://localhost:11027
repository: t/local/MYCPAN
dirmode: 0775
passive: yes
HERE

	close $fh;
	}