Build.PL100644000765000024 45513660620122 14352 0ustar00gugodstaff000000000000Test-Cukes-0.11# ========================================================================= # THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA. # DO NOT EDIT DIRECTLY. # ========================================================================= use 5.008_001; use strict; use Module::Build::Tiny 0.035; Build_PL(); Changes100644000765000024 134113660620122 14364 0ustar00gugodstaff000000000000Test-Cukes-0.110.11 2020-05-19T07:40:46+0800 - replace the deprecated Any::Moose with Moose 0.10 - Fix META.yml and use Try::Tiny FTW. 0.09 - Tristan Pratt makes it more compatible when using it with other Test::Bulder::Module-based tools. 0.08 - allow step definitions to be defined in all namespaces. 0.07 - makes it perl 5.8 compatible. thanks to miyagawa++ 0.06 - let runtests accept feature text too 0.05 - Fix the missing step report of "And" steps. 0.04 - report missing steps as TAP note 0.03 - if a step died, diag its dying message. 0.02 - Count each block as one assertion-based test - If pre-condition steps fail, then its successing steps will be skipped. 0.01 - initial version - basic implementation. LICENSE100644000765000024 223113660620122 14075 0ustar00gugodstaff000000000000Test-Cukes-0.11This software is Copyright (c) 2016 by Kang-min Liu . This is free software, licensed under: The MIT (X11) License The MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. META.json100644000765000024 432113660620122 14513 0ustar00gugodstaff000000000000Test-Cukes-0.11{ "abstract" : "A BBD test tool inspired by Cucumber", "author" : [ "Kang-min Liu " ], "dynamic_config" : 0, "generated_by" : "Minilla/v3.1.4", "license" : [ "mit" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Test-Cukes", "no_index" : { "directory" : [ "t", "xt", "inc", "share", "eg", "examples", "author", "builder" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "6.59", "Test::More" : "0" } }, "configure" : { "requires" : { "Module::Build::Tiny" : "0.035" } }, "develop" : { "requires" : { "Test::CPAN::Meta" : "0", "Test::MinimumVersion::Fast" : "0.04", "Test::PAUSE::Permissions" : "0.04", "Test::Pod" : "1.41", "Test::Spellunker" : "v0.2.7" } }, "runtime" : { "requires" : { "Carp::Assert" : "0.20", "Moose" : "0", "Test::Builder::Module" : "0.80", "Try::Tiny" : "0.07", "perl" : "5.008" } } }, "provides" : { "Test::Cukes" : { "file" : "lib/Test/Cukes.pm", "version" : "0.11" }, "Test::Cukes::Feature" : { "file" : "lib/Test/Cukes/Feature.pm" }, "Test::Cukes::Scenario" : { "file" : "lib/Test/Cukes/Scenario.pm" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/gugod/Test-Cukes/issues" }, "homepage" : "https://github.com/gugod/Test-Cukes", "repository" : { "url" : "git://github.com/gugod/Test-Cukes.git", "web" : "https://github.com/gugod/Test-Cukes" } }, "version" : "0.11", "x_contributors" : [ "Tatsuhiko Miyagawa ", "Yann Kerherve ", "prat0088 " ], "x_serialization_backend" : "JSON::PP version 2.97001", "x_static_install" : 1 } README.md100644000765000024 1054313660620122 14374 0ustar00gugodstaff000000000000Test-Cukes-0.11# NAME Test::Cukes - A BBD test tool inspired by Cucumber # SYNOPSIS Write your test program like this: # test.pl use Test::Cukes; # use Test::Cukes tests => 3; feature(< perl test.pl 1..3 ok 1 - Given the test program is running ok 2 - When it reaches this step ok 3 - Then it should pass # DESCRIPTION Test::Cukes is a testing tool inspired by Cucumber ([http://cukes.info](http://cukes.info)). It lets your write your module test with scenarios. It may be used with [Test::More](https://metacpan.org/pod/Test::More) or other family of TAP `Test::*` modules. It uses [Test::Builder::note](https://metacpan.org/pod/Test::Builder::note) function internally to print messages. This module implements the Given-When-Then clause only in English. To uses it in the test programs, feed the feature text into `feature` function, defines your step handlers, and then run all the tests by calling `runtests`. Step handlers may be defined in separate modules, as long as those modules are included before `runtests` is called. Each step may use either `assert` or standard TAP functions such as `Test::Simple`'s `ok` or `Test::More`'s `is` to verify desired result. If you specify a plan explicitly, you should be aware that each step line in your scenario runs an additional test, and will therefore add to the number of tests you must indicate. If any assertion in the Given block failed, the following `When` and `Then` blocks are all skipped. You don't need to specify the number of tests with `plan`. Each step block itself is simply one test. If the block died, it's then considered failed. Otherwise it's considered as passing. In the call to [Test::Cukes::runtests](https://metacpan.org/pod/Test::Cukes::runtests), [done\_testing](https://metacpan.org/pod/done_testing) will automatically be called for you if you didn't specify a plan. Test::Cukes re-exports `assert` function from `Carp::Assert` for you to use in the step block. For more info about how to define feature and scenarios, please read the documents from [http://cukes.info](http://cukes.info). # AUTHOR Kang-min Liu # CONTRIBUTORS Tatsuhiko Miyagawa, Tristan Pratt # SEE ALSO The official Cucumber web-page, [http://cukes.info/](http://cukes.info/). cucumber.pl, [http://search.cpan.org/dist/cucumber/](http://search.cpan.org/dist/cucumber/), another Perl implementation of Cucumber tool. [Carp::Assert](https://metacpan.org/pod/Carp::Assert) # LICENSE This is free software, licensed under: The MIT (X11) License # DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "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 SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. 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 SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (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 SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. cpanfile100644000765000024 36213660620122 14557 0ustar00gugodstaff000000000000Test-Cukes-0.11requires 'Moose'; requires 'Carp::Assert', '0.20'; requires 'Test::Builder::Module', '0.80'; requires 'Try::Tiny', '0.07'; requires 'perl', '5.008'; on build => sub { requires 'ExtUtils::MakeMaker', '6.59'; requires 'Test::More'; }; Cukes.pm100644000765000024 1577513660620122 16226 0ustar00gugodstaff000000000000Test-Cukes-0.11/lib/Testpackage Test::Cukes; use strict; use warnings; use Test::Cukes::Feature; use Carp::Assert; use Try::Tiny; use base 'Test::Builder::Module'; our $VERSION = "0.11"; our @EXPORT = qw(feature runtests Given When Then assert affirm should shouldnt); our @missing_steps = (); my $steps = {}; my $feature = {}; sub feature { my $caller = caller; my $text = shift; $feature->{$caller} = Test::Cukes::Feature->new($text) } sub runtests { my $caller = caller; my $feature_text = shift; if ($feature_text) { $feature->{$caller} = Test::Cukes::Feature->new($feature_text); } my @scenarios_of_caller = @{$feature->{$caller}->scenarios}; for my $scenario (@scenarios_of_caller) { my $skip = 0; my $skip_reason = ""; my $gwt; for my $step_text (@{$scenario->steps}) { my ($pre, $step) = split " ", $step_text, 2; if ($skip) { Test::Cukes->builder->skip($step_text); next; } $gwt = $pre if $pre =~ /(Given|When|Then)/; my $found_step = 0; for my $step_pattern (keys %$steps) { my $cb = $steps->{$step_pattern}->{code}; if (my (@matches) = $step =~ m/$step_pattern/) { my $ok = 1; try { $cb->(@matches); } catch { $ok = 0; }; Test::Cukes->builder->ok($ok, $step_text); if ($skip == 0 && !$ok) { Test::Cukes->builder->diag($@); $skip = 1; $skip_reason = "Failed: $step_text"; } $found_step = 1; last; } } unless($found_step) { $step_text =~ s/^And /$gwt /; push @missing_steps, $step_text; } } } # If the user doesn't specify tests explicitly when they use Test::Cukes;, # assume they had no plan and call done_testing for them. Test::Cukes->builder->done_testing if !Test::Cukes->builder->has_plan; report_missing_steps(); return 0; } sub report_missing_steps { return if @missing_steps == 0; Test::Cukes->builder->note("There are missing step definitions, fill them in:"); for my $step_text (@missing_steps) { my ($word, $text) = ($step_text =~ /^(Given|When|Then) (.+)$/); my $msg = "\n$word qr/${text}/ => sub {\n ...\n};\n"; Test::Cukes->builder->note($msg); } } sub _add_step { my ($step, $cb) = @_; my ($package, $filename, $line) = caller; $steps->{$step} = { definition => { package => $package, filename => $filename, line => $line, }, code => $cb }; } *Given = *_add_step; *When = *_add_step; *Then = *_add_step; 1; __END__ =head1 NAME Test::Cukes - A BBD test tool inspired by Cucumber =head1 SYNOPSIS Write your test program like this: # test.pl use Test::Cukes; # use Test::Cukes tests => 3; feature(< perl test.pl 1..3 ok 1 - Given the test program is running ok 2 - When it reaches this step ok 3 - Then it should pass =head1 DESCRIPTION Test::Cukes is a testing tool inspired by Cucumber (L). It lets your write your module test with scenarios. It may be used with L or other family of TAP C modules. It uses L function internally to print messages. This module implements the Given-When-Then clause only in English. To uses it in the test programs, feed the feature text into C function, defines your step handlers, and then run all the tests by calling C. Step handlers may be defined in separate modules, as long as those modules are included before C is called. Each step may use either C or standard TAP functions such as C's C or C's C to verify desired result. If you specify a plan explicitly, you should be aware that each step line in your scenario runs an additional test, and will therefore add to the number of tests you must indicate. If any assertion in the Given block failed, the following C and C blocks are all skipped. You don't need to specify the number of tests with C. Each step block itself is simply one test. If the block died, it's then considered failed. Otherwise it's considered as passing. In the call to L, L will automatically be called for you if you didn't specify a plan. Test::Cukes re-exports C function from C for you to use in the step block. For more info about how to define feature and scenarios, please read the documents from L. =head1 AUTHOR Kang-min Liu Egugod@gugod.orgE =head1 CONTRIBUTORS Tatsuhiko Miyagawa, Tristan Pratt =head1 SEE ALSO The official Cucumber web-page, L. cucumber.pl, L, another Perl implementation of Cucumber tool. L =head1 LICENSE This is free software, licensed under: The MIT (X11) License =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "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 SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. 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 SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (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 SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. =cut Feature.pm100644000765000024 226513660620122 17567 0ustar00gugodstaff000000000000Test-Cukes-0.11/lib/Test/Cukespackage Test::Cukes::Feature; use Moose; use Test::Cukes::Scenario; has name => ( is => "rw", required => 1, isa => "Str" ); has body => ( is => "rw", isa => "Str" ); has scenarios => ( is => "rw", isa => "ArrayRef[Test::Cukes::Scenario]" ); sub BUILDARGS { my $class = shift; if (@_ == 1 && ! ref $_[0]) { my $text = shift; my $args = { name => "", body => "", scenarios => [] }; my @blocks = split /\n\n/, $text; my $meta = shift @blocks; unless ($meta =~ m/^Feature:\s([^\n]+x?)$(.+)\z/sm) { die "Cannot extra feature name and body from text:\n----\n$meta\n----\n\n"; } $args->{name} = $1; $args->{body} = $2; for my $scenario_text (@blocks) { unless ($scenario_text =~ s/^ (.+?)$/$1/mg) { die "Scenario text is not properly indented:\n----\n${scenario_text}\n----\n\n"; } push @{$args->{scenarios}}, Test::Cukes::Scenario->new($scenario_text) } return $args; } return $class->SUPER::BUILDARGS(@_); } __PACKAGE__->meta->make_immutable; no Moose; 1; Scenario.pm100644000765000024 142013660620122 17727 0ustar00gugodstaff000000000000Test-Cukes-0.11/lib/Test/Cukespackage Test::Cukes::Scenario; use Moose; has name => ( is => "rw", required => 1, isa => "Str" ); has steps => ( is => "rw", required => 1, isa => "ArrayRef[Str]" ); sub BUILDARGS { my $class = shift; if (@_ == 1 && ! ref $_[0]) { my $scenario_text = shift; my $args = { name => "", steps => [] }; for my $line (split /\n+/, $scenario_text) { if ($line =~ /^Scenario:\s(.+)$/) { $args->{name} = $1; } elsif ($line =~ /^ (Given|When|Then|And)\s(.+)$/) { push @{$args->{ steps }}, "$1 $2"; } } return $args; } return $class->SUPER::BUILDARGS(@_); } __PACKAGE__->meta->make_immutable; no Moose; 1; 00_compile.t100644000765000024 10713660620122 15427 0ustar00gugodstaff000000000000Test-Cukes-0.11/tuse strict; use Test::More tests => 1; BEGIN { use_ok 'Test::Cukes' } feature.t100644000765000024 166113660620122 15161 0ustar00gugodstaff000000000000Test-Cukes-0.11/t#!/usr/bin/env perl -w use strict; use Test::More qw(no_plan); use Test::Cukes::Feature; my $feature = Test::Cukes::Feature->new(<name, "Hendrerit iriure et dolore autem tincidunt enim autem"); like($feature->body, qr/In order to.+As.+I want/s); is(scalar @{ $feature->scenarios }, 1); my $scenario = $feature->scenarios->[0]; is($scenario->name, "Some random scenario text"); is_deeply($scenario->steps, ["Given the pre-conditions is there", "When it branches into the second level", "Then the final shall be reached"]); runtest-with-arg.t100644000765000024 115513660620122 16750 0ustar00gugodstaff000000000000Test-Cukes-0.11/t#!/usr/bin/env perl -w use strict; use Test::Cukes; my @passed; Given qr/blah1/ => sub { push @passed, 1; assert @passed == 1; }; When qr/blah2/ => sub { push @passed, 2; assert @passed == 2; }; Then qr/blah3/ => sub { push @passed, 3; assert @passed == 3; # We can't use is_deeply because Test::More doesn't play nice with # Cukes's plan. assert 1 == $passed[0]; assert 2 == $passed[1]; assert 3 == $passed[2]; }; runtests(< 2; feature(< sub { $hit_given = 1; }; runtests; is($hit_given, 0, "Correctly never ran the 'when' test"); ok(@Test::Cukes::missing_steps == 3); runtest.t100644000765000024 205613660620122 15231 0ustar00gugodstaff000000000000Test-Cukes-0.11/t#!/usr/bin/env perl -w use strict; use Test::Cukes; use Test::More; feature(< sub { push @passed, 1; push @regex_matches, @_; assert @passed == 1; assert @regex_matches == 1 }; When qr/it is my birthday/ => sub { push @passed, 2; ok 1, "Using is, ok, etc no longer screw up Cuke's test plan and cause" . " it to fail."; assert @passed == 2; assert @regex_matches == 1 }; Then qr/we will eat (\d+) (.+)/ => sub { push @passed, 3; push @regex_matches, @_; assert @passed == 3; assert @regex_matches == 3; is_deeply [1, 2, 3], \@passed, "Steps were called in the correct order"; is_deeply ['cake', 28, 'cakes'], \@regex_matches, "Regex matches were" . " correctly passed to the step functions"; }; runtests; scenario.t100644000765000024 106513660620122 15327 0ustar00gugodstaff000000000000Test-Cukes-0.11/t#!/usr/bin/env perl -w use strict; use Test::More tests => 2; use Test::Cukes::Scenario; my $scenario = Test::Cukes::Scenario->new(<name, "Some random scenario text"); is_deeply($scenario->steps, ["Given the pre-conditions is there", "When it branches into the second level", "Then the final shall be reached"]); steps-from-other-namespace.t100644000765000024 122313660620122 20670 0ustar00gugodstaff000000000000Test-Cukes-0.11/t#!/usr/bin/env perl -w use strict; package Foo; use Test::Cukes; Given qr/^the pre-conditions is there$/, sub { assert 1; }; When qr/^it branches into the second level$/, sub { assert 1; }; Then qr/^the final shall be reached$/, sub { assert 1; }; package main; use Test::Cukes; feature(q{ Feature: Hendrerit iriure et dolore autem tincidunt enim autem In order to Quis facilisis facilisis minim esse As a dolor te duis. I want to vel feugait vulputate molestie. Scenario: Some random scenario text Given the pre-conditions is there When it branches into the second level Then the final shall be reached }); runtests; 02_perlcritic.t100644000765000024 33313660620122 16332 0ustar00gugodstaff000000000000Test-Cukes-0.11/xtuse 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'); perlcriticrc100644000765000024 17313660620122 16116 0ustar00gugodstaff000000000000Test-Cukes-0.11/xt[TestingAndDebugging::ProhibitNoStrict] allow=refs [TestingAndDebugging::RequireUseStrict] equivalent_modules = Any::Moose META.yml100644000765000024 234013660620122 14342 0ustar00gugodstaff000000000000Test-Cukes-0.11--- abstract: 'A BBD test tool inspired by Cucumber' author: - 'Kang-min Liu ' build_requires: ExtUtils::MakeMaker: '6.59' Test::More: '0' configure_requires: Module::Build::Tiny: '0.035' dynamic_config: 0 generated_by: 'Minilla/v3.1.4, CPAN::Meta::Converter version 2.150010' license: mit meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Test-Cukes no_index: directory: - t - xt - inc - share - eg - examples - author - builder provides: Test::Cukes: file: lib/Test/Cukes.pm version: '0.11' Test::Cukes::Feature: file: lib/Test/Cukes/Feature.pm Test::Cukes::Scenario: file: lib/Test/Cukes/Scenario.pm requires: Carp::Assert: '0.20' Moose: '0' Test::Builder::Module: '0.80' Try::Tiny: '0.07' perl: '5.008' resources: bugtracker: https://github.com/gugod/Test-Cukes/issues homepage: https://github.com/gugod/Test-Cukes repository: git://github.com/gugod/Test-Cukes.git version: '0.11' x_contributors: - 'Tatsuhiko Miyagawa ' - 'Yann Kerherve ' - 'prat0088 ' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' x_static_install: 1 MANIFEST100644000765000024 47313660620122 14207 0ustar00gugodstaff000000000000Test-Cukes-0.11Build.PL Changes LICENSE META.json README.md cpanfile lib/Test/Cukes.pm lib/Test/Cukes/Feature.pm lib/Test/Cukes/Scenario.pm t/00_compile.t t/feature.t t/runtest-with-arg.t t/runtest-without-defined-steps.t t/runtest.t t/scenario.t t/steps-from-other-namespace.t xt/02_perlcritic.t xt/perlcriticrc META.yml MANIFEST