public
Description: (Perl) This is what the module does
Homepage: http://search.cpan.org/dist/CPAN-PackageDetails
Clone URL: git://github.com/briandfoy/cpan-packagedetails.git
cpan-packagedetails / t / read.t
100644 75 lines (57 sloc) 2.307 kb
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
use Test::More 'no_plan';
 
use File::Spec::Functions;
use Test::Output;
 
my $class = 'CPAN::PackageDetails';
my $method = 'read';
 
use_ok( $class );
can_ok( $class, $method );
 
my $file = catfile( qw(t test_files 02packages.details.txt.gz) );
ok( -e $file, "Test file $file exists" );
 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Test with single, good argument to read
{
my $lines = 1439;
 
my $package_details = $class->$method( $file );
 
isa_ok( $package_details, $class );
is( $package_details->source_file, $file, "Get back the right filename");
 
# test with the top level
# these are values taken from the input file
is( $package_details->file, '02packages.details.txt',
'file field reports right value from top level'
);
is( $package_details->url, 'http://www.perl.com/CPAN/modules/02packages.details.txt',
'url field reports right value from top level' );
 
is( $package_details->count, $lines,
'line field reports right value from top level' );
 
is( $package_details->line_count, $lines,
"Entries has the right number of elements from delegate level");
 
# test with the delegate level
# these are values taken from the input file
my $header = $package_details->header;
 
is( $header->file, '02packages.details.txt',
'file field reports right value from delegate level'
);
is( $header->url, 'http://www.perl.com/CPAN/modules/02packages.details.txt',
'url field reports right value from delegate level' );
 
is( $header->line_count, $lines,
'line field reports right value from delegate level' );
 
my $entries = $package_details->entries;
is( $entries->count, $lines,
"Entries has the right number of elements from delegate level");
}
 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Test with no arguments to read - should fail
stderr_like
{ $class->$method() }
qr/Missing argument!/,
"$method carps when I don't give it an argument";
 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Test with a single bad argument to read (missing file) - should fail
{
my $missing_file = 'fooey.gz';
ok( ! -e $missing_file, "Missing file is not there" );
 
stderr_like
{ $class->$method( $missing_file ) }
qr/Could not open/,
"$method carps when I don't give it an argument";
}