Update Module::Load::Conditional to CPAN version 0.38
[p5sagit/p5-mst-13.2.git] / cpan / Module-Build / t / pod_parser.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use lib 't/lib';
5 use MBTest tests => 9;
6
7 blib_load('Module::Build::PodParser');
8
9 #########################
10
11 {
12   package IO::StringBased;
13
14   sub TIEHANDLE {
15     my ($class, $string) = @_;
16     return bless {
17                   data => [ map "$_\n", split /\n/, $string],
18                  }, $class;
19   }
20
21   sub READLINE {
22     shift @{ shift()->{data} };
23   }
24 }
25
26 local *FH;
27 tie *FH, 'IO::StringBased', <<'EOF';
28 =head1 NAME
29
30 Foo::Bar - Perl extension for blah blah blah
31
32 =head1 AUTHOR
33
34 C<Foo::Bar> was written by Engelbert Humperdinck I<E<lt>eh@example.comE<gt>> in 2004.
35
36 Home page: http://example.com/~eh/
37
38 =cut
39 EOF
40
41
42 my $pp = Module::Build::PodParser->new(fh => \*FH);
43 ok $pp, 'object created';
44
45 is $pp->get_author->[0], 'C<Foo::Bar> was written by Engelbert Humperdinck I<E<lt>eh@example.comE<gt>> in 2004.', 'author';
46 is $pp->get_abstract, 'Perl extension for blah blah blah', 'abstract';
47
48
49 {
50   # Try again without a valid author spec
51   untie *FH;
52   tie *FH, 'IO::StringBased', <<'EOF';
53 =head1 NAME
54
55 Foo::Bar - Perl extension for blah blah blah
56
57 =cut
58 EOF
59
60   my $pp = Module::Build::PodParser->new(fh => \*FH);
61   ok $pp, 'object created';
62
63   is_deeply $pp->get_author, [], 'author';
64   is $pp->get_abstract, 'Perl extension for blah blah blah', 'abstract';
65 }
66
67
68 {
69     # Try again with mixed-case =head1s.
70   untie *FH;
71   tie *FH, 'IO::StringBased', <<'EOF';
72 =head1 Name
73
74 Foo::Bar - Perl extension for blah blah blah
75
76 =head1 Author
77
78 C<Foo::Bar> was written by Engelbert Humperdinck I<E<lt>eh@example.comE<gt>> in 2004.
79
80 Home page: http://example.com/~eh/
81
82 =cut
83 EOF
84
85   my $pp = Module::Build::PodParser->new(fh => \*FH);
86   ok $pp, 'object created';
87
88   is $pp->get_author->[0], 'C<Foo::Bar> was written by Engelbert Humperdinck I<E<lt>eh@example.comE<gt>> in 2004.', 'author';
89   is $pp->get_abstract, 'Perl extension for blah blah blah', 'abstract';
90 }