.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Pod::Tests 3pm" .TH Pod::Tests 3pm 2024-02-21 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Pod::Tests \- (DEPRECATED) Extracts embedded tests and code examples from POD .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use Pod::Tests; \& $p = Pod::Tests\->new; \& \& $p\->parse_file($file); \& $p\->parse_fh($fh); \& $p\->parse(@code); \& \& my @examples = $p\->examples; \& my @tests = $p\->tests; \& \& foreach my $example (@examples) { \& print "The example: \*(Aq$example\->{code}\*(Aq was on line ". \& "$example\->{line}\en"; \& } \& \& my @test_code = $p\->build_tests(@tests); \& my @example_test_code = $p\->build_examples(@examples); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This is a specialized POD viewer to extract embedded tests and code examples from POD. It doesn't do much more than that. pod2test does the useful work. .SS Parsing .IX Subsection "Parsing" After creating a Pod::Tests object, you parse the POD by calling one of the available parsing methods documented below. You can call parse as many times as you'd like, all examples and tests found will stack up inside the object. .SS Testing .IX Subsection "Testing" Once extracted, the tests can be built into stand-alone testing code using the \fBbuild_tests()\fR and \fBbuild_examples()\fR methods. However, it is recommended that you first look at the pod2test program before embarking on this. .SS Methods .IX Subsection "Methods" .SS new .IX Subsection "new" .Vb 1 \& $parser = Pod::Tests\->new; .Ve .PP Returns a new Pod::Tests object which lets you read tests and examples out of a POD document. .SS parse .IX Subsection "parse" .Vb 1 \& $parser\->parse(@code); .Ve .PP Finds the examples and tests in a bunch of lines of Perl \f(CW@code\fR. Once run they're available via \fBexamples()\fR and \fBtesting()\fR. .ie n .SS "parse_file $file" .el .SS "parse_file \f(CW$file\fP" .IX Subsection "parse_file $file" .Vb 1 \& $parser\->parse_file($filename); .Ve .PP Just like \fBparse()\fR except it works on a file. .ie n .SS "parse_fh $fh" .el .SS "parse_fh \f(CW$fh\fP" .IX Subsection "parse_fh $fh" .Vb 1 \& $parser\->parse_fh($fh); .Ve .PP Just like \fBparse()\fR except it works on a filehandle. .SS tests .IX Subsection "tests" .Vb 1 \& @testing = $parser\->tests; .Ve .PP Returns the tests found in the parsed POD documents. Each element of \&\f(CW@testing\fR is a hash representing an individual testing block and contains information about that block. .PP .Vb 2 \& $test\->{code} actual testing code \& $test\->{line} line from where the test was taken .Ve .SS examples .IX Subsection "examples" .Vb 1 \& @examples = $parser\->examples; .Ve .PP Returns the examples found in the parsed POD documents. Each element of \&\f(CW@examples\fR is a hash representing an individual testing block and contains information about that block. .PP .Vb 2 \& $test\->{code} actual testing code \& $test\->{line} line from where the test was taken .Ve .SS build_tests .IX Subsection "build_tests" .Vb 1 \& my @code = $p\->build_tests(@tests); .Ve .PP Returns a code fragment based on the given embedded \f(CW@tests\fR. This fragment is expected to print the usual "ok/not ok" (or something Test::Harness can read) or nothing at all. .PP Typical usage might be: .PP .Vb 1 \& my @code = $p\->build_tests($p\->tests); .Ve .PP This fragment is suitable for placing into a larger test script. .PP \&\fBNOTE\fR Look at pod2test before embarking on your own test building. .SS build_examples .IX Subsection "build_examples" .Vb 1 \& my @code = $p\->build_examples(@examples); .Ve .PP Similar to \fBbuild_tests()\fR, it creates a code fragment which tests the basic validity of your example code. Essentially, it just makes sure it compiles. .PP If your example has an "example testing" block associated with it it will run the the example code and the example testing block. .SH EXAMPLES .IX Header "EXAMPLES" Here's the simplest example, just finding the tests and examples in a single module. .PP .Vb 2 \& my $p = Pod::Tests\->new; \& $p\->parse_file("path/to/Some.pm"); .Ve .PP And one to find all the tests and examples in a directory of files. This illustrates building a set of examples and tests through multiple calls to \fBparse_file()\fR. .PP .Vb 7 \& my $p = Pod::Tests\->new; \& opendir(PODS, "path/to/some/lib/") || die $!; \& while( my $file = readdir PODS ) { \& $p\->parse_file($file); \& } \& printf "Found %d examples and %d tests in path/to/some/lib\en", \& scalar $p\->examples, scalar $p\->tests; .Ve .PP Finally, an example of parsing your own POD using the DATA filehandle. .PP .Vb 2 \& use Fcntl qw(:seek); \& my $p = Pod::Tests\->new; \& \& # Seek to the beginning of the current code. \& seek(DATA, 0, SEEK_SET) || die $!; \& $p\->parse_fh(\e*DATA); .Ve .SS SUPPORT .IX Subsection "SUPPORT" This module has been replaced by the newer Test::Inline 2. Most testing code that currently works with \f(CW\*(C`pod2test\*(C'\fR should continue to work with the new version. The most notable exceptions are \f(CW\*(C`=for begin\*(C'\fR and \&\f(CW\*(C`=for end\*(C'\fR, which are deprecated. .PP After upgrading, Pod::Tests and \f(CW\*(C`pod2test\*(C'\fR were split out to provide a compatibility package for legacy code. .PP \&\f(CW\*(C`pod2test\*(C'\fR will stay in CPAN, but should remain unchanged indefinately, with the exception of any minor bugs that will require squishing. .PP Bugs in this dist should be reported via the following URL. Feature requests should not be submitted, as further development is now occuring in Test::Inline. .PP .SH AUTHOR .IX Header "AUTHOR" Michael G Schwern .PP Adam Kennedy .SH "SEE ALSO" .IX Header "SEE ALSO" Test::Inline .PP pod2test, Perl 6 RFC 183 http://dev.perl.org/rfc183.pod .PP Short set of slides on Pod::Tests http://www.pobox.com/~schwern/talks/Embedded_Testing/ .PP Similar schemes can be found in SelfTest and Test::Unit. .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright 2005 \- 2008 Adam Kennedy. .PP Copyright 2001 \- 2003 Michael G Schwern. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP The full text of the license can be found in the LICENSE file included with this module.