Build.PL100644000766000024 316212443714243 17351 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12# ========================================================================= # THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA. # DO NOT EDIT DIRECTLY. # ========================================================================= use 5.008_001; use strict; use warnings; use utf8; use Module::Build; use File::Basename; use File::Spec; my %args = ( license => 'perl', dynamic_config => 0, configure_requires => { 'Module::Build' => 0.38, }, name => 'Test-Synopsis-Expectation', module_name => 'Test::Synopsis::Expectation', allow_pureperl => 0, script_files => [glob('script/*'), glob('bin/*')], c_source => [qw()], PL_files => {}, test_files => ((-d '.git' || $ENV{RELEASE_TESTING}) && -d 'xt') ? 't/ xt/' : 't/', recursive_test_files => 1, ); if (-d 'share') { $args{share_dir} = 'share'; } my $builder = Module::Build->subclass( class => 'MyBuilder', code => q{ sub ACTION_distmeta { die "Do not run distmeta. Install Minilla and `minil install` instead.\n"; } sub ACTION_installdeps { die "Do not run installdeps. Run `cpanm --installdeps .` instead.\n"; } } )->new(%args); $builder->create_build_script(); use File::Copy; print "cp META.json MYMETA.json\n"; copy("META.json","MYMETA.json") or die "Copy failed(META.json): $!"; if (-f 'META.yml') { print "cp META.yml MYMETA.yml\n"; copy("META.yml","MYMETA.yml") or die "Copy failed(META.yml): $!"; } else { print "There is no META.yml... You may install this module from the repository...\n"; } Changes100644000766000024 155112443714243 17350 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12Revision history for Perl extension Test-Synopsis-Expectation 0.12 2014-12-16T02:27:25Z - Added SEE ALSO section, with links to Test::Synopsis, and the Dist::Zilla plugin based on it. - Improved the wording of the abstract and first paragraph of the DESCRIPTION section of the doc. - Added github repo to doc 0.11 2014-01-02T17:03:39Z - Add `success` notation 0.10 2013-12-31T08:25:12Z - Add notations to ignore testing 0.04 2013-12-28T04:38:59Z - Show line number and filename on each test cases 0.03 2013-12-19T16:24:36Z - Fix some tests 0.02 2013-12-19T15:44:22Z - Add checking syntax of synopsis code - Support SYNOPSIS that has multi part codes - Change so that it is not necessary to use Test::More in each tests - Change backend tokenizer to PPI 0.01 2013-12-16T10:06:03Z - original version LICENSE100644000766000024 4372712443714243 17115 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12This software is copyright (c) 2013 by moznion . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2013 by moznion . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2013 by moznion . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End META.json100644000766000024 471612443714243 17504 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12{ "abstract" : "Test that SYNOPSIS code produces expected results", "author" : [ "moznion " ], "dynamic_config" : 0, "generated_by" : "Minilla/v2.3.0", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Test-Synopsis-Expectation", "no_index" : { "directory" : [ "t", "xt", "inc", "share", "eg", "examples", "author", "builder" ] }, "prereqs" : { "configure" : { "requires" : { "CPAN::Meta" : "0", "CPAN::Meta::Prereqs" : "0", "Module::Build" : "0.38" } }, "develop" : { "requires" : { "Test::CPAN::Meta" : "0", "Test::LocalFunctions" : "0", "Test::MinimumVersion::Fast" : "0.04", "Test::PAUSE::Permissions" : "0.04", "Test::Perl::Critic" : "0", "Test::Pod" : "1.41", "Test::Spellunker" : "v0.2.7", "Test::UsedModules" : "0", "Test::Vars" : "0" } }, "runtime" : { "requires" : { "PPI::Tokenizer" : "0", "Pod::Simple::Methody" : "0", "Test::Builder::Module" : "0", "Test::More" : "0.98", "parent" : "0", "perl" : "5.008005" } }, "test" : { "requires" : { "Test::Builder::Tester" : "0", "Test::More" : "0.98" } } }, "provides" : { "Test::Synopsis::Expectation" : { "file" : "lib/Test/Synopsis/Expectation.pm", "version" : "0.12" }, "Test::Synopsis::Expectation::Pod" : { "file" : "lib/Test/Synopsis/Expectation/Pod.pm" }, "Test::Synopsis::Expectation::Sandbox" : { "file" : "lib/Test/Synopsis/Expectation.pm" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/moznion/Test-Synopsis-Expectation/issues" }, "homepage" : "https://github.com/moznion/Test-Synopsis-Expectation", "repository" : { "url" : "git://github.com/moznion/Test-Synopsis-Expectation.git", "web" : "https://github.com/moznion/Test-Synopsis-Expectation" } }, "version" : "0.12", "x_contributors" : [ "Neil Bowers " ] } README.md100644000766000024 1313712443714243 17357 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12[![Build Status](https://travis-ci.org/moznion/Test-Synopsis-Expectation.svg?branch=master)](https://travis-ci.org/moznion/Test-Synopsis-Expectation) [![Coverage Status](https://img.shields.io/coveralls/moznion/Test-Synopsis-Expectation/master.svg)](https://coveralls.io/r/moznion/Test-Synopsis-Expectation?branch=master) # NAME Test::Synopsis::Expectation - Test that SYNOPSIS code produces expected results # SYNOPSIS use Test::Synopsis::Expectation; synopsis_ok('eg/sample.pod'); done_testing; Following, SYNOPSIS of `eg/sample.pod` my $num; $num = 1; # => 1 ++$num; # => is 2 use PPI::Tokenizer; my $tokenizer = PPI::Tokenizer->new(\'code'); # => isa 'PPI::Tokenizer' my $str = 'Hello, I love you'; # => like qr/ove/ my $obj = { foo => ["bar", "baz"], }; # => is_deeply { foo => ["bar", "baz"] } my $bool = 1; # => success # DESCRIPTION This module checks that a module's SYNOPSIS section is syntactically correct, and will also check that it produces the expected results, based on annotations you add in comments. # FUNCTIONS - synopsis\_ok($files) This function tests SYNOPSIS codes of each files. This function expects file names as an argument as ARRAYREF or SCALAR. (This function is exported) - all\_synopsis\_ok() This function tests SYNOPSIS codes of the all of library files. This function uses `MANIFEST` to list up the target files of testing. (This function is exported) - prepare($code\_str) Register the executable codes to prepare for evaluation. If you use like; use Test::Synopsis::Expectation; Test::Synopsis::Expectation::prepare('my $foo = 1;'); synopsis_ok('path/to/target.pm'); done_testing; ### Following, SYNOPSIS of `target.pm` $foo; # => 1 Then, SYNOPSIS of `target.pm` is the same as; my $foo = 1; $foo; # => 1 (This function is not exported) - set\_ignorings Set the procedures which would like to ignore. use Test::Synopsis::Expectation; Test::Synopsis::Expectation::set_ignorings(['++$num;']); synopsis_ok(*DATA); done_testing; __DATA__ =head1 SYNOPSIS my $num; $num = 1; # => 1 ++$num; $num; # => 1 In the above example, `++$num;` will be ignored. # NOTATION OF EXPECTATION Comment that starts at `# =>` then this module treats the comment as test statement. - # => is my $foo = 1; # => is 1 This way is equivalent to the next. my $foo = 1; is $foo, 1; This carries out the same behavior as `Test::More::is`. - # => my $foo = 1; # => 1 This notation is the same as `# => is` - # => isa use Foo::Bar; my $instance = Foo::Bar->new; # => isa 'Foo::Bar' This way is equivalent to the next. use Foo::Bar; my $instance = Foo::Bar->new; isa_ok $instance, 'Foo::Bar'; This carries out the same behavior as `Test::More::isa_ok`. - # => like my $str = 'Hello, I love you'; # => like qr/ove/ This way is equivalent to the next. my $str = 'Hello, I love you'; like $str, qr/ove/; This carries out the same behavior as `Test::More::like`. - # => is\_deeply my $obj = { foo => ["bar", "baz"], }; # => is_deeply { foo => ["bar", "baz"] } This way is equivalent to the next. my $obj = { foo => ["bar", "baz"], }; is_deeply $obj, { foo => ["bar", "baz"] }; This carries out the same behavior as `Test::More::is_deeply`. - # => success my $bool = 1; $bool; # => success This way checks value as boolean. If target value of testing is 0 then this test will fail. Otherwise, it will pass. # ANNOTATIONS - =for test\_synopsis\_expectation\_no\_test The code block behind this annotation will not be tested. my $sum; $sum = 1; # => 1 =for test_synopsis_expectation_no_test my $sum; $sum = 1; # => 2 In this example, the first code block will be tested, but the second will not. # RESTRICTION ## Test case must be one line The following is valid; my $obj = { foo => ["bar", "baz"], }; # => is_deeply { foo => ["bar", "baz"] } However, the following is invalid; my $obj = { foo => ["bar", "baz"], }; # => is_deeply { # foo => ["bar", "baz"] # } So test case must be one line. ## Not put test cases inside of for(each) # Example of not working for (1..10) { my $foo = $_; # => 10 } This example doesn't work. On the contrary, it will be error (Probably nobody uses such as this way... I think). # NOTES ## yada-yada operator This module ignores yada-yada operators that is in SYNOPSIS code. Thus, following code is runnable. my $foo; ... $foo = 1; # => 1 # SEE ALSO [Test::Synopsis](https://metacpan.org/pod/Test::Synopsis) - simpler module, which just checks the syntax of your SYNOPSIS section. [Dist::Zilla::Plugin::Test::Synopsis](https://metacpan.org/pod/Dist::Zilla::Plugin::Test::Synopsis) - a plugin for [Dist::Zilla](https://metacpan.org/pod/Dist::Zilla) users, which adds a release test to your distribution, based on [Test::Synopsis](https://metacpan.org/pod/Test::Synopsis). # REPOSITORY [https://github.com/moznion/Test-Synopsis-Expectation](https://github.com/moznion/Test-Synopsis-Expectation) # LICENSE Copyright (C) moznion. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. # AUTHOR moznion cpanfile100644000766000024 103712443714243 17560 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12requires 'Pod::Simple::Methody'; requires 'PPI::Tokenizer'; requires 'Test::Builder::Module'; requires 'Test::More', '0.98'; requires 'parent'; requires 'perl', '5.008005'; on configure => sub { requires 'CPAN::Meta'; requires 'CPAN::Meta::Prereqs'; requires 'Module::Build'; }; on test => sub { requires 'Test::More', '0.98'; requires 'Test::Builder::Tester'; }; on develop => sub { requires 'Test::LocalFunctions'; requires 'Test::Perl::Critic'; requires 'Test::UsedModules'; requires 'Test::Vars'; }; sample.pod100644000766000024 71012443714243 20411 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/eg=head1 NAME sample - This is the sample POD =head1 SYNOPSIS my $num; $num = 1; # => 1 ++$num; # => is 2 use PPI::Tokenizer; my $tokenizer = PPI::Tokenizer->new(\'code'); # => isa 'PPI::Tokenizer' my $str = 'Hello, I love you'; # => like qr/ove/ my $obj = { foo => ["bar", "baz"], }; # => is_deeply { foo => ["bar", "baz"] } my $bool = 1; # => success =head1 AUTHOR moznion Emoznion@gmail.comE sample.t100644000766000024 41012443714243 20067 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/eg#!perl use strict; use warnings; use FindBin; use File::Spec::Functions qw/catfile/; use lib catfile($FindBin::Bin, '..', 'lib'); use Test::Synopsis::Expectation; my $target_file = catfile($FindBin::Bin, 'sample.pod'); synopsis_ok($target_file); done_testing; Expectation.pm100644000766000024 2315512443714243 24236 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/lib/Test/Synopsispackage Test::Synopsis::Expectation; use 5.008005; use strict; use warnings; use parent qw/Test::Builder::Module/; my @test_more_exports; BEGIN { @test_more_exports = (qw/done_testing/) } use PPI::Tokenizer; use ExtUtils::Manifest qw/maniread/; use Test::More import => \@test_more_exports; use Test::Synopsis::Expectation::Pod; our $VERSION = "0.12"; our @EXPORT = (@test_more_exports, qw/all_synopsis_ok synopsis_ok/); my $prepared = ''; my $ignorings = []; sub prepare { $prepared = shift; } sub set_ignorings { $ignorings = shift; $ignorings = [$ignorings] if ref $ignorings ne 'ARRAY'; return $ignorings; } sub all_synopsis_ok { my $builder = __PACKAGE__->builder; my @files = _list_up_files_from_manifest($builder); for my $file (@files) { _synopsis_ok($file); } } sub synopsis_ok { my ($files) = @_; $files = [$files] if ref $files ne 'ARRAY'; for my $file (@$files) { _synopsis_ok($file); } } sub _synopsis_ok { my ($file) = @_; local $Test::Builder::Level = $Test::Builder::Level + 1; my $parser = Test::Synopsis::Expectation::Pod->new; $parser->parse_file($file); my $block_num = 1; for my $target_code (@{$parser->{target_codes}}) { my ($expectations, $code) = _analyze_target_code($target_code); _check_syntax($code, $block_num, $file); for my $expectation (@$expectations) { _check_with_expectation($expectation, $block_num, $file); } $block_num++; } } sub _check_syntax { package Test::Synopsis::Expectation::Sandbox; eval $_[0]; ## no critic if ($@) { Test::More::fail("Syntax OK: $_[2] (SYNOPSIS Block: $_[1])"); } else { Test::More::pass("Syntax OK: $_[2] (SYNOPSIS Block: $_[1])"); } } sub _check_with_expectation { package Test::Synopsis::Expectation::Sandbox; # $_[0] is expectation my $got = eval $_[0]->{code}; ## no critic my $expected = eval $_[0]->{expected}; ## no critic my $method = $_[0]->{method}; my $test_name = "$_[2] (SYNOPSIS Block: $_[1], Line: $_[0]->{line_num})"; if ($method eq 'is') { Test::More::is($got, $expected, $test_name); } elsif ($method eq 'isa') { Test::More::isa_ok($got, $expected, $test_name); } elsif ($method eq 'like') { Test::More::like($got, $expected, $test_name); } elsif ($method eq 'is_deeply') { Test::More::is_deeply($got, $expected, $test_name); } elsif ($method eq 'success') { Test::More::ok($got, $test_name); } } sub _analyze_target_code { my ($target_code) = @_; my $deficient_brace = 0; my $code = $prepared || ''; # code for test my @expectations; # store expectations for test my $line_num = 1; for my $line (split /\n\r?/, $target_code) { my $tokens = PPI::Tokenizer->new(\$line)->all_tokens; if (grep {$_->{content} eq '...' && $_->isa('PPI::Token::Operator')} @$tokens) { next; } for my $ignoring (@$ignorings) { $line =~ s/\Q$ignoring\E//g; } $code .= "$line\n"; # Count the number of left braces to complete deficient right braces $deficient_brace++ if (grep {$_->{content} eq '{' && $_->isa('PPI::Token::Structure')} @$tokens); $deficient_brace-- if (grep {$_->{content} eq '}' && $_->isa('PPI::Token::Structure')} @$tokens); # Extract comment statement # Tokens contain one comment token on a line, at the most if (my ($comment) = grep {$_->isa('PPI::Token::Comment')} @$tokens) { # Accept special comment for this module # e.g. # # => is 42 my ($expectation) = $comment->{content} =~ /#\s*=>\s*(.+)/; next unless $expectation; # Accept test methods as string my $method; if ($expectation =~ s/^(?:(is|isa|is_deeply|like)\s|(success))//) { $method = $1 || $2; } push @expectations, +{ 'method' => $method || 'is', 'expected' => $expectation, 'code' => $code . ('}' x $deficient_brace), 'line_num' => $line_num, }; } $line_num++; } return (\@expectations, $code); } sub _list_up_files_from_manifest { my ($builder) = @_; my $manifest = $ExtUtils::Manifest::MANIFEST; if ( not -f $manifest ) { $builder->plan( skip_all => "$manifest doesn't exist" ); } return grep { m!\Alib/.*\.pm\Z! } keys %{ maniread() }; } 1; __END__ =encoding utf-8 =for stopwords isa yada-yada =head1 NAME Test::Synopsis::Expectation - Test that SYNOPSIS code produces expected results =head1 SYNOPSIS use Test::Synopsis::Expectation; synopsis_ok('eg/sample.pod'); done_testing; Following, SYNOPSIS of F =for test_synopsis_expectation_no_test my $num; $num = 1; # => 1 ++$num; # => is 2 use PPI::Tokenizer; my $tokenizer = PPI::Tokenizer->new(\'code'); # => isa 'PPI::Tokenizer' my $str = 'Hello, I love you'; # => like qr/ove/ my $obj = { foo => ["bar", "baz"], }; # => is_deeply { foo => ["bar", "baz"] } my $bool = 1; # => success =head1 DESCRIPTION This module checks that a module's SYNOPSIS section is syntactically correct, and will also check that it produces the expected results, based on annotations you add in comments. =head1 FUNCTIONS =over 4 =item * synopsis_ok($files) This function tests SYNOPSIS codes of each files. This function expects file names as an argument as ARRAYREF or SCALAR. (This function is exported) =item * all_synopsis_ok() This function tests SYNOPSIS codes of the all of library files. This function uses F to list up the target files of testing. (This function is exported) =item * prepare($code_str) Register the executable codes to prepare for evaluation. If you use like; use Test::Synopsis::Expectation; Test::Synopsis::Expectation::prepare('my $foo = 1;'); synopsis_ok('path/to/target.pm'); done_testing; ### Following, SYNOPSIS of `target.pm` $foo; # => 1 Then, SYNOPSIS of F is the same as; my $foo = 1; $foo; # => 1 (This function is not exported) =item * set_ignorings Set the procedures which would like to ignore. use Test::Synopsis::Expectation; Test::Synopsis::Expectation::set_ignorings(['++$num;']); synopsis_ok(*DATA); done_testing; __DATA__ =head1 SYNOPSIS my $num; $num = 1; # => 1 ++$num; $num; # => 1 In the above example, C<++$num;> will be ignored. =back =head1 NOTATION OF EXPECTATION Comment that starts at C<# =E> then this module treats the comment as test statement. =over 4 =item * # => is my $foo = 1; # => is 1 This way is equivalent to the next. my $foo = 1; is $foo, 1; This carries out the same behavior as C. =item * # => my $foo = 1; # => 1 This notation is the same as C<# =E is> =item * # => isa use Foo::Bar; my $instance = Foo::Bar->new; # => isa 'Foo::Bar' This way is equivalent to the next. use Foo::Bar; my $instance = Foo::Bar->new; isa_ok $instance, 'Foo::Bar'; This carries out the same behavior as C. =item * # => like my $str = 'Hello, I love you'; # => like qr/ove/ This way is equivalent to the next. my $str = 'Hello, I love you'; like $str, qr/ove/; This carries out the same behavior as C. =item * # => is_deeply my $obj = { foo => ["bar", "baz"], }; # => is_deeply { foo => ["bar", "baz"] } This way is equivalent to the next. my $obj = { foo => ["bar", "baz"], }; is_deeply $obj, { foo => ["bar", "baz"] }; This carries out the same behavior as C. =item * # => success my $bool = 1; $bool; # => success This way checks value as boolean. If target value of testing is 0 then this test will fail. Otherwise, it will pass. =back =head1 ANNOTATIONS =over 4 =item * =for test_synopsis_expectation_no_test The code block behind this annotation will not be tested. my $sum; $sum = 1; # => 1 =for test_synopsis_expectation_no_test my $sum; $sum = 1; # => 2 In this example, the first code block will be tested, but the second will not. =back =head1 RESTRICTION =head2 Test case must be one line The following is valid; my $obj = { foo => ["bar", "baz"], }; # => is_deeply { foo => ["bar", "baz"] } However, the following is invalid; my $obj = { foo => ["bar", "baz"], }; # => is_deeply { # foo => ["bar", "baz"] # } So test case must be one line. =head2 Not put test cases inside of for(each) # Example of not working for (1..10) { my $foo = $_; # => 10 } This example doesn't work. On the contrary, it will be error (Probably nobody uses such as this way... I think). =head1 NOTES =head2 yada-yada operator This module ignores yada-yada operators that is in SYNOPSIS code. Thus, following code is runnable. my $foo; ... $foo = 1; # => 1 =head1 SEE ALSO L - simpler module, which just checks the syntax of your SYNOPSIS section. L - a plugin for L users, which adds a release test to your distribution, based on L. =head1 REPOSITORY L =head1 LICENSE Copyright (C) moznion. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR moznion Emoznion@gmail.comE =cut Pod.pm100644000766000024 275512443714243 24743 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/lib/Test/Synopsis/Expectationpackage Test::Synopsis::Expectation::Pod; use strict; use warnings; use parent qw/Pod::Simple::Methody/; sub new { my $class = shift; my $parser = $class->SUPER::new(@_); # NOTE I think not good way... $parser->{in_head1} = 0; $parser->{in_synopsis} = 0; $parser->{in_verbatim} = 0; $parser->{no_test} = 0; $parser->{target_codes} = []; $parser->accept_target_as_text(qw/test_synopsis_expectation_no_test/); return $parser; } sub _handle_text { my($self, $text) = @_; if ($self->{in_head1} && $text =~ /^synopsis$/i) { $self->{in_synopsis} = 1; } # Target codes (that is synopsis code) if ($self->{in_synopsis} && $self->{in_verbatim}) { unless ($self->{no_test}) { push @{$self->{target_codes}}, $text; } $self->{no_test} = 0; } } sub _handle_element_start { my ($self, $element_name, $attr_hash_r) = @_; if ($element_name eq 'head1') { $self->{in_head1} = 1; $self->{in_synopsis} = 0; } elsif ($element_name eq 'Verbatim') { $self->{in_verbatim} = 1; } elsif ($element_name eq 'for') { if ($attr_hash_r->{target} eq 'test_synopsis_expectation_no_test') { $self->{no_test} = 1; } } } sub _handle_element_end { my ($self, $element_name) = @_; if ($element_name eq 'head1') { $self->{in_head1} = 0; } elsif ($element_name eq 'Verbatim') { $self->{in_verbatim} = 0; } } 1; minil.toml100644000766000024 10412443714243 20033 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12name = "Test-Synopsis-Expectation" badges = ["travis", "coveralls"] 00_compile.t100644000766000024 20612443714243 20410 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/tuse strict; use Test::More; use_ok $_ for qw( Test::Synopsis::Expectation Test::Synopsis::Expectation::Pod ); done_testing; 01_basic.t100644000766000024 107012443714243 20062 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/t#!perl use strict; use warnings; use Test::Synopsis::Expectation; synopsis_ok(*DATA); done_testing; __DATA__ =head1 NAME basic - It's basic =head1 SYNOPSIS my $sum; $sum = 1; # => 1 ++$sum; # => is 2 ++$sum; #=>is 3 use PPI::Tokenizer; my $tokenizer = PPI::Tokenizer->new(\'code'); # => isa 'PPI::Tokenizer' my $str = 'Hello, I love you'; # => like qr/ove/ my $obj = { foo => ["bar", "baz"], }; # => is_deeply { foo => ["bar", "baz"] } $sum; # => success =head1 AUTHOR moznion Emoznion@gmail.comE 02_fail.t100644000766000024 125412443714243 17721 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/t#!perl use strict; use warnings; use Test::Builder::Tester; use Test::Synopsis::Expectation; test_out( 'ok 1 - Syntax OK: *main::DATA (SYNOPSIS Block: 1)', 'not ok 2 - *main::DATA (SYNOPSIS Block: 1, Line: 1)', 'ok 3 - Syntax OK: *main::DATA (SYNOPSIS Block: 2)', 'not ok 4 - *main::DATA (SYNOPSIS Block: 2, Line: 1)', 'not ok 5 - *main::DATA (SYNOPSIS Block: 2, Line: 2)', ); synopsis_ok(*DATA); test_test (name => 'testing used_modules_ok()', skip_err => 1); done_testing; __DATA__ =head1 NAME fail - crazy!! =head1 SYNOPSIS 2; # => 1 Of course following is fail! 1; # => 2 0; # => success =head1 AUTHOR moznion Emoznion@gmail.comE 03_multiple_file.t100644000766000024 55412443714243 21623 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/t#!perl use strict; use warnings; use FindBin; use File::Spec::Functions qw/catfile/; use Test::Synopsis::Expectation; my $target_file = catfile($FindBin::Bin, 'resources', 'less.pod'); synopsis_ok([*DATA, $target_file]); done_testing; __DATA__ =head1 NAME less - Less! Less!! =head1 SYNOPSIS 1; # => 1 =head1 AUTHOR moznion Emoznion@gmail.comE 04_yadayada.t100644000766000024 40612443714243 20543 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/t#!perl use strict; use warnings; use Test::Synopsis::Expectation; synopsis_ok(*DATA); done_testing; __DATA__ =head1 NAME yadayada - It's yadayada =head1 SYNOPSIS my $sum; ... $sum = 1; # => 1 =head1 AUTHOR moznion Emoznion@gmail.comE 05_prepared.t100644000766000024 43612443714243 20574 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/t#!perl use strict; use warnings; use Test::Synopsis::Expectation; Test::Synopsis::Expectation::prepare('my $foo = 1;'); synopsis_ok(*DATA); done_testing; __DATA__ =head1 NAME prepared - prepare! =head1 SYNOPSIS $foo; # => 1 =head1 AUTHOR moznion Emoznion@gmail.comE 06_wrapped_brace.t100644000766000024 67212443714243 21573 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/t#!perl use strict; use warnings; use Test::Synopsis::Expectation; synopsis_ok(*DATA); done_testing; __DATA__ =head1 NAME wrapped_brace - Values in the wrapped_brace =head1 SYNOPSIS my $var; if (1) { $var = 1; # => 1 ++$var; # => 2 } if (1) { $var = 3; # => 3 if (1) { ++$var; # => 4 } } $var = 5; # => 5 =head1 AUTHOR moznion Emoznion@gmail.comE 07_multi_part_synopsis.t100644000766000024 43312443714243 23120 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/t#!perl use strict; use warnings; use Test::Synopsis::Expectation; synopsis_ok(*DATA); done_testing; __DATA__ =head1 NAME multi part synopsis - multi! =head1 SYNOPSIS 1; # => 1 Of course following is true! 2; # => 2 =head1 AUTHOR moznion Emoznion@gmail.comE 08_ignore.t100644000766000024 50112443714243 20251 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/t#!perl use strict; use warnings; use Test::Synopsis::Expectation; Test::Synopsis::Expectation::set_ignorings(['++$num;']); synopsis_ok(*DATA); done_testing; __DATA__ =head1 NAME ignore =head1 SYNOPSIS my $num; $num = 1; # => 1 ++$num; $num; # => 1 =head1 AUTHOR moznion Emoznion@gmail.comE 09_no_test.t100644000766000024 55612443714243 20454 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/t#!perl use strict; use warnings; use Test::Synopsis::Expectation; synopsis_ok(*DATA); done_testing; __DATA__ =head1 NAME no-test =head1 SYNOPSIS my $sum; $sum = 1; # => 1 The following is invalid. So it should not be tested. =for test_synopsis_expectation_no_test my $sum; $sum = 1; # => 2 =head1 AUTHOR moznion Emoznion@gmail.comE less.pod100644000766000024 16512443714243 21764 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/t/resources=head1 NAME less - Less! Less!! =head1 SYNOPSIS 1; # => 1 =head1 AUTHOR moznion Emoznion@gmail.comE local_functions.t100644000766000024 53712443714243 22042 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/xt#!perl use strict; use warnings; use Test::More; eval { require Test::LocalFunctions; }; plan skip_all => "Test::LocalFunctions required for testing variables" if $@; Test::LocalFunctions::all_local_functions_ok({ ignore_functions => [ qr/_handle_text/, qr/_handle_element_start/, qr/_handle_element_end/, ] }); perlcritic.t100644000766000024 34412443714243 21014 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/xt#!perl use strict; use Test::More; eval { require Test::Perl::Critic; Test::Perl::Critic->import( -profile => 'xt/perlcriticrc' ); }; plan skip_all => "Test::Perl::Critic is not installed." if $@; all_critic_ok('lib'); perlcriticrc100644000766000024 012443714243 21024 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/xtself.t100644000766000024 24412443714243 17604 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/xt#!perl use strict; use warnings; use Test::Synopsis::Expectation; Test::Synopsis::Expectation::set_ignorings(['done_testing;']); all_synopsis_ok; done_testing; used_modules.t100644000766000024 32212443714243 21340 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/xt#!perl use strict; use warnings; use Test::More; eval { require Test::UsedModules; }; plan skip_all => "Test::UsedModules required for testing variables" if $@; Test::UsedModules::all_used_modules_ok(); vars.t100644000766000024 42612443714243 17630 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12/xt#!perl use strict; use warnings; use Test::More; eval { require Test::Vars; }; plan skip_all => "Test::Vars required for testing variables" if $@; Test::Vars::all_vars_ok( ignore_vars => { '$guard' => 1, '$class' => 1, '$self' => 1, } ); META.yml100644000766000024 242612443714243 17330 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12--- abstract: 'Test that SYNOPSIS code produces expected results' author: - 'moznion ' build_requires: Test::Builder::Tester: '0' Test::More: '0.98' configure_requires: CPAN::Meta: '0' CPAN::Meta::Prereqs: '0' Module::Build: '0.38' dynamic_config: 0 generated_by: 'Minilla/v2.3.0, CPAN::Meta::Converter version 2.142690' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Test-Synopsis-Expectation no_index: directory: - t - xt - inc - share - eg - examples - author - builder provides: Test::Synopsis::Expectation: file: lib/Test/Synopsis/Expectation.pm version: '0.12' Test::Synopsis::Expectation::Pod: file: lib/Test/Synopsis/Expectation/Pod.pm Test::Synopsis::Expectation::Sandbox: file: lib/Test/Synopsis/Expectation.pm requires: PPI::Tokenizer: '0' Pod::Simple::Methody: '0' Test::Builder::Module: '0' Test::More: '0.98' parent: '0' perl: '5.008005' resources: bugtracker: https://github.com/moznion/Test-Synopsis-Expectation/issues homepage: https://github.com/moznion/Test-Synopsis-Expectation repository: git://github.com/moznion/Test-Synopsis-Expectation.git version: '0.12' x_contributors: - 'Neil Bowers ' MANIFEST100644000766000024 71412443714243 17166 0ustar00jp50594staff000000000000Test-Synopsis-Expectation-0.12Build.PL Changes LICENSE META.json README.md cpanfile eg/sample.pod eg/sample.t lib/Test/Synopsis/Expectation.pm lib/Test/Synopsis/Expectation/Pod.pm minil.toml t/00_compile.t t/01_basic.t t/02_fail.t t/03_multiple_file.t t/04_yadayada.t t/05_prepared.t t/06_wrapped_brace.t t/07_multi_part_synopsis.t t/08_ignore.t t/09_no_test.t t/resources/less.pod xt/local_functions.t xt/perlcritic.t xt/perlcriticrc xt/self.t xt/used_modules.t xt/vars.t META.yml MANIFEST