.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 turned on, 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 "Test::Synopsis 3pm" .TH Test::Synopsis 3pm "2016-03-02" "perl v5.22.1" "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" Test::Synopsis \- Test your SYNOPSIS code .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& # xt/synopsis.t (with Module::Install::AuthorTests) \& use Test::Synopsis; \& all_synopsis_ok(); \& \& # Or, run safe without Test::Synopsis \& use Test::More; \& eval "use Test::Synopsis"; \& plan skip_all => "Test::Synopsis required for testing" if $@; \& all_synopsis_ok(); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Test::Synopsis is an (author) test module to find .pm or .pod files under your \fIlib\fR directory and then make sure the example snippet code in your \fI\s-1SYNOPSIS\s0\fR section passes the perl compile check. .PP Note that this module only checks the perl syntax (by wrapping the code with \f(CW\*(C`sub\*(C'\fR) and doesn't actually run the code, \fB\s-1UNLESS\s0\fR that code is a \f(CW\*(C`BEGIN {}\*(C'\fR block or a \f(CW\*(C`use\*(C'\fR statement. .PP Suppose you have the following \s-1POD\s0 in your module. .PP .Vb 1 \& =head1 NAME \& \& Awesome::Template \- My awesome template \& \& =head1 SYNOPSIS \& \& use Awesome::Template; \& \& my $template = Awesome::Template\->new; \& $tempalte\->render("template.at"); \& \& =head1 DESCRIPTION .Ve .PP An user of your module would try copy-paste this synopsis code and find that this code doesn't compile because there's a typo in your variable name \fI\f(CI$tempalte\fI\fR. Test::Synopsis will catch that error before you ship it. .SH "VARIABLE DECLARATIONS" .IX Header "VARIABLE DECLARATIONS" Sometimes you might want to put some undeclared variables in your synopsis, like: .PP .Vb 1 \& =head1 SYNOPSIS \& \& use Data::Dumper::Names; \& print Dumper($scalar, \e@array, \e%hash); .Ve .PP This assumes these variables like \fI\f(CI$scalar\fI\fR are defined elsewhere in module user's code, but Test::Synopsis, by default, will complain that these variables are not declared: .PP .Vb 1 \& Global symbol "$scalar" requires explicit package name at ... .Ve .PP In this case, you can add the following \s-1POD\s0 sequence elsewhere in your \s-1POD:\s0 .PP .Vb 2 \& =for test_synopsis \& no strict \*(Aqvars\*(Aq .Ve .PP Or more explicitly, .PP .Vb 2 \& =for test_synopsis \& my($scalar, @array, %hash); .Ve .PP Test::Synopsis will find these \f(CW\*(C`=for\*(C'\fR blocks and these statements are prepended before your \s-1SYNOPSIS\s0 code when being evaluated, so those variable name errors will go away, without adding unnecessary bits in \&\s-1SYNOPSIS\s0 which might confuse users. .SH "SKIPPING TEST FROM INSIDE THE POD" .IX Header "SKIPPING TEST FROM INSIDE THE POD" You can use a \f(CW\*(C`BEGIN{}\*(C'\fR block in the \f(CW\*(C`=for test_synopsis\*(C'\fR to check for specific conditions (e.g. if a module is present), and possibly skip the test. .PP If you \f(CW\*(C`die()\*(C'\fR inside the \f(CW\*(C`BEGIN{}\*(C'\fR block and the die message begins with sequence \f(CW\*(C`SKIP:\*(C'\fR (note the colon at the end), the test will be skipped for that document. .PP .Vb 1 \& =head1 SYNOPSIS \& \& =for test_synopsis BEGIN { die "SKIP: skip this pod, it\*(Aqs horrible!\en"; } \& \& $x; # undeclared variable, but we skipped the test! \& \& =end .Ve .SH "EXPORTED SUBROUTINES" .IX Header "EXPORTED SUBROUTINES" .ie n .SS """all_synopsis_ok""" .el .SS "\f(CWall_synopsis_ok\fP" .IX Subsection "all_synopsis_ok" .Vb 1 \& all_synopsis_ok(); \& \& all_synopsis_ok( dump_all_code_on_error => 1 ); .Ve .PP Checks the \s-1SYNOPSIS\s0 code in all your modules. Takes \fBoptional\fR arguments as key/value pairs. Possible arguments are as follows: .PP \fI\f(CI\*(C`dump_all_code_on_error\*(C'\fI\fR .IX Subsection "dump_all_code_on_error" .PP .Vb 1 \& all_synopsis_ok( dump_all_code_on_error => 1 ); .Ve .PP Takes true or false values as a value. \fBDefaults to:\fR false. When set to a true value, if an error is discovered in the \s-1SYNOPSIS\s0 code, the test will dump the entire snippet of code it tried to test. Use this if you want to copy/paste and play around with the code until the error is fixed. .PP The dumped code will include any of the \f(CW\*(C`=for\*(C'\fR code you specified (see \&\*(L"\s-1VARIABLE DECLARATIONS\*(R"\s0 section above) as well as a few internal bits this test module uses to make \s-1SYNOPSIS\s0 code checking possible. .PP \&\fBNote:\fR you will likely have to remove the \f(CW\*(C`#\*(C'\fR and a space at the start of each line (\f(CW\*(C`perl \-pi \-e \*(Aqs/^#\es//;\*(Aq TEMP_FILE_WITH_CODE\*(C'\fR) .ie n .SS """synopsis_ok""" .el .SS "\f(CWsynopsis_ok\fP" .IX Subsection "synopsis_ok" .Vb 4 \& use Test::More tests => 1; \& use Test::Synopsis; \& synopsis_ok("t/lib/NoPod.pm"); \& synopsis_ok(qw/Pod1.pm Pod2.pm Pod3.pm/); .Ve .PP Lets you test a single file. \fBNote:\fR you must setup your own plan if you use this subroutine (e.g. with \f(CW\*(C`use Test::More tests => 1;\*(C'\fR). \&\fBTakes\fR a list of filenames for documents containing \s-1SYNOPSIS\s0 code to test. .SH "CAVEATS" .IX Header "CAVEATS" This module will not check code past the \f(CW\*(C`_\|_END_\|_\*(C'\fR or \&\f(CW\*(C`_\|_DATA_\|_\*(C'\fR tokens, if one is present in the \s-1SYNOPSIS\s0 code. .PP This module will actually execute \f(CW\*(C`use\*(C'\fR statements and any code you specify in the \f(CW\*(C`BEGIN {}\*(C'\fR blocks in the \s-1SYNOPSIS.\s0 .PP If you're using HEREDOCs in your \s-1SYNOPSIS,\s0 you will need to place the ending of the \s-1HEREDOC\s0 at the same indent as the first line of the code of your \s-1SYNOPSIS.\s0 .PP Redefinition warnings can be turned off with .PP .Vb 2 \& =for test_synopsis \& no warnings \*(Aqredefine\*(Aq; .Ve .SH "REPOSITORY" .IX Header "REPOSITORY" Fork this module on GitHub: .SH "BUGS" .IX Header "BUGS" To report bugs or request features, please use .PP If you can't access GitHub, you can email your request to \f(CW\*(C`bug\-Test\-Synopsis at rt.cpan.org\*(C'\fR .SH "AUTHOR" .IX Header "AUTHOR" Tatsuhiko Miyagawa .PP Goro Fuji blogged about the original idea at based on the testing code taken from Test::Weaken. .SH "MAINTAINER" .IX Header "MAINTAINER" Zoffix Znet .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" .IP "\(bu" 4 Dave Rolsky (\s-1DROLSKY\s0 ) .IP "\(bu" 4 Kevin Ryde (\s-1KRYDE\s0 ) .IP "\(bu" 4 Marcel Grünauer (\s-1MARCEL\s0 ) .IP "\(bu" 4 Mike Doherty (\s-1DOHERTY\s0 ) .IP "\(bu" 4 Patrice Clement (monsieurp ) .IP "\(bu" 4 Greg Sabino Mullane (\s-1TURNSTEP\s0 ) .IP "\(bu" 4 Zoffix Znet (\s-1ZOFFIX\s0 ) .IP "\(bu" 4 Olivier Mengué (\s-1DOLMEN\s0 ) .SH "LICENSE" .IX Header "LICENSE" This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "COPYRIGHT" .IX Header "COPYRIGHT" This library is Copyright (c) Tatsuhiko Miyagawa .SH "SEE ALSO" .IX Header "SEE ALSO" Test::Pod, Test::UseAllModules, Test::Inline