File: 02_main.t

package info (click to toggle)
libcpan-inject-perl 1.14-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 188 kB
  • sloc: perl: 1,589; makefile: 4
file content (146 lines) | stat: -rw-r--r-- 3,221 bytes parent folder | download | duplicates (4)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl

# Main testing for CPAN::Inject

use strict;
BEGIN {
	$|  = 1;
	$^W = 1;
}

use Test::More tests => 24;
use File::Spec::Functions ':ALL';
use File::Remove          'remove';
use CPAN::Inject;

# Create a testing root directory
my $sources = catdir('t', 'sources');
      if ( -e $sources ) { remove( \1, $sources ) }
END { if ( -e $sources ) { remove( \1, $sources ) } }
ok( ! -e $sources, 'No existing sources directory' );
mkdir $sources;
ok( -e $sources, 'Created sources directory' );





#####################################################################
# Constructor, Accessors, and Basic Methods

SCOPE: {
	my $cpan = CPAN::Inject->new(
		sources => $sources,
		);
	isa_ok( $cpan, 'CPAN::Inject' );
	is( $cpan->sources, $sources, '->sources ok' );
	is( $cpan->author,  'LOCAL',  '->author ok' );
	is(
		$cpan->author_subpath,
		catdir('authors', 'id', 'L', 'LO', 'LOCAL' ),
		'->author_subpath ok',
	);
	is(
		$cpan->author_path,
		catdir($sources, 'authors', 'id', 'L', 'LO', 'LOCAL' ),
		'->author_path ok',
	);
	is(
		$cpan->install_path('Perl-Tarball-1.00.tar.gz'),
		'LOCAL/Perl-Tarball-1.00.tar.gz',
		'->install_path ok',
	);
	is(
		$cpan->install_path(
			catfile('foo', 'bar', 'Perl-Tarball-1.00.tar.gz'),
			),
		'LOCAL/Perl-Tarball-1.00.tar.gz',
		'->install_path ok',
	);
}

SCOPE: {
	my $cpan = CPAN::Inject->new(
		sources => $sources,
		author  => 'ADAMK',
		);
	isa_ok( $cpan, 'CPAN::Inject' );
	is( $cpan->sources, $sources, '->sources ok' );
	is( $cpan->author,  'ADAMK',  '->author ok' );
}

SCOPE: {
	my $cpan = eval {
		CPAN::Inject->from_cpan_config(
			author  => 'ADAMK',
			);
	};
	SKIP: {
		skip( "Current user owns CPAN::Config", 1 ) unless $@;
		like($@,
			qr/(The directory .* does not exist|The sources directory is not owned by the current user)/, 
			'Got expected error',
		);
	}
	SKIP: {
		skip( "Current user does not own CPAN::Config", 2 ) if $@;
		isa_ok( $cpan, 'CPAN::Inject' );
		is( $cpan->author,  'ADAMK',  '->author ok' );
	}
}





#####################################################################
# Add a distribution

SCOPE: {
	my $cpan = CPAN::Inject->new(
		sources => $sources,
		);
	isa_ok( $cpan, 'CPAN::Inject' );

	# Add the distribution
	my $dist = catfile( 't', 'data', 'Config-Tiny-2.09.tar.gz' );
	ok( -f $dist, 'Test distribution exists' );
	is(
		$cpan->add( file => $dist ),
		'LOCAL/Config-Tiny-2.09.tar.gz',
		'->add ok',
	);
	my $author = catdir($sources, 'authors', 'id', 'L', 'LO', 'LOCAL');
	ok( -d $author, 'Created LOCAL base directory' );
	ok(
		-f catfile($author, 'Config-Tiny-2.09.tar.gz'),
		'Copied distribution to the correct destination',
	);
	ok(
		-f catfile($author, 'CHECKSUMS'),
		'Created CHECKSUMS file',
	);	
}

#####################################################################
# Remove a distribution

SCOPE: {
	my $cpan = CPAN::Inject->new(
		sources => $sources,
		);
	isa_ok( $cpan, 'CPAN::Inject' );

	# Remove the distribution
	ok(
		eval { $cpan->remove( dist => 'LOCAL/Config-Tiny-2.09.tar.gz' ); 1 },
		'->remove ok',
	);
	my $author = catdir($sources, 'authors', 'id', 'L', 'LO', 'LOCAL');
	ok(
		! -f catfile($author, 'Config-Tiny-2.09.tar.gz'),
		'Removed distribution file',
	);
}

1;