2 # Copyright (C) 2001-2005, Parrot Foundation.
7 use lib qw( . lib ../lib ../../lib );
8 use Test::More 'tests' => 25;
9 use File::Spec::Functions qw(:ALL);
13 t/perl/Parrot_Docs.t - Parrot::Docs unit tests
17 % prove t/perl/Parrot_Docs.t
21 These tests cover the basic functionality of the C<Parrot::Docs>
22 modules: file types, POD syntax checking, and to-HTML formatting.
24 When one or more of the C<Parrot::Docs> modules is modified, run the tests
25 to ensure nothing is broken.
29 BEGIN { use_ok("Parrot::Docs::POD2HTML") }
32 Parrot::Docs::POD2HTML->href_path('docs\pdds\pdd00_pdd.pod.html') eq
33 'docs/pdds/pdd00_pdd.pod.html',
37 BEGIN { use_ok('Parrot::Docs::Directory') }
38 BEGIN { use_ok('Parrot::Docs::File') }
42 my $d = Parrot::Docs::Directory->new( catfile(qw(lib Parrot Docs)) );
43 my @a = $d->files_of_type('Perl module');
45 # This will fail if you add a new module.
46 is( @a, 8, 'files_of_type succeed' );
47 @a = $d->files_of_type('foo');
48 is( @a, 0, 'files_of_type fail' );
50 my $f = $d->file_with_name('File.pm');
51 ok( $f->is_of_type('Perl module'), 'is_of_type succeed' );
52 ok( !$f->is_of_type('foo'), 'is_of_type fail' );
53 is( $f->short_description, 'Docs-Related File', 'short_description' );
55 $f = Parrot::Docs::File->new( tmp_file_path('file.pod') );
57 ok( !$f->contains_pod, 'contains_pod no' );
58 $f->write("=head1 FOO\n\nFoo\n\n=cut\n\nbar\n");
59 ok( $f->contains_pod, 'contains_pod yes, no errors' );
60 is( $f->num_pod_errors, 0, 'num_pod_errors none' );
62 # Not the best of tests, but at least something.
63 like( $f->pod_as_html, qr|<html.*?</html>|si, 'pod_as_html' );
64 $f->write("=haed1 FOO\n\nFoo\n\n=cut\n\nbar\n");
65 ok( $f->contains_pod, 'contains_pod yes, errors' );
66 is( $f->num_pod_errors, 1, 'num_pod_errors one' );
67 like( $f->pod_errors, qr/error/s, 'pod_errors' );
69 # Now the structural classes.
70 BEGIN { use_ok('Parrot::Docs::Item') }
71 BEGIN { use_ok('Parrot::Docs::Group') }
72 BEGIN { use_ok('Parrot::Docs::Section') }
74 my $src = Parrot::Docs::Directory->new( tmp_dir_path('src') );
75 $d = $src->directory_with_name('foo');
76 $f = $d->file_with_name('file1.pod');
77 $f->write("=head1 NAME\n\nxyz - foo/file1.pod\n\n=cut\n");
78 $f = $d->file_with_name('file2.pod');
79 $f->write("=head1 NAME\n\nxyz - foo/file1.pod\n\n=cut\n");
80 $d = $src->directory_with_name('bar');
81 $f = $d->file_with_name('file3.pod');
82 $f->write("=head1 NAME\n\nxyz - bar/file3.pod\n\n=cut\n");
83 $f = $src->file_with_name('file.txt');
84 $f->write("file.txt");
85 $d = $src->directory_with_name('pub');
86 $f = $d->file_with_name('beer.pint');
88 my $i = Parrot::Docs::Item->new( 'Usual suspects', 'foo', 'bar' );
91 my $g = Parrot::Docs::Group->new(
94 Parrot::Docs::Item->new( '', 'foo' ),
95 Parrot::Docs::Item->new( '', 'bar' )
98 ok( $g, 'new group' );
99 is( $g->name, 'Usual suspects', 'name' );
101 my $s = Parrot::Docs::Section->new(
105 Parrot::Docs::Item->new( 'our old friend', 'foo' ),
106 Parrot::Docs::Group->new(
107 'Bar', 'no jeans', Parrot::Docs::Item->new( 'time please', 'bar', 'pub' )
111 ok( $s, 'new section' );
113 my $tgt = Parrot::Docs::Directory->new( tmp_dir_path('tgt') );
115 $s->write_html( $src, $tgt, 1 );
117 $f = $tgt->file_with_name('index.html');
119 ok( $f, 'index.html' );
124 $html =~ m|Usual Suspects|s
125 # && $html =~ m|here they are|s
126 && $html =~ m|foo/file1.pod|s
127 && $html =~ m|foo/file2.pod|s
129 # && $html =~ m|no jeans|s
130 && $html =~ m|bar/file3.pod|s
131 && $html =~ m|time please|s,
138 Parrot::Docs::File->new( tmp_file_path('file.pod') )->delete();
139 Parrot::Docs::Directory->new( tmp_dir_path('src') )->delete();
140 Parrot::Docs::Directory->new( tmp_dir_path('tgt') )->delete();
143 # tmp_dir_path(@dirs)
145 return catdir( tmpdir, @_ );
148 # tmp_file_path(@dirs, $file)
153 $file = catfile( tmp_dir_path(), shift );
157 $file = catfile( tmp_dir_path(@_), $file );
165 # cperl-indent-level: 4
168 # vim: expandtab shiftwidth=4: