File: 41_multiple_packages.t

package info (click to toggle)
libparse-pmfile-perl 0.48-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 256 kB
  • sloc: perl: 676; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,320 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;
use Test::More;
use Parse::PMFile;
use File::Temp;

my $tmpdir = File::Temp->newdir(CLEANUP => 1);
plan skip_all => "tmpdir is not ready" unless -e $tmpdir && -w $tmpdir;

my $pmfile = "$tmpdir/Test.pm";
my @package = (qw/Parse PMFile Test/);
my @subpackages = (qw/Location Blah Thing/);

my $parser = Parse::PMFile->new;
subtest 'arisdottle' => sub {
  _generate_package(q{::});
  my $info = $parser->parse($pmfile);
  _check_packages($info);
};

subtest 'quote' => sub {
  _generate_package(q{'});
  my $info = $parser->parse($pmfile);
  _check_packages($info);
};

done_testing;

sub _generate_package {
  my ($sep) = @_;
  my $version = 1;

  open my $fh, '>', $pmfile or plan skip_all => "Failed to create a pmfile";
  print $fh 'package ' . join($sep, @package) . ";\n";
  print $fh q{our $VERSION = '1.0} . $version++ . "';\n1;\n";
  for my $subpackage (@subpackages) {
    print $fh 'package ' . join($sep, @package, $subpackage) . ";\n";
    print $fh q{our $VERSION = '1.0} . $version++ . "';\n1;\n";
  }
  close $fh;
}

sub _check_packages {
	my ($info) = @_;

	my $package = join(q{::}, @package);
	ok exists $info->{$package}, q{found base package};

	for my $subpackage (@subpackages) {
		ok exists $info->{$package . q{::} . $subpackage}, qq{found sub package $subpackage};
	}
}